jetbrains.buildServer.users.SUser Java Examples

The following examples show how to use jetbrains.buildServer.users.SUser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 6 votes vote down vote up
private SlackNotification createNotification(SUser sUser) {
    SlackNotification notification = notificationFactory.getSlackNotification();
    String userId = sUser.getPropertyValue(USERID_KEY);
    notification.setChannel(userId);
    notification.setTeamName(mainConfig.getTeamName());
    notification.setToken(mainConfig.getToken());
    notification.setFilterBranchName(mainConfig.getFilterBranchName());
    notification.setIconUrl(mainConfig.getIconUrl());
    notification.setBotName(mainConfig.getBotName());
    notification.setEnabled(mainConfig.getEnabled());
    notification.setShowBuildAgent(mainConfig.getShowBuildAgent());
    notification.setShowElapsedBuildTime(mainConfig.getShowElapsedBuildTime());
    notification.setShowCommits(mainConfig.getShowCommits());
    notification.setMaxCommitsToDisplay(mainConfig.getMaxCommitsToDisplay());
    notification.setMentionChannelEnabled(false);
    notification.setShowFailureReason(mainConfig.getShowFailureReason());

    return notification;

}
 
Example #2
Source File: PayloadContentCommits.java    From tcSlackBuildNotifier with MIT License 6 votes vote down vote up
public void populateCommits(SRunningBuild sRunningBuild) {
    List<SVcsModification> changes = sRunningBuild.getContainingChanges();
    if (changes == null) {
        return;
    }

    for (SVcsModification change : changes) {
        Collection<SUser> committers = change.getCommitters();
        String slackUserId = null;
        if (!committers.isEmpty()) {
            SUser committer = committers.iterator().next();
            slackUserId = committer.getPropertyValue(SlackNotificator.USERID_KEY);
            Loggers.ACTIVITIES.debug("Resolved committer " + change.getUserName() + " to Slack User " + slackUserId);
        }
        commits.add(new Commit(change.getVersion(), change.getDescription(), change.getUserName(), slackUserId));
    }
}
 
Example #3
Source File: ServerPrincipalFactory.java    From teamcity-oauth with Apache License 2.0 6 votes vote down vote up
@NotNull
public Optional<ServerPrincipal> getServerPrincipal(@NotNull final OAuthUser user, boolean allowCreatingNewUsersByLogin) {
    Optional<ServerPrincipal> existingPrincipal = findExistingPrincipal(user.getId());
    if (existingPrincipal.isPresent()) {
        LOG.info("Use existing user: " + user.getId());
        return existingPrincipal;
    } else if (allowCreatingNewUsersByLogin) {
        LOG.info("Creating user: " + user);
        SUser created = userModel.createUserAccount(PluginConstants.OAUTH_AUTH_SCHEME_NAME, user.getId());
        created.setUserProperty(PluginConstants.ID_USER_PROPERTY_KEY, user.getId());
        created.updateUserAccount(user.getId(), user.getName(), user.getEmail());
        return Optional.of(new ServerPrincipal(PluginConstants.OAUTH_AUTH_SCHEME_NAME, user.getId()));
    } else {
        LOG.info("User: " + user + " could not be found and allowCreatingNewUsersByLogin is disabled");
        return existingPrincipal;
    }
}
 
Example #4
Source File: DownloadSymbolsControllerTest.java    From teamcity-symbol-server with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "Booleans")
public void request_pdb_guid_case_insensitive(boolean lowercaseSignature) throws Exception{
  myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
  SUser user = myFixture.getUserModel().getGuestUser();
  user.addRole(RoleScope.projectScope(myProject.getProjectId()), getProjectDevRole());
  assertTrue(user.isPermissionGrantedForProject(myProject.getProjectId(), Permission.VIEW_BUILD_RUNTIME_DATA));

  final String fileSignatureUpper = "8EF4E863187C45E78F4632152CC82FEB";
  final String fileSignature = lowercaseSignature ? fileSignatureUpper.toLowerCase() : fileSignatureUpper;
  final String guid = "8EF4E863187C45E78F4632152CC82FE";
  final String fileName = "secur32.pdb";
  final String filePath = "foo/secur32.pdb";
  final byte[] fileContent = new byte[]{(byte) (lowercaseSignature ? 1 : 0)};

  RunningBuildEx build = startBuild();
  build.publishArtifact(filePath, fileContent);
  finishBuild(build, false);

  myBuildMetadataStorage.addEntry(build.getBuildId(), guid.toLowerCase(), fileName, filePath);
  myRequest.setRequestURI("mock", String.format("/app/symbols/%s/%s/%s", fileName, fileSignature, fileName));

  doGet();

  assertEquals(-1, myResponse.getStatus());
  assertTrue("Returned data did not match set pdb data", Arrays.equals(fileContent, myResponse.getReturnedBytes()));
}
 
