Beispiel #1
0
  @Override
  protected boolean hasIssuePermission(
      User user, boolean issueCreation, Issue issue, String parameter) {
    CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
    CustomField field = customFieldManager.getCustomFieldObject(parameter);

    if (field != null) {
      Set<User> values = convertToUserSet(getValuesFromIssue(field, issue));
      return values.contains(user);
    }
    return false;
  }
Beispiel #2
0
  /**
   * Defines whether the given user has permission to see the given issue using the issue's value of
   * the named custom field.
   *
   * @param user the user whose permission is being checked.
   * @param issueCreation unused.
   * @param issueGv a GenericValue representing the issue.
   * @param customFieldName user custom field to use to determine which users have permission to the
   *     issue.
   * @return true only if the user has permission to see the issue based on the custom field value.
   */
  @Override
  protected boolean hasIssuePermission(
      User user, boolean issueCreation, GenericValue issueGv, String customFieldName) {
    CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
    IssueFactory issueFactory = ComponentAccessor.getComponentOfType(IssueFactory.class);
    CustomField field = customFieldManager.getCustomFieldObject(customFieldName);

    if (field != null) {
      Set<User> values =
          convertToUserSet(getValuesFromIssue(field, issueFactory.getIssue(issueGv)));
      return values.contains(user);
    }
    return false;
  }
