@Test public void userCanEditContributors() { doReturn(promises.resolve(true)).when(projectController).canUpdateProject(any()); service.canEditContributors(Collections.emptyList(), ContributorType.CONTRIBUTOR).then(canEditContributors -> { assertTrue(canEditContributors); return promises.resolve(); }); }
@Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { return projectController.canUpdateProject(libraryPlaces.getActiveWorkspace()).then(canUpdateProject -> { if (canUpdateProject) { 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); }); }
ProjectContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { return projectController.canUpdateProject(libraryPlaces.getActiveWorkspace()).then(canUpdateProject -> { if (canUpdateProject) { 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); }); } }
ProjectContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { return projectController.canUpdateProject(libraryPlaces.getActiveWorkspace()).then(canUpdateProject -> { if (canUpdateProject) { 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  ProjectContributorsListServiceImpl(final LibraryPlaces libraryPlaces,
                                              final Caller<RepositoryService> repositoryService,
                                              final SpaceContributorsListServiceImpl spaceContributorsListService,
                                              final SessionInfo sessionInfo,
                                              final ProjectController projectController,
                                              final ContributorsSecurityUtils contributorsSecurityUtils,
                                              final Promises promises); }
ProjectContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { return projectController.canUpdateProject(libraryPlaces.getActiveWorkspace()).then(canUpdateProject -> { if (canUpdateProject) { 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  ProjectContributorsListServiceImpl(final LibraryPlaces libraryPlaces,
                                              final Caller<RepositoryService> repositoryService,
                                              final SpaceContributorsListServiceImpl spaceContributorsListService,
                                              final SessionInfo sessionInfo,
                                              final ProjectController projectController,
                                              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(Consumer<List<String>> validUsernamesConsumer); @Override void onExternalChange(final Consumer<Collection<Contributor>> contributorsConsumer); @Override boolean requireValidUsername(); @Override String getInvalidNameMessageConstant(); void onRepositoryContributorsUpdatedEvent(@Observes final RepositoryContributorsUpdatedEvent repositoryContributorsUpdatedEvent); }
ProjectContributorsListServiceImpl implements ContributorsListService { @Override public Promise<Boolean> canEditContributors(final List<Contributor> contributors, final ContributorType type) { return projectController.canUpdateProject(libraryPlaces.getActiveWorkspace()).then(canUpdateProject -> { if (canUpdateProject) { 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  ProjectContributorsListServiceImpl(final LibraryPlaces libraryPlaces,
                                              final Caller<RepositoryService> repositoryService,
                                              final SpaceContributorsListServiceImpl spaceContributorsListService,
                                              final SessionInfo sessionInfo,
                                              final ProjectController projectController,
                                              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(Consumer<List<String>> validUsernamesConsumer); @Override void onExternalChange(final Consumer<Collection<Contributor>> contributorsConsumer); @Override boolean requireValidUsername(); @Override String getInvalidNameMessageConstant(); void onRepositoryContributorsUpdatedEvent(@Observes final RepositoryContributorsUpdatedEvent repositoryContributorsUpdatedEvent);  }