Example #5
Source File: UserTelegramSettingsExtension.java    From teamcity-telegram-plugin with Apache License 2.0 6 votes vote down vote up
public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRequest request) {
  SUser user = SessionUser.getUser(request);
  String userIdStr = request.getParameter("userId");
  if (userIdStr != null) {
    long userId = Long.parseLong(userIdStr);
    user = userModel.findUserById(userId);
    if (user == null) {
      throw new UserNotFoundException(userId, "User with id " + userIdStr + " does not exist");
    }
  }

  boolean telegramNotConfigured = true;
  if (rulesManager.isRulesWithEventsConfigured(user.getId(), this.getPluginName())) {
    String chatId = user.getPropertyValue(TelegramNotificator.TELEGRAM_PROP_KEY);
    telegramNotConfigured = StringUtil.isEmpty(chatId);
  }

  model.put("showTelegramNotConfiguredWarning", telegramNotConfigured);
  model.put("showTelegramPausedWarning", settingsManager.getSettings().isPaused());
}
 
Example #6
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyBuildProblemResponsibleAssigned(@NotNull Collection<BuildProblemInfo> buildProblems,
                                                  @NotNull ResponsibilityEntry entry,
                                                  @NotNull SProject project,
                                                  @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getBuildProblemsResponsibilityAssignedMap(buildProblems, entry, project, users);
  this.sendNotification(root, users, "build_problem_responsibility_assigned_to_me");
}
 
Example #7
Source File: ServerPrincipalFactory.java    From teamcity-oauth with Apache License 2.0 5 votes vote down vote up
@NotNull
private Optional<ServerPrincipal> findExistingPrincipal(@NotNull final String userName) {
    try {
        final SUser user = userModel.findUserByUsername(userName, PluginConstants.ID_USER_PROPERTY_KEY);
        return Optional.ofNullable(user).map(u -> new ServerPrincipal(PluginConstants.OAUTH_AUTH_SCHEME_NAME, user.getUsername()));
    } catch (InvalidUsernameException e) {
        // ignore it
        return Optional.empty();
    }
}
 
Example #8
Source File: DownloadSymbolsControllerTest.java    From teamcity-symbol-server with Apache License 2.0 5 votes vote down vote up
@Test
public void request_file_with_plus_sign() throws Exception{
  myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);

  SUser user = myFixture.getUserModel().getGuestUser();
  user.addRole(RoleScope.projectScope(myProject.getProjectId()), getProjectDevRole());
  assertTrue(user.isPermissionGrantedForProject(myProject.getProjectId(), Permission.VIEW_BUILD_RUNTIME_DATA));

  final File artDirectory = createTempDir();
  final String fileName = "file++.pdb";
  File file = new File(artDirectory, fileName);
  assertTrue(file.createNewFile());
  FileUtil.writeFile(file, "text", "UTF-8");

  myBuildType.setArtifactPaths(artDirectory.getAbsolutePath());
  RunningBuildEx build = startBuild();
  build.publishArtifact(fileName, file);
  finishBuild(build, false);

  final String fileSignature = "8EF4E863187C45E78F4632152CC82FEB";
  final String guid = "8EF4E863187C45E78F4632152CC82FE";

  myBuildMetadataStorage.addEntry(build.getBuildId(), guid.toLowerCase(), fileName, fileName);
  myRequest.setRequestURI("mock", String.format("/app/symbols/%s/%s/%s", fileName, fileSignature, fileName));

  doGet();

  assertEquals(-1, myResponse.getStatus());
  assertEquals("text", myResponse.getReturnedContent());

  myRequest.setRequestURI("mock", String.format("/app/symbols/%s/%s/%s", "file%2b%2b.pdb", fileSignature, fileName));

  doGet();

  assertEquals(-1, myResponse.getStatus());
  assertEquals("text", myResponse.getReturnedContent());
}
 