Beispiel #3
0
 public void doValidation(
     String key, Map<String, String> parameters, JiraServiceContext jiraServiceContext) {
   // JRA-13808: Need to check whether or not the user CF has a searcher set.
   String customFieldOption = parameters.get(getType());
   if (StringUtils.isEmpty(customFieldOption)) {
     String localisedMessage =
         jiraServiceContext
             .getI18nBean()
             .getText("admin.permissions.errors.please.select.user.customfield");
     jiraServiceContext.getErrorCollection().addErrorMessage(localisedMessage);
   } else {
     // passed in parameters names a Custom Field - lets investigate.
     CustomField customField = customFieldManager.getCustomFieldObject(customFieldOption);
     if (customField != null && customField.getCustomFieldSearcher() == null) {
       // In order to use a Custom Field it must be indexed in Lucene Index. Currently we only
       // index custom fields if they have a Searcher.
       // Message: "Custom field '{0}' is not indexed for searching - please add a searcher to this
       // Custom Field."
       String localisedMessage =
           jiraServiceContext
               .getI18nBean()
               .getText("admin.permissions.errors.customfieldnotindexed", customField.getName());
       jiraServiceContext.getErrorCollection().addErrorMessage(localisedMessage);
     }
   }
 }
  @Test
  public void shouldAddCustomFieldParamsOnDelete() throws Exception {
    final CustomField customField1 = createMock(CustomField.class);
    expect(customField1.getId()).andReturn("customfield_10000");
    expect(customField1.getValue(issue)).andReturn("Value1");
    final CustomField customField2 = createMock(CustomField.class);
    expect(customField2.getId()).andReturn("customfield_10001");
    expect(customField2.getValue(issue)).andReturn("Value2");
    replay(customField1, customField2);

    expect(customFieldManager.getCustomFieldObjects(issue))
        .andReturn(ImmutableList.of(customField1, customField2));
    IssueDeleteHelper tested = getIssueDeleteHelper();
    setUpEmptyWatchers();
    expect(mockSubTaskManager.isSubTask(issueGenericValue)).andReturn(false);
    replayMocks();

    tested.deleteIssue((User) null, issue, EventDispatchOption.ISSUE_DELETED, true);
    makeAssertions();
    verify(customField1, customField2);
    final Map<String, Object> expected =
        ImmutableMap.<String, Object>of(
            "customfield_10000", "Value1", "customfield_10001", "Value2");
    assertEquals(expected, capturedEventParams.get(IssueEvent.CUSTOM_FIELDS_PARAM_NAME));
    assertTrue(capturedSendMailFlag);
  }
  @Override
  protected void getVelocityParamsForView(
      Map<String, Object> velocityParams, AbstractDescriptor descriptor) {
    String lCf = getParam(descriptor, Consts.LATEST_START_FIELD);
    String cCf = getParam(descriptor, Consts.CALCULATED_FIELD);
    CustomFieldManager cfMgr = ComponentAccessor.getCustomFieldManager();

    if (lCf != null && lCf.length() > 0) {
      velocityParams.put("nolCf", Boolean.FALSE);

      CustomField lCfObj = cfMgr.getCustomFieldObject(lCf);
      if (lCfObj != null) {
        velocityParams.put("nolCfObj", Boolean.FALSE);
        velocityParams.put("lCfName", lCfObj.getName());
      } else {
        velocityParams.put("nolCfObj", Boolean.TRUE);
      }
    } else {
      velocityParams.put("nolCf", Boolean.TRUE);
    }

    if (cCf != null && cCf.length() > 0) {
      velocityParams.put("nocCf", Boolean.FALSE);

      CustomField cCfObj = cfMgr.getCustomFieldObject(cCf);
      if (cCfObj != null) {
        velocityParams.put("nocCfObj", Boolean.FALSE);
        velocityParams.put("cCfName", cCfObj.getName());
      } else {
        velocityParams.put("nocCfObj", Boolean.TRUE);
      }
    } else {
      velocityParams.put("nocCf", Boolean.TRUE);
    }

    velocityParams.put(Consts.LATEST_START_FIELD, getParam(descriptor, Consts.LATEST_START_FIELD));
    velocityParams.put(Consts.CALCULATED_FIELD, getParam(descriptor, Consts.CALCULATED_FIELD));
  }
  public void testHeadingMarkupForNoCustomFields() {

    expect(cfm.getCustomFieldObject("customfield_nick")).andReturn(null);
    replay(cfm);

    expect(i18n.getText("common.words.none")).andReturn("none");

    replay(i18n);

    final StatsMarkup statsMarkup =
        ObjectToFieldValueMapper.transform("customfield_nick", "nick", FULL_URL, transformer);

    assertEquals("<a href='" + FULL_URL + "'>none</a>", statsMarkup.getHtml());
  }
 public CopyCommentListener(
     EventPublisher eventPublisher,
     HistorySearchManager historySearchManager,
     CustomFieldManager customFieldManager,
     IssueManager issueManager,
     CommentManager commentManager) {
   this.eventPublisher = eventPublisher;
   this.customFieldManager = customFieldManager;
   this.issueManager = issueManager;
   this.commentManager = commentManager;
   findChangeLogFunction = historySearchManager.getFindInChangeLogFunction();
   fatherCf = customFieldManager.getCustomFieldObjectByName(fatherName);
   if (fatherCf == null) {
     log.error("can't find fatherCf custom field with name : " + fatherName);
   }
 }
  @RequiresXsrfCheck
  public String doRemove() throws Exception {
    if (isFieldLocked()) {
      return "locked";
    }

    final FieldConfigScheme configScheme = getConfig();

    if (customFieldContextConfigHelper.doesRemovingSchemeFromCustomFieldAffectIssues(
        getLoggedInUser(), getCustomField(), configScheme)) {
      reindexMessageManager.pushMessage(
          getLoggedInUser(), "admin.notifications.task.custom.fields");
    }

    fieldConfigSchemeManager.removeFieldConfigScheme(configScheme.getId());

    ComponentAccessor.getFieldManager().refresh();
    customFieldManager.refreshConfigurationSchemes(getCustomFieldId());
    return redirectToView();
  }
  public void testHeadingMarkupForCustomFields() {

    CustomField cf = createMock(CustomField.class);
    CustomFieldSearcher cfs = createMock(CustomFieldSearcher.class);
    CustomFieldSearcherModuleDescriptor cfmd =
        createMock(CustomFieldSearcherModuleDescriptor.class);

    expect(cfm.getCustomFieldObject("customfield_nick")).andReturn(cf);
    replay(cfm);

    expect(cf.getCustomFieldSearcher()).andReturn(cfs);
    replay(cf);

    expect(cfs.getDescriptor()).andReturn(cfmd);
    replay(cfs);

    expect(cfmd.getStatHtml(cf, "nick", FULL_URL)).andReturn("CustomField Markup");
    replay(cfmd);

    final StatsMarkup statsMarkup =
        ObjectToFieldValueMapper.transform("customfield_nick", "nick", FULL_URL, transformer);

    assertEquals("CustomField Markup", statsMarkup.getHtml());
  }
  private void baseMockSetup() throws GenericEntityException, RemoveException, IndexException {
    expect(mailThreadManager.removeAssociatedEntries(ISSUE_ID)).andReturn(1);
    expect(mockIssueLinkManager.removeIssueLinks(issueGenericValue, (User) null)).andReturn(1);
    expect(attachmentManager.getAttachments(issue)).andReturn(ImmutableList.of(attachment));

    expect(mockIssueManager.getIssueObject(ISSUE_ID)).andReturn(issue);
    associationManager.removeAssociationsFromSource(issueGenericValue);
    expectLastCall();
    associationManager.removeUserAssociationsFromSink(issueGenericValue);
    expectLastCall();
    customFieldManager.removeCustomFieldValues(issueGenericValue);
    expectLastCall();
    attachmentManager.deleteAttachment(attachment);
    expectLastCall();
    attachmentManager.deleteAttachmentDirectory(issue);
    expectLastCall();
    workflowManager.removeWorkflowEntries(issueGenericValue);
    expectLastCall();
    indexManager.deIndex(issueGenericValue);
    expectLastCall();
    changeHistoryManager.removeAllChangeItems(issue);
    expectLastCall();
    stubEventManager();
  }
 private CustomField getSortingCustomField() {
   return customFieldManager.getCustomFieldObjectByName(OppressionService.MEGAPRIORITYSORTINGNAME);
 }
 /* (non-Javadoc)
  * @see com.googlecode.jsu.workflow.AbstractWorkflowPluginFactory#getVelocityParamsForInput(java.util.Map)
  */
 protected void getVelocityParamsForInput(Map<String, Object> velocityParams) {
   velocityParams.put("val-fieldsList", customFieldManager.getCustomFieldObjects());
 }
