Skip to content
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

Snowflake integration #5176

Merged
merged 6 commits into from
Jun 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'release' of github.com:appsmithorg/appsmith into featur…
…e/snowflake-integration
  • Loading branch information
nidhi-nair committed Jun 16, 2021
commit caf5cd564780d36ea11c188d514ad1aba25e6663
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,78 @@ public void updateFirestoreWhereConditionsData(MongoTemplate mongoTemplate) {
.forEach(action -> mongoTemplate.save(action));
}

@ChangeSet(order = "071", id = "add-snowflake-plugin", author = "")
@ChangeSet(order = "071", id = "add-application-export-permissions", author = "")
public void addApplicationExportPermissions(MongoTemplate mongoTemplate) {
final List<Organization> organizations = mongoTemplate.find(
query(where("userRoles").exists(true)),
Organization.class
);

for (final Organization organization : organizations) {
Set<String> adminUsernames = organization.getUserRoles()
.stream()
.filter(role -> (role.getRole().equals(AppsmithRole.ORGANIZATION_ADMIN)))
.map(role -> role.getUsername())
.collect(Collectors.toSet());

if (adminUsernames.isEmpty()) {
continue;
}
// All the administrators of the organization should be allowed to export applications permission
Set<String> exportApplicationPermissionUsernames = new HashSet<>();
exportApplicationPermissionUsernames.addAll(adminUsernames);

Set<Policy> policies = organization.getPolicies();
if (policies == null) {
policies = new HashSet<>();
}

Optional<Policy> exportAppOrgLevelOptional = policies.stream()
.filter(policy -> policy.getPermission().equals(ORGANIZATION_EXPORT_APPLICATIONS.getValue())).findFirst();

if (exportAppOrgLevelOptional.isPresent()) {
Policy exportApplicationPolicy = exportAppOrgLevelOptional.get();
exportApplicationPolicy.getUsers().addAll(exportApplicationPermissionUsernames);
} else {
// this policy doesnt exist. create and add this to the policy set
Policy inviteUserPolicy = Policy.builder().permission(ORGANIZATION_EXPORT_APPLICATIONS.getValue())
.users(exportApplicationPermissionUsernames).build();
organization.getPolicies().add(inviteUserPolicy);
}

mongoTemplate.save(organization);

// Update the applications with export applications policy for all administrators of the organization
List<Application> orgApplications = mongoTemplate.find(
query(where(fieldName(QApplication.application.organizationId)).is(organization.getId())),
Application.class
);

for (final Application application : orgApplications) {
Set<Policy> applicationPolicies = application.getPolicies();
if (applicationPolicies == null) {
applicationPolicies = new HashSet<>();
}

Optional<Policy> exportAppOptional = applicationPolicies.stream()
.filter(policy -> policy.getPermission().equals(EXPORT_APPLICATIONS.getValue())).findFirst();

if (exportAppOptional.isPresent()) {
Policy exportAppPolicy = exportAppOptional.get();
exportAppPolicy.getUsers().addAll(adminUsernames);
} else {
// this policy doesn't exist, create and add this to the policy set
Policy newExportAppPolicy = Policy.builder().permission(EXPORT_APPLICATIONS.getValue())
.users(adminUsernames).build();
application.getPolicies().add(newExportAppPolicy);
}

mongoTemplate.save(application);
}
}
}

@ChangeSet(order = "072", id = "add-snowflake-plugin", author = "")
public void addSnowflakePlugin(MongoTemplate mongoTemplate) {
Plugin plugin = new Plugin();
plugin.setName("Snowflake");
Expand All @@ -2408,5 +2479,6 @@ public void addSnowflakePlugin(MongoTemplate mongoTemplate) {
}

installPluginToAllOrganizations(mongoTemplate, plugin.getId());

}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.