Ejemplo n.º 1
0
 private void checkTransitionPermission(
     String transitionKey, UserSession userSession, DefaultIssue defaultIssue) {
   List<Transition> outTransitions = workflow.outTransitions(defaultIssue);
   for (Transition transition : outTransitions) {
     String projectKey = defaultIssue.projectKey();
     if (transition.key().equals(transitionKey)
         && StringUtils.isNotBlank(transition.requiredProjectPermission())
         && projectKey != null) {
       userSession.checkComponentPermission(transition.requiredProjectPermission(), projectKey);
     }
   }
 }
Ejemplo n.º 2
0
  public DefaultIssue createManualIssue(
      String componentKey,
      RuleKey ruleKey,
      @Nullable Integer line,
      @Nullable String message,
      @Nullable String severity) {
    verifyLoggedIn();

    DbSession dbSession = dbClient.openSession(false);
    try {
      Optional<ComponentDto> componentOptional =
          dbClient.componentDao().selectByKey(dbSession, componentKey);
      if (!componentOptional.isPresent()) {
        throw new BadRequestException(
            String.format("Component with key '%s' not found", componentKey));
      }
      ComponentDto component = componentOptional.get();
      ComponentDto project =
          dbClient.componentDao().selectOrFailByUuid(dbSession, component.projectUuid());

      userSession.checkComponentPermission(UserRole.USER, project.getKey());
      if (!ruleKey.isManual()) {
        throw new IllegalArgumentException(
            "Issues can be created only on rules marked as 'manual': " + ruleKey);
      }
      Rule rule = getNullableRuleByKey(ruleKey);
      if (rule == null) {
        throw new IllegalArgumentException("Unknown rule: " + ruleKey);
      }

      DefaultIssue issue =
          new DefaultIssueBuilder()
              .componentKey(component.getKey())
              .projectKey(project.getKey())
              .line(line)
              .message(!Strings.isNullOrEmpty(message) ? message : rule.getName())
              .severity(Objects.firstNonNull(severity, Severity.MAJOR))
              .ruleKey(ruleKey)
              .reporter(userSession.getLogin())
              .assignee(findSourceLineUser(dbSession, component.uuid(), line))
              .build();

      Date now = new Date();
      issue.setCreationDate(now);
      issue.setUpdateDate(now);
      issueStorage.save(issue);
      return issue;
    } finally {
      dbSession.close();
    }
  }
Ejemplo n.º 3
0
  public Issue setSeverity(String issueKey, String severity) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      userSession.checkComponentPermission(UserRole.ISSUE_ADMIN, issue.projectKey());

      IssueChangeContext context =
          IssueChangeContext.createUser(new Date(), userSession.getLogin());
      if (issueUpdater.setManualSeverity(issue, severity, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue;
    } finally {
      session.close();
    }
  }
Ejemplo n.º 4
0
  @Override
  public void handle(Request request, Response response) {
    String componentUuid = request.mandatoryParam(PARAM_UUID);

    JsonWriter json = response.newJsonWriter();
    json.beginObject();

    DbSession session = dbClient.openSession(false);
    try {
      ComponentDto component = componentFinder.getByUuid(session, componentUuid);
      userSession.checkComponentPermission(UserRole.USER, component.getKey());

      Map<String, MeasureDto> measuresByMetricKey = measuresByMetricKey(component, session);
      appendComponent(json, component, userSession, session);
      appendPermissions(json, component, userSession);
      appendMeasures(json, measuresByMetricKey);

    } finally {
      MyBatis.closeQuietly(session);
    }

    json.endObject();
    json.close();
  }