Removed migration to delete organization collection

Renamed constant FieldName.ORGANIZATION to FieldName.WORKSPACE, kept the value as organization
Renamed constants in appsmith errors
This commit is contained in:
Sidhant Goel 2022-05-11 22:08:03 +05:30
parent 214e5a8318
commit 087d24c6de
No known key found for this signature in database
GPG Key ID: 0784E3B2D2D6C980
15 changed files with 31 additions and 36 deletions

View File

@ -12,7 +12,7 @@ public class FieldName {
public static final String PLUGIN_TYPE = "pluginType";
public static final String COLLECTION_ID = "collectionId";
public static final String ACTION_ID = "actionId";
public static String ORGANIZATION = "organization";
public static String WORKSPACE = "organization";
public static String ID = "id";
public static final String NAME = "name";
public static String PAGE_ID = "pageId";

View File

@ -16,13 +16,13 @@ public enum AppsmithError {
AppsmithErrorAction.DEFAULT, null, ErrorType.ARGUMENT_ERROR, null),
PAGE_ID_NOT_GIVEN(400, 4004, "Missing page id. Please enter one.", AppsmithErrorAction.DEFAULT, null, ErrorType.ARGUMENT_ERROR, null),
DUPLICATE_KEY_USER_ERROR(400, 4005, "{0} already exists. Please use a different {1}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
PAGE_DOESNT_BELONG_TO_USER_ORGANIZATION(400, 4006, "Page {0} does not belong to the current user {1} " +
PAGE_DOESNT_BELONG_TO_USER_WORKSPACE(400, 4006, "Page {0} does not belong to the current user {1} " +
"workspace", AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.BAD_REQUEST, null),
UNSUPPORTED_OPERATION(400, 4007, "Unsupported operation", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
DEPRECATED_API(400, 4008, "This API has been deprecated, please contact the Appsmith support for more details.", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
USER_DOESNT_BELONG_ANY_ORGANIZATION(400, 4009, "User {0} does not belong to any workspace",
USER_DOESNT_BELONG_ANY_WORKSPACE(400, 4009, "User {0} does not belong to any workspace",
AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.INTERNAL_ERROR, null),
USER_DOESNT_BELONG_TO_ORGANIZATION(400, 4010, "User {0} does not belong to an workspace with id {1}",
USER_DOESNT_BELONG_TO_WORKSPACE(400, 4010, "User {0} does not belong to an workspace with id {1}",
AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.INTERNAL_ERROR, null),
NO_CONFIGURATION_FOUND_IN_DATASOURCE(400, 4011, "No datasource configuration found. Please configure it and try again.",
AppsmithErrorAction.DEFAULT, "Datasource configuration is invalid", ErrorType.DATASOURCE_CONFIGURATION_ERROR, null),
@ -53,7 +53,7 @@ public enum AppsmithError {
" \"layoutId\" : \"{5}\"," +
" \"dynamicBinding\" : {6}",
AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.BAD_REQUEST, null),
USER_ALREADY_EXISTS_IN_ORGANIZATION(400, 4021, "The user {0} has already been added to the workspace with role {1}. To change the role, please navigate to `Manage Users` page.",
USER_ALREADY_EXISTS_IN_WORKSPACE(400, 4021, "The user {0} has already been added to the workspace with role {1}. To change the role, please navigate to `Manage Users` page.",
AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
UNAUTHORIZED_DOMAIN(401, 4019, "Invalid email domain {0} used for sign in/sign up. Please contact the administrator to configure this domain if this is unexpected.",
AppsmithErrorAction.DEFAULT, null, ErrorType.AUTHENTICATION_ERROR, null),
@ -105,7 +105,7 @@ public enum AppsmithError {
AppsmithErrorAction.DEFAULT, null, ErrorType.CONNECTIVITY_ERROR, null),
DATASOURCE_HAS_ACTIONS(409, 4030, "Cannot delete datasource since it has {0} action(s) using it.",
AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
ORGANIZATION_ID_NOT_GIVEN(400, 4031, "Missing workspace id. Please enter one.", AppsmithErrorAction.DEFAULT, null, ErrorType.ARGUMENT_ERROR, null),
WORKSPACE_ID_NOT_GIVEN(400, 4031, "Missing workspace id. Please enter one.", AppsmithErrorAction.DEFAULT, null, ErrorType.ARGUMENT_ERROR, null),
INVALID_CURL_METHOD(400, 4032, "Invalid method in cURL command: {0}.", AppsmithErrorAction.DEFAULT, null, ErrorType.ARGUMENT_ERROR, null),
OAUTH_NOT_AVAILABLE(500, 5006, "Login with {0} is not supported.", AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.BAD_REQUEST, null),
MARKETPLACE_NOT_CONFIGURED(500, 5007, "Marketplace is not configured.", AppsmithErrorAction.DEFAULT, null, ErrorType.CONFIGURATION_ERROR, null),

View File

@ -759,18 +759,13 @@ public class DatabaseChangelog2 {
}
}
@ChangeSet(order = "009", id = "drop-organization-collection", author = "")
public void dropOrganizationCollection(MongockTemplate mongockTemplate) {
mongockTemplate.dropCollection(Organization.class);
}
/**
* We are creating indexes manually because Spring's index resolver creates indexes on fields as well.
* See https://stackoverflow.com/questions/60867491/ for an explanation of the problem. We have that problem with
* the `Action.datasource` field.
*/
@ChangeSet(order = "010", id = "add-workspace-indexes", author = "")
@ChangeSet(order = "009", id = "add-workspace-indexes", author = "")
public void addWorkspaceIndexes(MongockTemplate mongockTemplate) {
ensureIndexes(mongockTemplate, Workspace.class,
makeIndex("createdAt"),

View File

@ -360,7 +360,7 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE {
return userMono
.flatMap(user -> {
Mono<Workspace> orgMono = workspaceRepository.findById(workspaceId, ORGANIZATION_MANAGE_APPLICATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, workspaceId)));
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, workspaceId)));
return orgMono.map(org -> {
application.setOrganizationId(org.getId());

View File

@ -131,7 +131,7 @@ public class DatasourceServiceCEImpl extends BaseService<DatasourceRepository, D
return userMono
.flatMap(user -> {
Mono<Workspace> orgMono = workspaceService.findById(datasource.getOrganizationId(), ORGANIZATION_MANAGE_APPLICATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, datasource.getOrganizationId())));
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, datasource.getOrganizationId())));
return orgMono.map(org -> {
Set<Policy> policySet = org.getPolicies().stream()
@ -227,7 +227,7 @@ public class DatasourceServiceCEImpl extends BaseService<DatasourceRepository, D
}
if (datasource.getOrganizationId() == null) {
invalids.add(AppsmithError.ORGANIZATION_ID_NOT_GIVEN.getMessage());
invalids.add(AppsmithError.WORKSPACE_ID_NOT_GIVEN.getMessage());
return Mono.just(datasource);
}

View File

@ -181,7 +181,7 @@ public class UserServiceCEImpl extends BaseService<UserRepository, User, String>
Set<String> workspaceIds = user.getOrganizationIds();
if (workspaceIds == null || workspaceIds.isEmpty()) {
return Mono.error(new AppsmithException(AppsmithError.USER_DOESNT_BELONG_ANY_ORGANIZATION, user.getId()));
return Mono.error(new AppsmithException(AppsmithError.USER_DOESNT_BELONG_ANY_WORKSPACE, user.getId()));
}
Optional<String> maybeOrgId = workspaceIds.stream()
@ -194,7 +194,7 @@ public class UserServiceCEImpl extends BaseService<UserRepository, User, String>
}
// Throw an exception if the orgId is not part of the user's workspaces
return Mono.error(new AppsmithException(AppsmithError.USER_DOESNT_BELONG_TO_ORGANIZATION, user.getId(), orgId));
return Mono.error(new AppsmithException(AppsmithError.USER_DOESNT_BELONG_TO_WORKSPACE, user.getId(), orgId));
});
}
@ -673,7 +673,7 @@ public class UserServiceCEImpl extends BaseService<UserRepository, User, String>
// Check if the current user has invite permissions
Mono<Workspace> workspaceMono = workspaceRepository.findById(inviteUsersDTO.getOrgId(), ORGANIZATION_INVITE_USERS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, inviteUsersDTO.getOrgId())))
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, inviteUsersDTO.getOrgId())))
.zipWith(currentUserMono)
.flatMap(tuple -> {
Workspace workspace = tuple.getT1();

View File

@ -96,7 +96,7 @@ public class UserWorkspaceServiceCEImpl implements UserWorkspaceServiceCE {
exampleOrg.setPolicies(null);
return workspaceRepository.findOne(Example.of(exampleOrg))
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, orgId)))
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, orgId)))
.zipWith(currentUserMono)
.map(tuple -> {
Workspace workspace = tuple.getT1();
@ -129,7 +129,7 @@ public class UserWorkspaceServiceCEImpl implements UserWorkspaceServiceCE {
@Override
public Mono<Workspace> addUserRoleToWorkspace(String orgId, UserRole userRole) {
Mono<Workspace> workspaceMono = workspaceRepository.findById(orgId, MANAGE_ORGANIZATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, orgId)));
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, orgId)));
Mono<User> userMono = userRepository.findByEmail(userRole.getUsername())
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.USER)));
@ -151,7 +151,7 @@ public class UserWorkspaceServiceCEImpl implements UserWorkspaceServiceCE {
// Do not add the user if the user already exists in the workspace
for (UserRole role : userRoles) {
if (role.getUsername().equals(userRole.getUsername())) {
return Mono.error(new AppsmithException(AppsmithError.USER_ALREADY_EXISTS_IN_ORGANIZATION, role.getUsername(), role.getRoleName()));
return Mono.error(new AppsmithException(AppsmithError.USER_ALREADY_EXISTS_IN_WORKSPACE, role.getUsername(), role.getRoleName()));
}
}
// User was not found in the workspace. Continue with adding it

View File

@ -145,7 +145,7 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
@Override
public Mono<Workspace> create(Workspace workspace, User user) {
if (workspace == null) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ORGANIZATION));
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.WORKSPACE));
}
// Does the user have permissions to create an workspace?
@ -218,7 +218,7 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
@Override
public Mono<Workspace> update(String id, Workspace resource) {
Mono<Workspace> findWorkspaceMono = repository.findById(id, MANAGE_ORGANIZATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, id)));
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, id)));
// In case the update is not used to update the policies, then set the policies to null to ensure that the
// existing policies are not overwritten.
@ -275,7 +275,7 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
.map(User::getUsername);
return workspaceMono
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, orgId)))
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, orgId)))
.zipWith(usernameMono)
.flatMap(tuple -> {
Workspace workspace = tuple.getT1();
@ -309,7 +309,7 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
public Mono<List<UserRole>> getWorkspaceMembers(String orgId) {
return repository
.findById(orgId, ORGANIZATION_INVITE_USERS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, orgId)))
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, orgId)))
.map(workspace -> {
final List<UserRole> userRoles = workspace.getUserRoles();
return CollectionUtils.isEmpty(userRoles) ? Collections.emptyList() : userRoles;
@ -319,7 +319,7 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
@Override
public Mono<Workspace> uploadLogo(String organizationId, Part filePart) {
final Mono<Workspace> findWorkspaceMono = repository.findById(organizationId, MANAGE_ORGANIZATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, organizationId)));
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, organizationId)));
// We don't execute the upload Mono if we don't find the workspace.
final Mono<Asset> uploadAssetMono = assetService.upload(filePart, Constraint.WORKSPACE_LOGO_SIZE_KB, false);
@ -347,7 +347,7 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
public Mono<Workspace> deleteLogo(String organizationId) {
return repository
.findById(organizationId, MANAGE_ORGANIZATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, organizationId)))
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, organizationId)))
.flatMap(workspace -> {
final String prevAssetId = workspace.getLogoAssetId();
if(prevAssetId == null) {
@ -374,7 +374,7 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
// fetching the org first to make sure user has permission to archive
return repository.findById(workspaceId, MANAGE_ORGANIZATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(
AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, workspaceId
AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, workspaceId
)))
.flatMap(repository::archive);
} else {

View File

@ -43,7 +43,7 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.APPLICATION, srcApplicationId)));
final Mono<Workspace> targetWorkspaceMono = workspaceService.findById(targetWorkspaceId, AclPermission.ORGANIZATION_MANAGE_APPLICATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, targetWorkspaceId)));
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.WORKSPACE, targetWorkspaceId)));
Mono<User> userMono = sessionUserService.getCurrentUser();

