Пример #1
0
 @Deprecated()
 public CruiseConfig loadCruiseConfigForEdit(
     Username username, HttpLocalizedOperationResult result) {
   if (!isUserAdmin(username) && !isUserTemplateAdmin(username)) {
     result.unauthorized(
         LocalizedMessage.string("UNAUTHORIZED_TO_ADMINISTER"), HealthStateType.unauthorised());
   }
   return clonedConfigForEdit();
 }
Пример #2
0
 private boolean isAuthorized() {
   if (!(goConfigService.isUserAdmin(username)
       || goConfigService.isGroupAdministrator(username.getUsername()))) {
     result.unauthorized(
         LocalizedMessage.string("UNAUTHORIZED_TO_EDIT"), HealthStateType.unauthorised());
     return false;
   }
   return true;
 }
Пример #3
0
 private boolean isAdminOfGroup(
     String toGroupName, Username username, HttpLocalizedOperationResult result) {
   if (!isUserAdminOfGroup(username.getUsername(), toGroupName)) {
     result.unauthorized(
         LocalizedMessage.string("UNAUTHORIZED_TO_EDIT_GROUP", toGroupName),
         HealthStateType.unauthorised());
     return false;
   }
   return true;
 }
  @Test
  public void shouldNotContinueIfTheUserDontHavePermissionsToOperateOnPackageRepositories()
      throws Exception {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    CreatePackageRepositoryCommand command =
        new CreatePackageRepositoryCommand(
            goConfigService, packageRepositoryService, packageRepository, currentUser, result);

    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.unauthorized(
        LocalizedMessage.string("UNAUTHORIZED_TO_EDIT"), HealthStateType.unauthorised());

    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result, is(expectedResult));
  }