Example #9
Source File: DownloadSymbolsControllerTest.java    From teamcity-symbol-server with Apache License 2.0 5 votes vote down vote up
@Test
public void request_pdb_simple() throws Throwable {
  myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
  SUser user = myFixture.getUserModel().getGuestUser();
  user.addRole(RoleScope.projectScope(myProject.getProjectId()), getProjectDevRole());
  assertTrue(user.isPermissionGrantedForProject(myProject.getProjectId(), Permission.VIEW_BUILD_RUNTIME_DATA));

  myRequest.setRequestURI("mock", getRegisterPdbUrl("8EF4E863187C45E78F4632152CC82FEB", "secur32.pdb", "secur32.pdb"));

  doGet();

  assertEquals(HttpStatus.SC_NOT_FOUND, myResponse.getStatus());
  assertEquals("Symbol file not found", myResponse.getStatusText());
}
 
Example #10
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
@Override
public void notifyBuildSuccessful(SRunningBuild sRunningBuild, Set<SUser> set) {
    for (SUser sUser : set) {
        if (!userHasSlackIdConfigured(sUser)) {
            continue;
        }
        SlackNotification slackNotification = createNotification(sUser);
        slackNotification.setPayload(payloadManager.buildFinished(sRunningBuild, getPreviousNonPersonalBuild(sRunningBuild)));
        doNotification(slackNotification);
    }
}
 
Example #11
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * @param users telegram users
 * @return users ids without duplicates
 */
private List<Long> collectChatIds(@NotNull Set<SUser> users) {
  return users.stream()
      .map(user -> user.getPropertyValue(TELEGRAM_PROP_KEY))
      .filter(Objects::nonNull)
      // looks like new Teamcity don't validate input with validator in user properties
      // so we should check input before send (TW-47469). It's fixed at bugtrack but looks like
      // it's still reproducing...
      .filter(TelegramNotificator::isLong)
      .map(Long::parseLong)
      .distinct()
      .collect(Collectors.toList());
}
 
Example #12
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyBuildProblemsUnmuted(@NotNull Collection<BuildProblemInfo> buildProblems,
                                       @NotNull MuteInfo muteInfo,
                                       @Nullable SUser user,
                                       @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getBuildProblemsMutedMap(buildProblems, muteInfo, users);
  this.sendNotification(root, users, "build_problems_unmuted");
}
 
Example #13
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyBuildProblemsMuted(@NotNull Collection<BuildProblemInfo> buildProblems,
                                     @NotNull MuteInfo muteInfo,
                                     @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getBuildProblemsMutedMap(buildProblems, muteInfo, users);
  this.sendNotification(root, users, "build_problems_muted");
}
 
Example #14
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyTestsUnmuted(@NotNull Collection<STest> tests,
                               @NotNull MuteInfo muteInfo,
                               @Nullable SUser user,
                               @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getTestsUnmutedMap(tests, muteInfo, user, users);
  this.sendNotification(root, users, "tests_unmuted");
}
 
Example #15
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyTestsMuted(@NotNull Collection<STest> tests,
                             @NotNull MuteInfo muteInfo,
                             @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getTestsMutedMap(tests, muteInfo, users);
  this.sendNotification(root, users, "tests_muted");
}
 
Example #16
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyBuildProblemResponsibleChanged(@NotNull Collection<BuildProblemInfo> buildProblems,
                                                 @NotNull ResponsibilityEntry entry,
                                                 @NotNull SProject project,
                                                 @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getBuildProblemsResponsibilityAssignedMap(buildProblems, entry, project, users);
  this.sendNotification(root, users, "build_problem_responsibility_changed");
}
 
Example #17
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyResponsibleAssigned(@NotNull Collection<TestName> testNames,
                                      @NotNull ResponsibilityEntry entry,
                                      @NotNull SProject project,
                                      @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getTestResponsibilityChangedMap(testNames, entry, project, users);
  this.sendNotification(root, users, "multiple_test_responsibility_assigned_to_me");
}
 
Example #18
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyResponsibleChanged(@NotNull Collection<TestName> testNames,
                                     @NotNull ResponsibilityEntry entry,
                                     @NotNull SProject project,
                                     @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getTestResponsibilityAssignedMap(testNames, entry, project, users);
  this.sendNotification(root, users, "multiple_test_responsibility_changed");
}
 
Example #19
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyResponsibleAssigned(@Nullable TestNameResponsibilityEntry oldValue,
                                      @NotNull TestNameResponsibilityEntry newValue,
                                      @NotNull SProject project,
                                      @NotNull Set<SUser> users) {
  Map<String, Object> root = messageBuilder.
      getTestResponsibilityAssignedMap(newValue, oldValue, project, users);
  this.sendNotification(root, users, "test_responsibility_assigned_to_me");
}
 
