Removed the usage of get current organization id. Requires addition of organization id to a few api calls.
This commit is contained in:
parent
1923f0ddea
commit
a31796a216
|
|
@ -9,5 +9,7 @@ public class PluginOrgDTO {
|
||||||
|
|
||||||
String pluginId;
|
String pluginId;
|
||||||
|
|
||||||
|
String organizationId;
|
||||||
|
|
||||||
OrganizationPluginStatus status;
|
OrganizationPluginStatus status;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -521,13 +521,8 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
||||||
actionExample.setPageId(params.getFirst(FieldName.PAGE_ID));
|
actionExample.setPageId(params.getFirst(FieldName.PAGE_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
Mono<String> orgIdMono = sessionUserService
|
|
||||||
.getCurrentUser()
|
|
||||||
.map(user -> user.getCurrentOrganizationId());
|
|
||||||
|
|
||||||
if (params.getFirst(FieldName.APPLICATION_ID) != null) {
|
if (params.getFirst(FieldName.APPLICATION_ID) != null) {
|
||||||
return orgIdMono
|
return pageService
|
||||||
.flatMapMany(orgId -> pageService
|
|
||||||
.findNamesByApplicationId(params.getFirst(FieldName.APPLICATION_ID))
|
.findNamesByApplicationId(params.getFirst(FieldName.APPLICATION_ID))
|
||||||
.switchIfEmpty(Mono.error(new AppsmithException(
|
.switchIfEmpty(Mono.error(new AppsmithException(
|
||||||
AppsmithError.NO_RESOURCE_FOUND, "pages for application", params.getFirst(FieldName.APPLICATION_ID)))
|
AppsmithError.NO_RESOURCE_FOUND, "pages for application", params.getFirst(FieldName.APPLICATION_ID)))
|
||||||
|
|
@ -537,18 +532,12 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
||||||
.map(pageNameIdDTO -> {
|
.map(pageNameIdDTO -> {
|
||||||
Action example = new Action();
|
Action example = new Action();
|
||||||
example.setPageId(pageNameIdDTO.getId());
|
example.setPageId(pageNameIdDTO.getId());
|
||||||
example.setOrganizationId(orgId);
|
|
||||||
return example;
|
return example;
|
||||||
})
|
})
|
||||||
.flatMap(example -> repository.findAll(Example.of(example), sort))
|
.flatMap(example -> repository.findAll(Example.of(example), sort))
|
||||||
)
|
|
||||||
.flatMap(this::setTransientFieldsInAction);
|
.flatMap(this::setTransientFieldsInAction);
|
||||||
}
|
}
|
||||||
return orgIdMono
|
return repository.findAll(Example.of(actionExample), sort)
|
||||||
.flatMapMany(orgId -> {
|
|
||||||
actionExample.setOrganizationId(orgId);
|
|
||||||
return repository.findAll(Example.of(actionExample), sort);
|
|
||||||
})
|
|
||||||
.flatMap(this::setTransientFieldsInAction);
|
.flatMap(this::setTransientFieldsInAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ public interface ApplicationPageService {
|
||||||
|
|
||||||
Mono<Application> addPageToApplication(Mono<Application> applicationMono, Page page, Boolean isDefault);
|
Mono<Application> addPageToApplication(Mono<Application> applicationMono, Page page, Boolean isDefault);
|
||||||
|
|
||||||
Mono<Page> doesPageBelongToCurrentUserOrganization(Page page);
|
|
||||||
|
|
||||||
Mono<Page> getPage(String pageId, Boolean viewMode);
|
Mono<Page> getPage(String pageId, Boolean viewMode);
|
||||||
|
|
||||||
Mono<Application> createApplication(Application application, String orgId);
|
Mono<Application> createApplication(Application application, String orgId);
|
||||||
|
|
|
||||||
|
|
@ -117,21 +117,6 @@ public class ApplicationPageServiceImpl implements ApplicationPageService {
|
||||||
.flatMap(applicationService::save);
|
.flatMap(applicationService::save);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<Page> doesPageBelongToCurrentUserOrganization(Page page) {
|
|
||||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
|
||||||
final String[] username = {null};
|
|
||||||
|
|
||||||
return userMono
|
|
||||||
.map(user -> {
|
|
||||||
username[0] = user.getEmail();
|
|
||||||
return user;
|
|
||||||
})
|
|
||||||
.flatMap(user -> applicationService.findByIdAndOrganizationId(page.getApplicationId(), user.getCurrentOrganizationId()))
|
|
||||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.PAGE_DOESNT_BELONG_TO_USER_ORGANIZATION, page.getId(), username[0])))
|
|
||||||
//If mono transmits, then application id belongs to the current user's organization. Return page.
|
|
||||||
.then(Mono.just(page));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Page> getPage(String pageId, Boolean viewMode) {
|
public Mono<Page> getPage(String pageId, Boolean viewMode) {
|
||||||
return pageService.findById(pageId, READ_PAGES)
|
return pageService.findById(pageId, READ_PAGES)
|
||||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGE_ID)))
|
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGE_ID)))
|
||||||
|
|
|
||||||
|
|
@ -243,12 +243,17 @@ public class DatasourceServiceImpl extends BaseService<DatasourceRepository, Dat
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<Datasource> get(MultiValueMap<String, String> params) {
|
public Flux<Datasource> get(MultiValueMap<String, String> params) {
|
||||||
|
/**
|
||||||
|
* Note : Currently this API is ONLY used to fetch datasources for an organization.
|
||||||
|
*/
|
||||||
|
if (params.getFirst(FieldName.ORGANIZATION_ID) != null) {
|
||||||
|
return repository.findAllByOrganizationId(params.getFirst(FieldName.ORGANIZATION_ID), AclPermission.READ_DATASOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
return sessionUserService
|
return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ORGANIZATION_ID));
|
||||||
.getCurrentUser()
|
|
||||||
.flatMapMany(user -> repository.findAllByOrganizationId(user.getCurrentOrganizationId(), AclPermission.READ_DATASOURCES));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,6 @@ public class LayoutServiceImpl implements LayoutService {
|
||||||
public Mono<Layout> getLayout(String pageId, String layoutId, Boolean viewMode) {
|
public Mono<Layout> getLayout(String pageId, String layoutId, Boolean viewMode) {
|
||||||
return pageService.findByIdAndLayoutsId(pageId, layoutId)
|
return pageService.findByIdAndLayoutsId(pageId, layoutId)
|
||||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGE_ID + " or " + FieldName.LAYOUT_ID)))
|
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.PAGE_ID + " or " + FieldName.LAYOUT_ID)))
|
||||||
.flatMap(applicationPageService::doesPageBelongToCurrentUserOrganization)
|
|
||||||
//The pageId given is correct and belongs to the current user's organization.
|
|
||||||
.map(page -> {
|
.map(page -> {
|
||||||
List<Layout> layoutList = page.getLayouts();
|
List<Layout> layoutList = page.getLayouts();
|
||||||
//Because the findByIdAndLayoutsId call returned non-empty result, we are guaranteed to find the layoutId here.
|
//Because the findByIdAndLayoutsId call returned non-empty result, we are guaranteed to find the layoutId here.
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import com.appsmith.server.domains.Organization;
|
||||||
import com.appsmith.server.domains.OrganizationPlugin;
|
import com.appsmith.server.domains.OrganizationPlugin;
|
||||||
import com.appsmith.server.domains.Plugin;
|
import com.appsmith.server.domains.Plugin;
|
||||||
import com.appsmith.server.domains.PluginType;
|
import com.appsmith.server.domains.PluginType;
|
||||||
import com.appsmith.server.domains.User;
|
|
||||||
import com.appsmith.server.dtos.InstallPluginRedisDTO;
|
import com.appsmith.server.dtos.InstallPluginRedisDTO;
|
||||||
import com.appsmith.server.dtos.OrganizationPluginStatus;
|
import com.appsmith.server.dtos.OrganizationPluginStatus;
|
||||||
import com.appsmith.server.dtos.PluginOrgDTO;
|
import com.appsmith.server.dtos.PluginOrgDTO;
|
||||||
|
|
@ -84,10 +83,15 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
||||||
@Override
|
@Override
|
||||||
public Flux<Plugin> get(MultiValueMap<String, String> params) {
|
public Flux<Plugin> get(MultiValueMap<String, String> params) {
|
||||||
|
|
||||||
return sessionUserService.getCurrentUser()
|
String organizationId = params.getFirst(FieldName.ORGANIZATION_ID);
|
||||||
.flatMapMany(user -> {
|
if (organizationId == null) {
|
||||||
log.debug("Going to filter plugin params for user: {}", user.getEmail());
|
return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ORGANIZATION_ID));
|
||||||
return organizationService.findById(user.getCurrentOrganizationId())
|
}
|
||||||
|
|
||||||
|
// TODO : Think about the various scenarios where this plugin api is called and then decide on permissions.
|
||||||
|
Mono<Organization> organizationMono = organizationService.findById(organizationId);
|
||||||
|
|
||||||
|
return organizationMono
|
||||||
.flatMapMany(org -> {
|
.flatMapMany(org -> {
|
||||||
log.debug("Fetching plugins by params: {} for org: {}", params, org.getName());
|
log.debug("Fetching plugins by params: {} for org: {}", params, org.getName());
|
||||||
if (org.getPlugins() == null) {
|
if (org.getPlugins() == null) {
|
||||||
|
|
@ -114,7 +118,6 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
||||||
}
|
}
|
||||||
return mongoTemplate.find(query, Plugin.class);
|
return mongoTemplate.find(query, Plugin.class);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -137,9 +140,11 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
||||||
if (pluginOrgDTO.getPluginId() == null) {
|
if (pluginOrgDTO.getPluginId() == null) {
|
||||||
return Mono.error(new AppsmithException(AppsmithError.PLUGIN_ID_NOT_GIVEN));
|
return Mono.error(new AppsmithException(AppsmithError.PLUGIN_ID_NOT_GIVEN));
|
||||||
}
|
}
|
||||||
|
if (pluginOrgDTO.getOrganizationId() == null) {
|
||||||
|
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ORGANIZATION_ID));
|
||||||
|
}
|
||||||
|
|
||||||
return Mono.just(pluginOrgDTO)
|
return storeOrganizationPlugin(pluginOrgDTO, pluginOrgDTO.getStatus())
|
||||||
.flatMap(plugin -> storeOrganizationPlugin(plugin, pluginOrgDTO.getStatus()))
|
|
||||||
.switchIfEmpty(Mono.empty());
|
.switchIfEmpty(Mono.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,47 +153,46 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
||||||
if (pluginDTO.getPluginId() == null) {
|
if (pluginDTO.getPluginId() == null) {
|
||||||
return Mono.error(new AppsmithException(AppsmithError.PLUGIN_ID_NOT_GIVEN));
|
return Mono.error(new AppsmithException(AppsmithError.PLUGIN_ID_NOT_GIVEN));
|
||||||
}
|
}
|
||||||
|
if (pluginDTO.getOrganizationId() == null) {
|
||||||
|
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ORGANIZATION_ID));
|
||||||
|
}
|
||||||
|
|
||||||
//Find the organization using id and plugin id -> This is to find if the organization has the plugin installed
|
//Find the organization using id and plugin id -> This is to find if the organization has the plugin installed
|
||||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
Mono<Organization> organizationMono = organizationService.findByIdAndPluginsPluginId(pluginDTO.getOrganizationId(),
|
||||||
Mono<Organization> organizationMono = userMono.flatMap(user ->
|
pluginDTO.getPluginId());
|
||||||
organizationService.findByIdAndPluginsPluginId(user.getCurrentOrganizationId(), pluginDTO.getPluginId()));
|
|
||||||
|
|
||||||
return organizationMono
|
return organizationMono
|
||||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.PLUGIN_NOT_INSTALLED, pluginDTO.getPluginId())))
|
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.PLUGIN_NOT_INSTALLED, pluginDTO.getPluginId())))
|
||||||
//In case the plugin is not found for the organization, the organizationMono would not emit and the rest of the flow would stop
|
//In case the plugin is not found for the organization, the organizationMono would not emit and the rest of the flow would stop
|
||||||
//i.e. the rest of the code flow would only happen when there is a plugin found for the organization that can
|
//i.e. the rest of the code flow would only happen when there is a plugin found for the organization that can
|
||||||
//be uninstalled.
|
//be uninstalled.
|
||||||
.map(organization -> {
|
.flatMap(organization -> {
|
||||||
List<OrganizationPlugin> organizationPluginList = organization.getPlugins();
|
List<OrganizationPlugin> organizationPluginList = organization.getPlugins();
|
||||||
organizationPluginList.removeIf(listPlugin -> listPlugin.getPluginId().equals(pluginDTO.getPluginId()));
|
organizationPluginList.removeIf(listPlugin -> listPlugin.getPluginId().equals(pluginDTO.getPluginId()));
|
||||||
organization.setPlugins(organizationPluginList);
|
organization.setPlugins(organizationPluginList);
|
||||||
return organization;
|
return organizationService.save(organization);
|
||||||
})
|
});
|
||||||
.flatMap(organizationService::save);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<Organization> storeOrganizationPlugin(PluginOrgDTO pluginDTO, OrganizationPluginStatus status) {
|
private Mono<Organization> storeOrganizationPlugin(PluginOrgDTO pluginDTO, OrganizationPluginStatus status) {
|
||||||
|
|
||||||
//Find the organization using id and plugin id -> This is to find if the organization already has the plugin installed
|
Mono<Organization> pluginInOrganizationMono = organizationService
|
||||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
.findByIdAndPluginsPluginId(pluginDTO.getOrganizationId(), pluginDTO.getPluginId());
|
||||||
Mono<Organization> pluginInOrganizationMono = userMono.flatMap(user ->
|
|
||||||
organizationService.findByIdAndPluginsPluginId(user.getCurrentOrganizationId(), pluginDTO.getPluginId()));
|
|
||||||
|
|
||||||
|
|
||||||
//If plugin is already present for the organization, just return the organization, else install and return organization
|
//If plugin is already present for the organization, just return the organization, else install and return organization
|
||||||
return pluginInOrganizationMono
|
return pluginInOrganizationMono
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
.switchIfEmpty(Mono.defer(() -> {
|
||||||
log.debug("Plugin {} not already installed. Running the switch if empty code block", pluginDTO.getPluginId());
|
log.debug("Plugin {} not already installed. Installing now", pluginDTO.getPluginId());
|
||||||
//If the plugin is not found in the organization, its not installed already. Install now.
|
//If the plugin is not found in the organization, its not installed already. Install now.
|
||||||
return repository
|
return repository
|
||||||
.findById(pluginDTO.getPluginId())
|
.findById(pluginDTO.getPluginId())
|
||||||
.zipWith(userMono, (plugin, user) -> {
|
.map(plugin -> {
|
||||||
|
|
||||||
log.debug("Before publishing to the redis queue");
|
log.debug("Before publishing to the redis queue");
|
||||||
//Publish the event to the pub/sub queue
|
//Publish the event to the pub/sub queue
|
||||||
InstallPluginRedisDTO installPluginRedisDTO = new InstallPluginRedisDTO();
|
InstallPluginRedisDTO installPluginRedisDTO = new InstallPluginRedisDTO();
|
||||||
installPluginRedisDTO.setOrganizationId(user.getCurrentOrganizationId());
|
installPluginRedisDTO.setOrganizationId(pluginDTO.getOrganizationId());
|
||||||
installPluginRedisDTO.setPluginOrgDTO(pluginDTO);
|
installPluginRedisDTO.setPluginOrgDTO(pluginDTO);
|
||||||
String jsonString;
|
String jsonString;
|
||||||
try {
|
try {
|
||||||
|
|
@ -202,13 +206,12 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
||||||
.subscribe();
|
.subscribe();
|
||||||
})
|
})
|
||||||
//Now that the plugin jar has been successfully downloaded, go on and add the plugin to the organization
|
//Now that the plugin jar has been successfully downloaded, go on and add the plugin to the organization
|
||||||
.then(userMono)
|
.then(organizationService.findById(pluginDTO.getOrganizationId()))
|
||||||
.flatMap(user -> organizationService.findById(user.getCurrentOrganizationId()))
|
.flatMap(organization -> {
|
||||||
.map(organization -> {
|
|
||||||
|
|
||||||
List<OrganizationPlugin> organizationPluginList = organization.getPlugins();
|
List<OrganizationPlugin> organizationPluginList = organization.getPlugins();
|
||||||
if (organizationPluginList == null) {
|
if (organizationPluginList == null) {
|
||||||
organizationPluginList = new ArrayList<OrganizationPlugin>();
|
organizationPluginList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
OrganizationPlugin organizationPlugin = new OrganizationPlugin();
|
OrganizationPlugin organizationPlugin = new OrganizationPlugin();
|
||||||
|
|
@ -219,9 +222,8 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
||||||
|
|
||||||
log.debug("Going to save the organization with install plugin. This means that installation has been successful");
|
log.debug("Going to save the organization with install plugin. This means that installation has been successful");
|
||||||
|
|
||||||
return organization;
|
return organizationService.save(organization);
|
||||||
})
|
});
|
||||||
.flatMap(organizationService::save);
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
||||||
* platform. This flow also ensures that a personal workspace name is created for the user. The new user is then
|
* platform. This flow also ensures that a personal workspace name is created for the user. The new user is then
|
||||||
* given admin permissions to the personal workspace.
|
* given admin permissions to the personal workspace.
|
||||||
* <p>
|
* <p>
|
||||||
* For new user invite flow, please {@link UserOrganizationService#inviteUserNew(InviteUserDTO, String)}
|
* For new user invite flow, please {@link UserService#inviteUser(InviteUserDTO, String)}
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
* @return
|
* @return
|
||||||
|
|
|
||||||
|
|
@ -38,5 +38,5 @@ spring.mail.host=email-smtp.us-east-1.amazonaws.com
|
||||||
spring.mail.port=587
|
spring.mail.port=587
|
||||||
spring.mail.username=AKIAVWHAAGIQOHPT4BZ7
|
spring.mail.username=AKIAVWHAAGIQOHPT4BZ7
|
||||||
spring.mail.password=BEE5W6i7YznAJ/YDOLbppovmOlRzxXElJ+uJtGhdCfjY
|
spring.mail.password=BEE5W6i7YznAJ/YDOLbppovmOlRzxXElJ+uJtGhdCfjY
|
||||||
spring.mail.properties.mail.smtp.auth=true
|
spring.mail.properties.mail.smtp.auth=false
|
||||||
spring.mail.properties.mail.smtp.starttls.enable=true
|
spring.mail.properties.mail.smtp.starttls.enable=true
|
||||||
Loading…
Reference in New Issue
Block a user