Search in sources :

Example 1 with ProjectAccess

use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.

the class ProjectAccessScreen method resetEditors.

private void resetEditors() {
    // Push an empty instance through the driver before pushing the real
    // data. This will force GWT to delete and recreate the editors, which
    // is required to build initialize them as editable vs. read-only.
    ProjectAccess mock = new ProjectAccess();
    mock.setProjectName(access.getProjectName());
    mock.setRevision(access.getRevision());
    mock.setLocal(Collections.<AccessSection>emptyList());
    mock.setOwnerOf(Collections.<String>emptySet());
    driver.edit(mock);
}
Also used : ProjectAccess(com.google.gerrit.common.data.ProjectAccess)

Example 2 with ProjectAccess

use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.

the class ProjectAccessScreen method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    CallbackGroup cbs = new CallbackGroup();
    ConfigServerApi.capabilities(cbs.add(new AsyncCallback<NativeMap<CapabilityInfo>>() {

        @Override
        public void onSuccess(NativeMap<CapabilityInfo> result) {
            capabilityMap = result;
        }

        @Override
        public void onFailure(Throwable caught) {
        // Handled by ScreenLoadCallback.onFailure().
        }
    }));
    Util.PROJECT_SVC.projectAccess(getProjectKey(), cbs.addFinal(new ScreenLoadCallback<ProjectAccess>(this) {

        @Override
        public void preDisplay(ProjectAccess access) {
            displayReadOnly(access);
        }
    }));
    savedPanel = ACCESS;
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) ScreenLoadCallback(com.google.gerrit.client.rpc.ScreenLoadCallback) NativeMap(com.google.gerrit.client.rpc.NativeMap) CapabilityInfo(com.google.gerrit.client.config.CapabilityInfo) ProjectAccess(com.google.gerrit.common.data.ProjectAccess)

Example 3 with ProjectAccess

use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.

the class ProjectAccessFactory method call.

