-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Introduce Organization Administrator concept along with Instance Administrator #39381
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b2577b8
Renaming TENANT_ADMIN to the new terminology
trishaanand 9e76766
Merge branch 'release' into feat/ce-instance-org-admin
trishaanand e8c7a95
Renaming the instance administrator role
trishaanand 2884732
Renaming existing instance admin role to org admin role and introduci…
trishaanand 4929d58
Making instance admin and removing instance admin via env variables n…
trishaanand c0b2b0b
Updating cacheable repository helper method to use organization domai…
trishaanand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
220 changes: 96 additions & 124 deletions
220
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/UserUtilsCE.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
.../com/appsmith/server/migrations/db/ce/Migration066_RenameInstanceAdminRoleToOrgAdmin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package com.appsmith.server.migrations.db.ce; | ||
|
||
import com.appsmith.external.models.Policy; | ||
import com.appsmith.server.constants.FieldName; | ||
import com.appsmith.server.domains.Config; | ||
import com.appsmith.server.domains.Organization; | ||
import com.appsmith.server.domains.PermissionGroup; | ||
import io.mongock.api.annotations.ChangeUnit; | ||
import io.mongock.api.annotations.Execution; | ||
import io.mongock.api.annotations.RollbackExecution; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.minidev.json.JSONObject; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.data.mongodb.core.query.Update; | ||
|
||
import java.util.Set; | ||
|
||
import static com.appsmith.external.models.BaseDomain.policySetToMap; | ||
|
||
@Slf4j | ||
@ChangeUnit(id = "rename-instance-admin-role-to-org-admin-role", order = "066") | ||
public class Migration066_RenameInstanceAdminRoleToOrgAdmin { | ||
|
||
private final MongoTemplate mongoTemplate; | ||
|
||
public Migration066_RenameInstanceAdminRoleToOrgAdmin(MongoTemplate mongoTemplate) { | ||
this.mongoTemplate = mongoTemplate; | ||
} | ||
|
||
@RollbackExecution | ||
public void rollbackExecution() {} | ||
|
||
@Execution | ||
public void execute() { | ||
// 1. Find instanceConfig | ||
Config instanceConfig = | ||
mongoTemplate.findOne(Query.query(Criteria.where("name").is("instanceConfig")), Config.class); | ||
|
||
if (instanceConfig == null || instanceConfig.getConfig() == null) { | ||
log.error("Instance config not found"); | ||
return; | ||
} | ||
|
||
// 2. Find default organization - add null check | ||
Organization defaultOrganization = mongoTemplate.findOne(new Query(), Organization.class); | ||
if (defaultOrganization == null) { | ||
log.error("Default organization not found"); | ||
return; | ||
} | ||
|
||
renameInstanceAdminPermissionGroupToOrganizationAdmin(instanceConfig, defaultOrganization); | ||
createInstanceAdminRole(instanceConfig, defaultOrganization); | ||
} | ||
|
||
private void createInstanceAdminRole(Config instanceConfig, Organization defaultOrganization) { | ||
|
||
// Create instance management permission group | ||
PermissionGroup instanceManagerPermissionGroup = new PermissionGroup(); | ||
instanceManagerPermissionGroup.setName(FieldName.INSTANCE_ADMIN_ROLE); | ||
|
||
// No permissions given to instance admin role. This would be a hidden permission group. | ||
|
||
// Fetch the organization admin role | ||
PermissionGroup organizationAdminRole = mongoTemplate.findOne( | ||
Query.query(Criteria.where("defaultDomainId").is(defaultOrganization.getId())), PermissionGroup.class); | ||
|
||
// Assign the permission group to all the users and user groups who already are assigned to the org admin role | ||
instanceManagerPermissionGroup.setAssignedToUserIds(organizationAdminRole.getAssignedToUserIds()); | ||
instanceManagerPermissionGroup.setAssignedToGroupIds(organizationAdminRole.getAssignedToGroupIds()); | ||
|
||
// Save the permission group | ||
PermissionGroup savedInstanceAdminRole = mongoTemplate.save(instanceManagerPermissionGroup); | ||
|
||
// Update the config document | ||
JSONObject config = instanceConfig.getConfig(); | ||
config.put("defaultPermissionGroup", savedInstanceAdminRole.getId()); | ||
instanceConfig.setConfig(config); | ||
|
||
Set<Policy> policies = instanceConfig.getPolicies(); | ||
policies.stream().forEach(policy -> { | ||
policy.getPermissionGroups().remove(organizationAdminRole.getId()); | ||
policy.getPermissionGroups().add(savedInstanceAdminRole.getId()); | ||
}); | ||
instanceConfig.setPolicies(policies); | ||
instanceConfig.setPolicyMap(policySetToMap(policies)); | ||
mongoTemplate.save(instanceConfig); | ||
} | ||
|
||
private void renameInstanceAdminPermissionGroupToOrganizationAdmin( | ||
Config instanceConfig, Organization defaultOrganization) { | ||
try { | ||
|
||
String instanceAdminRoleId = | ||
instanceConfig.getConfig().get("defaultPermissionGroup").toString(); | ||
|
||
// 3. Update permission group with all fields in a single update | ||
Update update = Update.update("name", "Organization Administrator Role") | ||
.set("defaultDomainId", defaultOrganization.getId()) | ||
.set("defaultDomainType", "Organization"); // Use string directly instead of class name | ||
|
||
long modifiedCount = mongoTemplate | ||
.updateFirst( | ||
Query.query(Criteria.where("_id").is(instanceAdminRoleId)), update, PermissionGroup.class) | ||
.getModifiedCount(); | ||
|
||
if (modifiedCount > 0) { | ||
log.info( | ||
"Successfully renamed instance admin role to organization admin role for group: {}", | ||
instanceAdminRoleId); | ||
} else { | ||
log.warn("No permission group was updated for id: {}", instanceAdminRoleId); | ||
} | ||
|
||
} catch (Exception e) { | ||
log.error("Error while renaming instance admin role", e); | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Ensure domain types align with the new admin concept
The updated criteria logic looks streamlined and removes references to instance-based roles, focusing on organization-based roles. It's essential to verify that no leftover references to the old "instance admin" or "tenant admin" roles remain within the codebase or mismatch the newly introduced organization-centric approach.
Run the following script to confirm if any vestiges of "instanceAdminPermissionGroupId", "TENANT_ADMIN", or "instance admin" remain:
🏁 Script executed:
Length of output: 50719
Action Required: Align All Legacy Admin References with the New Organization-Centric Approach
The updated criteria in CacheableRepositoryHelperCEImpl.java is correctly streamlined for organization-based roles. However, the search results show that legacy instance/tenant admin references (e.g.,
"instanceAdminPermissionGroupId"
,TENANT_ADMIN
, and"instance admin"
) still appear in several parts of the codebase. Please review and determine if these references:Files to check:
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/InMemoryCacheableRepositoryHelper.java
Migration066_RenameInstanceAdminRoleToOrgAdmin.java
,Migration10000_UpdateSuperUser.java
)src/test/java
paths related to user and permission group managementPlease update or remove outdated references where appropriate to avoid potential inconsistencies with the organization-centric role logic.