Beispiel #13
0
 @Override
 public String getArgumentDisplay(String argument) {
   CustomFieldManager fieldManager = ComponentAccessor.getCustomFieldManager();
   CustomField field = fieldManager.getCustomFieldObject(argument);
   return (field != null) ? field.getName() : argument;
 }
 private void setUpEmptyCustomFields() {
   expect(customFieldManager.getCustomFieldObjects(issue))
       .andReturn(Collections.<CustomField>emptyList());
 }
 public CustomField getCustomField() {
   return customFieldManager.getCustomFieldObject(getCustomFieldId());
 }
  @Override
  @RequiresXsrfCheck
  protected String doExecute() throws Exception {
    if (isFieldLocked()) {
      return "locked";
    }

    FieldConfigScheme configScheme =
        new FieldConfigScheme.Builder(getConfig())
            .setName(getName())
            .setDescription(getDescription())
            .toFieldConfigScheme();

    if (isBasicMode()) {
      // Add the contexts
      final List<JiraContextNode> contexts =
          CustomFieldUtils.buildJiraIssueContexts(
              isGlobal(), getProjectCategories(), getProjects(), treeManager);

      // Add the issue types
      final List<GenericValue> issueTypes =
          CustomFieldUtils.buildIssueTypes(constantsManager, getIssuetypes());

      boolean messageRequired;
      if (configScheme.getId() == null) {
        messageRequired =
            customFieldContextConfigHelper.doesAddingContextToCustomFieldAffectIssues(
                getLoggedInUser(), getCustomField(), contexts, issueTypes, false);

        configScheme =
            fieldConfigSchemeManager.createFieldConfigScheme(
                configScheme, contexts, issueTypes, getCustomField());
      } else {
        // keep a handle on the old scheme (pre edit) projects and issue types
        messageRequired =
            customFieldContextConfigHelper.doesChangingContextAffectIssues(
                getLoggedInUser(),
                getCustomField(),
                configScheme,
                isGlobal(),
                contexts,
                issueTypes);

        // Update so keep the old config
        if (issueTypes != null) {
          // Since we know that there is only one config
          final Long configId = getFieldConfigIds()[0];
          final FieldConfig config = fieldConfigManager.getFieldConfig(configId);
          final Map<String, FieldConfig> configs =
              new HashMap<String, FieldConfig>(issueTypes.size());
          for (final GenericValue issueType : issueTypes) {
            final String issueTypeId =
                issueType == null
                    ? null
                    : issueType.getString(FieldConfigSchemePersisterImpl.ENTITY_ID);
            configs.put(issueTypeId, config);
          }
          configScheme =
              new FieldConfigScheme.Builder(configScheme).setConfigs(configs).toFieldConfigScheme();
        }
        configScheme =
            fieldConfigSchemeManager.updateFieldConfigScheme(
                configScheme, contexts, getCustomField());
      }

      if (messageRequired) {
        reindexMessageManager.pushMessage(
            getLoggedInUser(), "admin.notifications.task.custom.fields");
      }

      fieldConfigScheme = configScheme;
    } else {
      // @TODO advanced config
    }

    ComponentAccessor.getFieldManager().refresh();
    customFieldManager.refreshConfigurationSchemes(getCustomFieldId());

    return redirectToView();
  }