@Override
public ProjectAccess call() throws NoSuchProjectException, IOException, ConfigInvalidException, PermissionBackendException {
    ProjectControl pc = checkProjectControl();
    // Load the current configuration from the repository, ensuring its the most
    // recent version available. If it differs from what was in the project
    // state, force a cache flush now.
    //
    ProjectConfig config;
    try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
        config = ProjectConfig.read(md);
        if (config.updateGroupNames(groupBackend)) {
            md.setMessage("Update group names\n");
            config.commit(md);
            projectCache.evict(config.getProject());
            pc = checkProjectControl();
        } else if (config.getRevision() != null && !config.getRevision().equals(pc.getProjectState().getConfig().getRevision())) {
            projectCache.evict(config.getProject());
            pc = checkProjectControl();
        }
    }
    final RefControl metaConfigControl = pc.controlForRef(RefNames.REFS_CONFIG);
    List<AccessSection> local = new ArrayList<>();
    Set<String> ownerOf = new HashSet<>();
    Map<AccountGroup.UUID, Boolean> visibleGroups = new HashMap<>();
    for (AccessSection section : config.getAccessSections()) {
        String name = section.getName();
        if (AccessSection.GLOBAL_CAPABILITIES.equals(name)) {
            if (pc.isOwner()) {
                local.add(section);
                ownerOf.add(name);
            } else if (metaConfigControl.isVisible()) {
                local.add(section);
            }
        } else if (RefConfigSection.isValid(name)) {
            RefControl rc = pc.controlForRef(name);
            if (rc.isOwner()) {
                local.add(section);
                ownerOf.add(name);
            } else if (metaConfigControl.isVisible()) {
                local.add(section);
            } else if (rc.isVisible()) {
                // Filter the section to only add rules describing groups that
                // are visible to the current-user. This includes any group the
                // user is a member of, as well as groups they own or that
                // are visible to all users.
                AccessSection dst = null;
                for (Permission srcPerm : section.getPermissions()) {
                    Permission dstPerm = null;
                    for (PermissionRule srcRule : srcPerm.getRules()) {
                        AccountGroup.UUID group = srcRule.getGroup().getUUID();
                        if (group == null) {
                            continue;
                        }
                        Boolean canSeeGroup = visibleGroups.get(group);
                        if (canSeeGroup == null) {
                            try {
                                canSeeGroup = groupControlFactory.controlFor(group).isVisible();
                            } catch (NoSuchGroupException e) {
                                canSeeGroup = Boolean.FALSE;
                            }
                            visibleGroups.put(group, canSeeGroup);
                        }
                        if (canSeeGroup) {
                            if (dstPerm == null) {
                                if (dst == null) {
                                    dst = new AccessSection(name);
                                    local.add(dst);
                                }
                                dstPerm = dst.getPermission(srcPerm.getName(), true);
                            }
                            dstPerm.add(srcRule);
                        }
                    }
                }
            }
        }
    }
    if (ownerOf.isEmpty() && pc.isOwnerAnyRef()) {
        // Special case: If the section list is empty, this project has no current
        // access control information. Rely on what ProjectControl determines
        // is ownership, which probably means falling back to site administrators.
        ownerOf.add(AccessSection.ALL);
    }
    final ProjectAccess detail = new ProjectAccess();
    detail.setProjectName(projectName);
    if (config.getRevision() != null) {
        detail.setRevision(config.getRevision().name());
    }
    detail.setInheritsFrom(config.getProject().getParent(allProjectsName));
    if (projectName.equals(allProjectsName)) {
        if (pc.isOwner()) {
            ownerOf.add(AccessSection.GLOBAL_CAPABILITIES);
        }
    }
    detail.setLocal(local);
    detail.setOwnerOf(ownerOf);
    detail.setCanUpload(metaConfigControl.isVisible() && (pc.isOwner() || metaConfigControl.canUpload()));
    detail.setConfigVisible(pc.isOwner() || metaConfigControl.isVisible());
    detail.setGroupInfo(buildGroupInfo(local));
    detail.setLabelTypes(pc.getLabelTypes());
    detail.setFileHistoryLinks(getConfigFileLogLinks(projectName.get()));
    return detail;
}
Also used : HashMap(java.util.HashMap) PermissionRule(com.google.gerrit.common.data.PermissionRule) RefControl(com.google.gerrit.server.project.RefControl) ArrayList(java.util.ArrayList) ProjectControl(com.google.gerrit.server.project.ProjectControl) AccessSection(com.google.gerrit.common.data.AccessSection) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException) ProjectAccess(com.google.gerrit.common.data.ProjectAccess) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Permission(com.google.gerrit.common.data.Permission) ProjectPermission(com.google.gerrit.server.permissions.ProjectPermission) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) HashSet(java.util.HashSet)

Example 4 with ProjectAccess

use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.

the class ProjectAccessScreen method onReview.

@UiHandler("review")
void onReview(@SuppressWarnings("unused") ClickEvent event) {
    final ProjectAccess access = driver.flush();
    if (driver.hasErrors()) {
        Window.alert(AdminConstants.I.errorsMustBeFixed());
        return;
    }
    String message = commitMessage.getText().trim();
    if ("".equals(message)) {
        message = null;
    }
    enable(false);
    //
    Util.PROJECT_SVC.reviewProjectAccess(//
    getProjectKey(), //
    access.getRevision(), //
    message, //
    access.getLocal(), //
    access.getInheritsFrom(), new GerritCallback<Change.Id>() {

        @Override
        public void onSuccess(Change.Id changeId) {
            enable(true);
            commitMessage.setText("");
            error.clear();
            if (changeId != null) {
                Gerrit.display(PageLinks.toChange(changeId));
            } else {
                displayReadOnly(access);
            }
        }

        @Override
        public void onFailure(Throwable caught) {
            error.clear();
            enable(true);
            super.onFailure(caught);
        }
    });
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) ProjectAccess(com.google.gerrit.common.data.ProjectAccess) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 5 with ProjectAccess

use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.

