Package com.google.gerrit.server.project

Examples of com.google.gerrit.server.project.ChangeControl


        int psVal = p.getValue();
        if (test.match(psVal, expVal)) {
          // Double check the value is still permitted for the user.
          //
          try {
            ChangeControl cc = ccFactory.controlFor(object.change(dbProvider), //
                userFactory.create(dbProvider, p.getAccountId()));
            if (!cc.isVisible(dbProvider.get())) {
              // The user can't see the change anymore.
              //
              continue;
            }
            psVal = cc.getRange(permissionName).squash(psVal);
          } catch (NoSuchChangeException e) {
            // The project has disappeared.
            //
            continue;
          }
View Full Code Here


  @Override
  public VoidResult call() throws NoSuchChangeException, OrmException, IOException {

    final Change.Id changeId = patchSetId.getParentKey();
    final ChangeControl control = changeControlFactory.validateFor(changeId);
    if (!control.canDeleteDraft(db)) {
      throw new NoSuchChangeException(changeId);
    }

    ChangeUtil.deleteDraftChange(patchSetId, gitManager, replication, db);
    return VoidResult.INSTANCE;
View Full Code Here

      Change c = cd.change(db);
      if (c == null) {
        return false;
      }

      ChangeControl cc = changeControl.controlFor(c, user);
      if (cc.isVisible(db.get())) {
        cd.cacheVisibleTo(cc);
        return true;
      }
    } catch (NoSuchChangeException e) {
    }
View Full Code Here

    return a;
  }

  private Map<String, LabelInfo> labelsFor(ChangeData cd) throws OrmException {
    Change in = cd.change(db);
    ChangeControl ctl = cd.changeControl();
    if (ctl == null || ctl.getCurrentUser() != user) {
      try {
        ctl = changeControlFactory.controlFor(in);
      } catch (NoSuchChangeException e) {
        return null;
      }
    }

    PatchSet ps = cd.currentPatchSet(db);
    Map<String, LabelInfo> labels = Maps.newLinkedHashMap();
    for (SubmitRecord rec : ctl.canSubmit(db.get(), ps, cd, true, false)) {
      if (rec.labels == null) {
        continue;
      }
      for (SubmitRecord.Label r : rec.labels) {
        LabelInfo p = labels.get(r.label);
View Full Code Here

    if (change.getStatus().isClosed()) {
      reject(request.cmd, "change " + request.ontoChange + " closed");
      return null;
    }

    final ChangeControl changeCtl = projectControl.controlFor(change);
    if (!changeCtl.canAddPatchSet()) {
      reject(request.cmd, "cannot replace " + request.ontoChange);
      return null;
    }
    if (!validCommit(changeCtl.getRefControl(), request.cmd, c)) {
      return null;
    }

    final PatchSet.Id priorPatchSet = change.currentPatchSetId();
    for (final PatchSet ps : db.patchSets().byChange(request.ontoChange)) {
View Full Code Here

  @Override
  public VoidResult call() throws NoSuchChangeException,
      InvalidChangeOperationException, OrmException {
    final Change.Id changeId = patchSetId.getParentKey();
    final ChangeControl ctl = changeControlFactory.validateFor(changeId);
    change = ctl.getChange();
    patchSet = db.patchSets().get(patchSetId);
    if (patchSet == null) {
      throw new NoSuchChangeException(changeId);
    }
    drafts = drafts();
View Full Code Here

  @Override
  public PatchSetPublishDetail call() throws OrmException,
      PatchSetInfoNotAvailableException, NoSuchChangeException {
    final Change.Id changeId = patchSetId.getParentKey();
    final ChangeControl control = changeControlFactory.validateFor(changeId);
    change = control.getChange();
    PatchSet patchSet = db.patchSets().get(patchSetId);
    patchSetInfo = infoFactory.get(change, patchSet);
    drafts = db.patchComments().draftByPatchSetAuthor(patchSetId, user.getAccountId()).toList();

    aic.want(change.getOwner());

    PatchSetPublishDetail detail = new PatchSetPublishDetail();
    detail.setPatchSetInfo(patchSetInfo);
    detail.setChange(change);
    detail.setDrafts(drafts);

    List<PermissionRange> allowed = Collections.emptyList();
    List<PatchSetApproval> given = Collections.emptyList();

    if (change.getStatus().isOpen()
        && patchSetId.equals(change.currentPatchSetId())) {
      // TODO Push this selection of labels down into the Prolog interpreter.
      // Ideally we discover the labels the user can apply here based on doing
      // a findall() over the space of labels they can apply combined against
      // the submit rule, thereby skipping any mutually exclusive cases. However
      // those are not common, so it might just be reasonable to take this
      // simple approach.

      Map<String, PermissionRange> rangeByName =
          new HashMap<String, PermissionRange>();
      for (PermissionRange r : control.getLabelRanges()) {
        if (r.isLabel()) {
          rangeByName.put(r.getLabel(), r);
        }
      }
      allowed = new ArrayList<PermissionRange>();

      given = db.patchSetApprovals() //
          .byPatchSetUser(patchSetId, user.getAccountId()) //
          .toList();

      boolean couldSubmit = false;
      List<SubmitRecord> submitRecords = control.canSubmit(db, patchSet);
      for (SubmitRecord rec : submitRecords) {
        if (rec.status == SubmitRecord.Status.OK) {
          couldSubmit = true;
        }

        if (rec.labels != null) {
          int ok = 0;

          for (SubmitRecord.Label lbl : rec.labels) {
            aic.want(lbl.appliedBy);

            boolean canMakeOk = false;
            PermissionRange range = rangeByName.get(lbl.label);
            if (range != null) {
              if (!allowed.contains(range)) {
                allowed.add(range);
              }

              ApprovalType at = approvalTypes.byLabel(lbl.label);
              if (at == null || at.getMax().getValue() == range.getMax()) {
                canMakeOk = true;
              }
            }

            switch (lbl.status) {
              case OK:
              case MAY:
                ok++;
                break;

              case NEED:
                if (canMakeOk) {
                  ok++;
                }
                break;
            }
          }

          if (rec.status == SubmitRecord.Status.NOT_READY
              && ok == rec.labels.size()) {
            couldSubmit = true;
          }
        }
      }

      if (couldSubmit && control.getRefControl().canSubmit()) {
        detail.setCanSubmit(true);
      }

      detail.setSubmitRecords(submitRecords);
    }
View Full Code Here

  public ChangeDetail call() throws NoSuchChangeException, OrmException,
      EmailException, NoSuchEntityException, PatchSetInfoNotAvailableException,
      MissingObjectException, IncorrectObjectTypeException, IOException {

    final Change.Id changeId = patchSetId.getParentKey();
    final ChangeControl control = changeControlFactory.validateFor(changeId);
    if (!control.canAddPatchSet()) {
      throw new NoSuchChangeException(changeId);
    }

    Change.Id revertedChangeId = ChangeUtil.revert(patchSetId, currentUser, message, db,
        revertedSenderFactory, hooks, gitManager, patchSetInfoFactory,
View Full Code Here

  }

  @Override
  public ReviewerResult call() throws Exception {
    ReviewerResult result = new ReviewerResult();
    ChangeControl ctl = changeControlFactory.validateFor(changeId);
    Set<Account.Id> rejected = new HashSet<Account.Id>();

    List<PatchSetApproval> current = db.patchSetApprovals().byChange(changeId).toList();
    for (PatchSetApproval psa : current) {
      Account.Id who = psa.getAccountId();
      if (ids.contains(who) && !ctl.canRemoveReviewer(psa) && rejected.add(who)) {
        result.addError(new ReviewerResult.Error(
            ReviewerResult.Error.Type.REMOVE_NOT_PERMITTED,
            formatUser(who)));
      }
    }
View Full Code Here

            accountInfoCacheFactory.create();

        aicFactory.want(aid);
        for (final Change.Id id : cids) {
          try {
            final ChangeControl cc = changeControlFactory.validateFor(id);
            final Change change = cc.getChange();
            final PatchSet.Id ps_id = change.currentPatchSetId();
            final Map<ApprovalCategory.Id, PatchSetApproval> psas =
                new HashMap<ApprovalCategory.Id, PatchSetApproval>();
            final FunctionState fs =
                functionStateFactory.create(cc, ps_id, psas.values());
View Full Code Here

TOP

Related Classes of com.google.gerrit.server.project.ChangeControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.