@Test public void adminCanEditSomeContributors() { doReturn(false).when(organizationalUnitController).canUpdateOrgUnit(any()); final List<Contributor> contributors = new ArrayList<>(); contributors.add(new Contributor("owner", ContributorType.ADMIN)); service.canEditContributors(contributors, ContributorType.OWNER).then(canEditContributors -> { assertFalse(canEditContributors); return promises.resolve(); }); service.canEditContributors(contributors, ContributorType.ADMIN).then(canEditContributors -> { assertTrue(canEditContributors); return promises.resolve(); }); service.canEditContributors(contributors, ContributorType.CONTRIBUTOR).then(canEditContributors -> { assertTrue(canEditContributors); return promises.resolve(); }); }
@Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { if (organizationalUnitController.canUpdateOrgUnit(libraryPlaces.getActiveSpace())) { return promises.resolve(true); } final Optional<Contributor> contributor = contributors.stream().filter(c -> c.getUsername().equals(sessionInfo.getIdentity().getIdentifier())).findFirst(); if (contributor.isPresent()) { final ContributorType userContributorType = contributor.get().getType(); return promises.resolve(contributorsSecurityUtils.canUserEditContributorOfType(userContributorType, type)); } return promises.resolve(false); }
SpaceContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { if (organizationalUnitController.canUpdateOrgUnit(libraryPlaces.getActiveSpace())) { return promises.resolve(true); } final Optional<Contributor> contributor = contributors.stream().filter(c -> c.getUsername().equals(sessionInfo.getIdentity().getIdentifier())).findFirst(); if (contributor.isPresent()) { final ContributorType userContributorType = contributor.get().getType(); return promises.resolve(contributorsSecurityUtils.canUserEditContributorOfType(userContributorType, type)); } return promises.resolve(false); } }
SpaceContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { if (organizationalUnitController.canUpdateOrgUnit(libraryPlaces.getActiveSpace())) { return promises.resolve(true); } final Optional<Contributor> contributor = contributors.stream().filter(c -> c.getUsername().equals(sessionInfo.getIdentity().getIdentifier())).findFirst(); if (contributor.isPresent()) { final ContributorType userContributorType = contributor.get().getType(); return promises.resolve(contributorsSecurityUtils.canUserEditContributorOfType(userContributorType, type)); } return promises.resolve(false); } @Inject  SpaceContributorsListServiceImpl(final LibraryPlaces libraryPlaces,
                                            final Caller<OrganizationalUnitService> organizationalUnitService,
                                            final Event<AfterEditOrganizationalUnitEvent> afterEditOrganizationalUnitEvent,
                                            final Caller<LibraryService> libraryService,
                                            final SessionInfo sessionInfo,
                                            final OrganizationalUnitController organizationalUnitController,
                                            final ContributorsSecurityUtils contributorsSecurityUtils,
                                            final Promises promises); }
SpaceContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { if (organizationalUnitController.canUpdateOrgUnit(libraryPlaces.getActiveSpace())) { return promises.resolve(true); } final Optional<Contributor> contributor = contributors.stream().filter(c -> c.getUsername().equals(sessionInfo.getIdentity().getIdentifier())).findFirst(); if (contributor.isPresent()) { final ContributorType userContributorType = contributor.get().getType(); return promises.resolve(contributorsSecurityUtils.canUserEditContributorOfType(userContributorType, type)); } return promises.resolve(false); } @Inject  SpaceContributorsListServiceImpl(final LibraryPlaces libraryPlaces,
                                            final Caller<OrganizationalUnitService> organizationalUnitService,
                                            final Event<AfterEditOrganizationalUnitEvent> afterEditOrganizationalUnitEvent,
                                            final Caller<LibraryService> libraryService,
                                            final SessionInfo sessionInfo,
                                            final OrganizationalUnitController organizationalUnitController,
                                            final ContributorsSecurityUtils contributorsSecurityUtils,
                                            final Promises promises); @Override void getContributors(Consumer<List<Contributor>> contributorsConsumer); @Override void saveContributors(final List<Contributor> contributors,
                                 final Runnable successCallback,
                                 final ErrorCallback<Message> errorCallback); @Override Promise<Boolean> canEditContributors(final List<Contributor> contributors,
                                                final ContributorType type); @Override void getValidUsernames(final Consumer<List<String>> validUsernamesConsumer); @Override void onExternalChange(final Consumer<Collection<Contributor>> contributorsConsumer); @Override boolean requireValidUsername(); @Override String getInvalidNameMessageConstant(); void onSpaceContributorsUpdatedEvent(@Observes final SpaceContributorsUpdatedEvent spaceContributorsUpdatedEvent); }
SpaceContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { if (organizationalUnitController.canUpdateOrgUnit(libraryPlaces.getActiveSpace())) { return promises.resolve(true); } final Optional<Contributor> contributor = contributors.stream().filter(c -> c.getUsername().equals(sessionInfo.getIdentity().getIdentifier())).findFirst(); if (contributor.isPresent()) { final ContributorType userContributorType = contributor.get().getType(); return promises.resolve(contributorsSecurityUtils.canUserEditContributorOfType(userContributorType, type)); } return promises.resolve(false); } @Inject  SpaceContributorsListServiceImpl(final LibraryPlaces libraryPlaces,
                                            final Caller<OrganizationalUnitService> organizationalUnitService,
                                            final Event<AfterEditOrganizationalUnitEvent> afterEditOrganizationalUnitEvent,
                                            final Caller<LibraryService> libraryService,
                                            final SessionInfo sessionInfo,
                                            final OrganizationalUnitController organizationalUnitController,
                                            final ContributorsSecurityUtils contributorsSecurityUtils,
                                            final Promises promises); @Override void getContributors(Consumer<List<Contributor>> contributorsConsumer); @Override void saveContributors(final List<Contributor> contributors,
                                 final Runnable successCallback,
                                 final ErrorCallback<Message> errorCallback); @Override Promise<Boolean> canEditContributors(final List<Contributor> contributors,
                                                final ContributorType type); @Override void getValidUsernames(final Consumer<List<String>> validUsernamesConsumer); @Override void onExternalChange(final Consumer<Collection<Contributor>> contributorsConsumer); @Override boolean requireValidUsername(); @Override String getInvalidNameMessageConstant(); void onSpaceContributorsUpdatedEvent(@Observes final SpaceContributorsUpdatedEvent spaceContributorsUpdatedEvent);  }