View File

@ -232,7 +232,7 @@ public class EmailEventHandlerCEImpl implements EmailEventHandlerCE {
templateParams.put("App_User_Name", CommentConstants.APPSMITH_BOT_NAME);
templateParams.put("Commenter_Name", comment.getAuthorName());
templateParams.put("Application_Name", comment.getApplicationName());
templateParams.put("Organization_Name", workspace.getName());
templateParams.put("Workspace_Name", workspace.getName());
templateParams.put("Comment_Body", CommentUtils.getCommentBody(comment));
templateParams.put("commentUrl", getCommentThreadLink(
application,

View File

@ -695,7 +695,7 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica
})
.then(workspaceService.findById(workspaceId, AclPermission.ORGANIZATION_MANAGE_APPLICATIONS))
.switchIfEmpty(Mono.error(
new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.ORGANIZATION, workspaceId))
new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.WORKSPACE, workspaceId))
)
.flatMap(workspace -> {
// Check if the request is to hydrate the application to DB for particular branch

View File

@ -155,7 +155,7 @@ public class DatasourceServiceTest {
.assertNext(datasource1 -> {
assertThat(datasource1.getName()).isEqualTo(datasource.getName());
assertThat(datasource1.getIsValid()).isFalse();
assertThat(datasource1.getInvalids().contains(AppsmithError.ORGANIZATION_ID_NOT_GIVEN.getMessage()));
assertThat(datasource1.getInvalids().contains(AppsmithError.WORKSPACE_ID_NOT_GIVEN.getMessage()));
})
.verifyComplete();
}

View File

@ -163,7 +163,7 @@ public class WorkspaceServiceTest {
Mono<Workspace> workspaceResponse = workspaceService.create(null);
StepVerifier.create(workspaceResponse)
.expectErrorMatches(throwable -> throwable instanceof AppsmithException &&
throwable.getMessage().equals(AppsmithError.INVALID_PARAMETER.getMessage(FieldName.ORGANIZATION)))
throwable.getMessage().equals(AppsmithError.INVALID_PARAMETER.getMessage(FieldName.WORKSPACE)))
.verify();
}
@ -1071,7 +1071,7 @@ public class WorkspaceServiceTest {
Mono<Workspace> deleteLogo = workspaceService.deleteLogo("");
StepVerifier.create(deleteLogo)
.expectErrorMatches(throwable -> throwable instanceof AppsmithException &&
throwable.getMessage().equals(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.ORGANIZATION, "")))
throwable.getMessage().equals(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.WORKSPACE, "")))
.verify();
}

View File

@ -88,7 +88,7 @@ public class WorkspaceServiceUnitTest {
Mono<List<UserRole>> workspaceMembers = workspaceService.getWorkspaceMembers(sampleOrgId);
StepVerifier
.create(workspaceMembers)
.expectErrorMessage(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.ORGANIZATION, sampleOrgId))
.expectErrorMessage(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.WORKSPACE, sampleOrgId))
.verify();
}
}

View File

@ -413,7 +413,7 @@ public class ApplicationForkingServiceTests {
StepVerifier.create(resultMono)
.expectErrorMatches(throwable -> throwable instanceof AppsmithException &&
throwable.getMessage().equals(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.ORGANIZATION, testUserOrgId)))
throwable.getMessage().equals(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.WORKSPACE, testUserOrgId)))
.verify();
}