Skip to content

Commit

Permalink
linting and comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sondermanish committed May 9, 2024
1 parent e0984af commit 9c01c08
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import static com.appsmith.server.migrations.db.ce.Migration047AddMissingFieldsInDefaultAppsmithAiDatasource.newerCheckForDeletedCriteria;
import static com.appsmith.server.migrations.db.ce.Migration047AddMissingFieldsInDefaultAppsmithAiDatasource.olderCheckForDeletedCriteria;

/**
* This class adds a new policy delete:applicationPages to all non deleted applications.
* The permissionGroups of the new policy is copied from the policy having permission delete application
* in the same application.
*
*/
@Slf4j
@ChangeUnit(order = "053", id = "add-app-delete-pages-permission-to-application", author = " ")
@RequiredArgsConstructor
Expand All @@ -38,18 +44,24 @@ public class Migration053AddApplicationDeletePagePermissionToApplications {
public void rollbackExecution() {}

@Execution
public void addNewPolicyWithPermissionGroupsFromExisting() {
public void addApplicationDeletePagesPermissionToApplication() {

// selection of all the applications which have not been deleted.
Criteria applicationCriteria =
new Criteria().andOperator(olderCheckForDeletedCriteria(), newerCheckForDeletedCriteria());

// conditional to match delete:applications permission
Document equalityConditionDoc = new Document("$eq", List.of("$$this.permission", DELETE_APPLICATIONS_VALUE));

// filtering the policy from the policies based on equality condition
Document filterPermissionGroupsDoc = new Document(
"$filter", new Document().append("input", "$policies").append("cond", equalityConditionDoc));

// selecting the permissionGroups set present at array index,
// (the list is dynamically created after filtering policies on permission and then returning permissionGroups)
Document permissionGroupArrayElementAtDoc = new Document("$arrayElemAt", List.of(filterPermissionGroupsDoc, 0));

// creating a new policy with permission delete:applicationPages and permissionGroups from delete:app policy
List<Document> singletonPolicyList = List.of(new Document(PERMISSION, APPLICATION_DELETE_PAGES_VALUE)
.append(
PERMISSION_GROUPS,
Expand All @@ -61,6 +73,7 @@ public void addNewPolicyWithPermissionGroupsFromExisting() {
new Document("existingPolicy", permissionGroupArrayElementAtDoc))
.append("in", "$$existingPolicy.permissionGroups"))));

// concatenating existing policies set with the newly created policy which is in set
Document concatPolicySets = new Document("$concatArrays", List.of("$policies", singletonPolicyList));

AggregationOperation aggregationOperation = Aggregation.addFields()
Expand All @@ -72,10 +85,13 @@ public void addNewPolicyWithPermissionGroupsFromExisting() {
new Query().addCriteria(applicationCriteria),
Aggregation.newUpdate(aggregationOperation),
Application.class);
} catch (Exception e) {
} catch (Exception exception) {
log.debug(
"Migration050 failed due to reason {}. \n skipping addition of policy to appications ",
e.getMessage());
"Migration with change-id : add-app-delete-pages-permission-to-application failed due to reason {}."
+ "skipping addition of policy to applications ",
exception.getMessage());

throw exception;
}
}
}

0 comments on commit 9c01c08

Please sign in to comment.