Search in sources :

Example 1 with APP_ACCESS_EXCEPTION_MSG

use of org.sagebionetworks.bridge.BridgeConstants.APP_ACCESS_EXCEPTION_MSG in project BridgeServer2 by Sage-Bionetworks.

the class AppController method getAppMemberships.

@GetMapping(path = { "/v1/apps/memberships", "/v3/studies/memberships" }, produces = { APPLICATION_JSON_UTF8_VALUE })
public String getAppMemberships() throws Exception {
    UserSession session = getAuthenticatedSession();
    if (session.getParticipant().getRoles().isEmpty()) {
        throw new UnauthorizedException(APP_ACCESS_EXCEPTION_MSG);
    }
    Stream<App> stream = null;
    if (!session.isSynapseAuthenticated()) {
        // If they have not signed in via Synapse, they cannot switch apps, so don't return any
        stream = ImmutableList.<App>of().stream();
    } else if (session.isInRole(SUPERADMIN)) {
        // Superadmins can see all apps and can switch between all apps.
        stream = appService.getApps().stream().filter(s -> s.isActive());
    } else {
        // Otherwise, apps are linked by Synapse user ID.
        List<String> appIds = accountService.getAppIdsForUser(session.getParticipant().getSynapseUserId());
        stream = appIds.stream().map(id -> appService.getApp(id)).filter(s -> s.isActive() && appIds.contains(s.getIdentifier()));
    }
    List<App> apps = stream.sorted(APP_COMPARATOR).collect(toList());
    return APP_LIST_WRITER.writeValueAsString(new ResourceList<App>(apps, true));
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) AppEmailType(org.sagebionetworks.bridge.services.AppEmailType) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ResourceList(org.sagebionetworks.bridge.models.ResourceList) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) APP_LIST_WRITER(org.sagebionetworks.bridge.models.apps.App.APP_LIST_WRITER) CmsPublicKey(org.sagebionetworks.bridge.models.CmsPublicKey) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) PostMapping(org.springframework.web.bind.annotation.PostMapping) UploadCertificateService(org.sagebionetworks.bridge.services.UploadCertificateService) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Set(java.util.Set) APPLICATION_JSON_UTF8_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE) RestController(org.springframework.web.bind.annotation.RestController) ADMIN(org.sagebionetworks.bridge.Roles.ADMIN) BridgeConfigFactory(org.sagebionetworks.bridge.config.BridgeConfigFactory) List(java.util.List) Stream(java.util.stream.Stream) ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) BridgeUtils(org.sagebionetworks.bridge.BridgeUtils) UploadView(org.sagebionetworks.bridge.models.upload.UploadView) DEVELOPER(org.sagebionetworks.bridge.Roles.DEVELOPER) SynapseException(org.sagebionetworks.client.exceptions.SynapseException) EmailVerificationService(org.sagebionetworks.bridge.services.EmailVerificationService) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) BridgeObjectMapper(org.sagebionetworks.bridge.json.BridgeObjectMapper) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) App(org.sagebionetworks.bridge.models.apps.App) GetMapping(org.springframework.web.bind.annotation.GetMapping) EmailVerificationStatusHolder(org.sagebionetworks.bridge.models.apps.EmailVerificationStatusHolder) WORKER(org.sagebionetworks.bridge.Roles.WORKER) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) APP_ACCESS_EXCEPTION_MSG(org.sagebionetworks.bridge.BridgeConstants.APP_ACCESS_EXCEPTION_MSG) SUPERADMIN(org.sagebionetworks.bridge.Roles.SUPERADMIN) DateTime(org.joda.time.DateTime) UnauthorizedException(org.sagebionetworks.bridge.exceptions.UnauthorizedException) EmailVerificationStatus(org.sagebionetworks.bridge.services.EmailVerificationStatus) HttpStatus(org.springframework.http.HttpStatus) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) Collectors.toList(java.util.stream.Collectors.toList) UploadService(org.sagebionetworks.bridge.services.UploadService) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) Comparator(java.util.Comparator) SynapseProjectIdTeamIdHolder(org.sagebionetworks.bridge.models.apps.SynapseProjectIdTeamIdHolder) Collections(java.util.Collections) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) UnauthorizedException(org.sagebionetworks.bridge.exceptions.UnauthorizedException) ResourceList(org.sagebionetworks.bridge.models.ResourceList) List(java.util.List) ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DateTime (org.joda.time.DateTime)1 APP_ACCESS_EXCEPTION_MSG (org.sagebionetworks.bridge.BridgeConstants.APP_ACCESS_EXCEPTION_MSG)1 BridgeUtils (org.sagebionetworks.bridge.BridgeUtils)1 ADMIN (org.sagebionetworks.bridge.Roles.ADMIN)1 DEVELOPER (org.sagebionetworks.bridge.Roles.DEVELOPER)1 SUPERADMIN (org.sagebionetworks.bridge.Roles.SUPERADMIN)1 WORKER (org.sagebionetworks.bridge.Roles.WORKER)1 BridgeConfigFactory (org.sagebionetworks.bridge.config.BridgeConfigFactory)1 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)1 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)1