the class ProjectAccessScreen method onCommit.

@UiHandler("commit")
void onCommit(@SuppressWarnings("unused") ClickEvent event) {
    final ProjectAccess access = driver.flush();
    if (driver.hasErrors()) {
        Window.alert(AdminConstants.I.errorsMustBeFixed());
        return;
    }
    String message = commitMessage.getText().trim();
    if ("".equals(message)) {
        message = null;
    }
    enable(false);
    //
    Util.PROJECT_SVC.changeProjectAccess(//
    getProjectKey(), //
    access.getRevision(), //
    message, //
    access.getLocal(), //
    access.getInheritsFrom(), new GerritCallback<ProjectAccess>() {

        @Override
        public void onSuccess(ProjectAccess newAccess) {
            enable(true);
            commitMessage.setText("");
            error.clear();
            final Set<String> diffs = getDiffs(access, newAccess);
            if (diffs.isEmpty()) {
                displayReadOnly(newAccess);
            } else {
                error.add(new Label(Gerrit.C.projectAccessError()));
                for (final String diff : diffs) {
                    error.add(new Label(diff));
                }
                if (access.canUpload()) {
                    error.add(new Label(Gerrit.C.projectAccessProposeForReviewHint()));
                }
            }
        }

        private Set<String> getDiffs(ProjectAccess wantedAccess, ProjectAccess newAccess) {
            List<AccessSection> wantedSections = mergeSections(removeEmptyPermissionsAndSections(wantedAccess.getLocal()));
            List<AccessSection> newSections = removeEmptyPermissionsAndSections(newAccess.getLocal());
            HashSet<AccessSection> same = new HashSet<>(wantedSections);
            HashSet<AccessSection> different = new HashSet<>(wantedSections.size() + newSections.size());
            different.addAll(wantedSections);
            different.addAll(newSections);
            same.retainAll(newSections);
            different.removeAll(same);
            Set<String> differentNames = new HashSet<>();
            for (AccessSection s : different) {
                differentNames.add(s.getName());
            }
            return differentNames;
        }

        @Override
        public void onFailure(Throwable caught) {
            error.clear();
            enable(true);
            if (caught instanceof RemoteJsonException && caught.getMessage().startsWith(UpdateParentFailedException.MESSAGE)) {
                new ErrorDialog(Gerrit.M.parentUpdateFailed(caught.getMessage().substring(UpdateParentFailedException.MESSAGE.length() + 1))).center();
            } else {
                super.onFailure(caught);
            }
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Label(com.google.gwt.user.client.ui.Label) RemoteJsonException(com.google.gwtjsonrpc.client.RemoteJsonException) ErrorDialog(com.google.gerrit.client.ErrorDialog) ProjectAccess(com.google.gerrit.common.data.ProjectAccess) AccessSection(com.google.gerrit.common.data.AccessSection) List(java.util.List) HashSet(java.util.HashSet) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Aggregations

ProjectAccess (com.google.gerrit.common.data.ProjectAccess)5 AccessSection (com.google.gerrit.common.data.AccessSection)2 UiHandler (com.google.gwt.uibinder.client.UiHandler)2 HashSet (java.util.HashSet)2 ErrorDialog (com.google.gerrit.client.ErrorDialog)1 CapabilityInfo (com.google.gerrit.client.config.CapabilityInfo)1 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)1 NativeMap (com.google.gerrit.client.rpc.NativeMap)1 ScreenLoadCallback (com.google.gerrit.client.rpc.ScreenLoadCallback)1 Permission (com.google.gerrit.common.data.Permission)1 PermissionRule (com.google.gerrit.common.data.PermissionRule)1 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)1 Change (com.google.gerrit.reviewdb.client.Change)1 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)1 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)1 ProjectPermission (com.google.gerrit.server.permissions.ProjectPermission)1 ProjectControl (com.google.gerrit.server.project.ProjectControl)1 RefControl (com.google.gerrit.server.project.RefControl)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Label (com.google.gwt.user.client.ui.Label)1