Example #20
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyResponsibleChanged(@Nullable TestNameResponsibilityEntry oldValue,
                                     @NotNull TestNameResponsibilityEntry newValue,
                                     @NotNull SProject project,
                                     @NotNull Set<SUser> users) {
  Map<String, Object> props = messageBuilder.
      getTestResponsibilityChangedMap(newValue, oldValue, project, users);
  sendNotification(props, users, "test_responsibility_changed");
}
 
Example #21
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
@Override
public void notifyBuildFailed(SRunningBuild sRunningBuild, Set<SUser> set) {
    for (SUser sUser : set) {
        if (!userHasSlackIdConfigured(sUser)) {
            continue;
        }
        SlackNotification slackNotification = createNotification(sUser);
        slackNotification.setPayload(payloadManager.buildFinished(sRunningBuild, getPreviousNonPersonalBuild(sRunningBuild)));
        doNotification(slackNotification);
    }
}
 
Example #22
Source File: SlackProjectTab.java    From TCSlackNotifierPlugin with MIT License 5 votes vote down vote up
@Override
protected void fillModel(Map<String, Object> model, HttpServletRequest httpServletRequest, SProject sProject, SUser sUser) {

    SlackProjectSettings slackProjectSettings = (SlackProjectSettings) projectSettingsManager.getSettings(sProject.getProjectId(), SlackProjectSettingsFactory.SETTINGS_KEY);

    String channel = slackConfigProcessor.getDefaultChannel() ;
    boolean enabled = true ;
    String logoUrl = "" ;

    if( slackProjectSettings != null && slackProjectSettings.getChannel() != null && slackProjectSettings.getChannel().length() > 0 )
    {
        channel = slackProjectSettings.getChannel() ;
    }
    if( slackProjectSettings != null && slackProjectSettings.getLogoUrl() != null && slackProjectSettings.getLogoUrl().length() > 0 )
    {
        logoUrl = slackProjectSettings.getLogoUrl();
    }
    if( slackProjectSettings != null )
    {
        enabled = slackProjectSettings.isEnabled();
    }

    model.put("configDir" , sProject.getConfigDirectory().toString());
    model.put("channel" , channel );
    model.put("enabled" , enabled );
    model.put("logoUrl" , logoUrl );

}
 
Example #23
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
@Override
public void notifyBuildStarted(SRunningBuild sRunningBuild, Set<SUser> set) {
    for (SUser sUser : set) {
        if (!userHasSlackIdConfigured(sUser)) {
            continue;
        }
        SlackNotification slackNotification = createNotification(sUser);
        slackNotification.setPayload(payloadManager.buildStarted(sRunningBuild, getPreviousNonPersonalBuild(sRunningBuild)));
        doNotification(slackNotification);
    }
}
 
Example #24
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
@Override
public void notifyBuildFailing(SRunningBuild sRunningBuild, Set<SUser> set) {
    for (SUser sUser : set) {
        if (!userHasSlackIdConfigured(sUser)) {
            continue;
        }
        SlackNotification slackNotification = createNotification(sUser);
        slackNotification.setPayload(payloadManager.beforeBuildFinish(sRunningBuild, getPreviousNonPersonalBuild(sRunningBuild)));
        doNotification(slackNotification);
    }
}
 
Example #25
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyLabelingFailed(@NotNull Build build, @NotNull VcsRoot root,
                                 @NotNull Throwable exception, @NotNull Set<SUser> users) {
  Map<String, Object> props = messageBuilder.
      getLabelingFailedMap((SBuild) build, root, exception, users);
  sendNotification(props, users, "labeling_failed");
}
 
Example #26
Source File: ReportsMain.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
@Override
public UserSet<SUser> getCommitters(SelectPrevBuildPolicy selectPrevBuildPolicy) {
    return null;
}
 
Example #27
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
private boolean userHasSlackIdConfigured(SUser sUser) {
    String userName = sUser.getPropertyValue(USERID_KEY);

    return StringUtil.isNotEmpty(userName);
}
 
Example #28
Source File: MockSBuildType.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
public Collection<SUser> getPendingChangesCommitters() {
	// TODO Auto-generated method stub
	return null;
}
 
Example #29
Source File: MockSBuildAgent.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
public void setAuthorized(boolean arg0, SUser arg1, String arg2)
		throws LicenseNotGrantedException {
	// TODO Auto-generated method stub

}
 
Example #30
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
@Override
public void notifyBuildFailedToStart(SRunningBuild sRunningBuild, Set<SUser> set) {
}