Package com.gitblit.models

Examples of com.gitblit.models.RegistrantAccessPermission


    // TODO reconsider ownership as a user property
    // manually specify personal repository ownerships
    for (RepositoryModel rm : allRepositories) {
      if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
        RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND,
            PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
        // user may be owner of a repository to which they've inherited
        // a team permission, replace any existing perm with owner perm
        set.remove(rp);
        set.add(rp);
View Full Code Here


      // no permissions needed, REWIND for authenticated!
      return list;
    }
    // NAMED users and teams
    for (UserModel user : allUsers) {
      RegistrantAccessPermission ap = user.getRepositoryPermission(repository);
      if (ap.permission.exceeds(AccessPermission.NONE)) {
        list.add(ap);
      }
    }
    return list;
View Full Code Here

  }

  public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
    List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
    for (TeamModel team : allTeams) {
      RegistrantAccessPermission ap = team.getRepositoryPermission(repository);
      if (ap.permission.exceeds(AccessPermission.NONE)) {
        list.add(ap);
      }
    }
    Collections.sort(list);
View Full Code Here

                return new OddEvenItem<RegistrantAccessPermission>(id, index, model);
            }

      @Override
      public void populateItem(final Item<RegistrantAccessPermission> item) {
        final RegistrantAccessPermission entry = item.getModelObject();
        if (RegistrantType.REPOSITORY.equals(entry.registrantType)) {
          String repoName = StringUtils.stripDotGit(entry.registrant);
          if (!entry.isMissing() && StringUtils.findInvalidCharacter(repoName) == null) {
            // repository, strip .git and show swatch
            Fragment repositoryFragment = new Fragment("registrant", "repositoryRegistrant", RegistrantPermissionsPanel.this);
            Component swatch = new Label("repositorySwatch", "&nbsp;").setEscapeModelStrings(false);
            WicketUtils.setCssBackground(swatch, entry.toString());
            repositoryFragment.add(swatch);
            Label registrant = new Label("repositoryName", repoName);
            repositoryFragment.add(registrant);
            item.add(repositoryFragment);
          } else {
            // regex or missing
            Label label = new Label("registrant", entry.registrant);
            WicketUtils.setCssStyle(label, "font-weight: bold;");
            item.add(label);
          }
        } else if (RegistrantType.USER.equals(entry.registrantType)) {
          // user
          PersonIdent ident = new PersonIdent(entry.registrant, "");
          UserModel user = app().users().getUserModel(entry.registrant);
          if (user != null) {
            ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);
          }

          Fragment userFragment = new Fragment("registrant", "userRegistrant", RegistrantPermissionsPanel.this);
          userFragment.add(new GravatarImage("userAvatar", ident, 20));
          userFragment.add(new Label("userName", entry.registrant));
          item.add(userFragment);
        } else {
          // team
          Fragment teamFragment = new Fragment("registrant", "teamRegistrant", RegistrantPermissionsPanel.this);
          teamFragment.add(new Label("teamName", entry.registrant));
          item.add(teamFragment);
        }
        switch (entry.permissionType) {
        case ADMINISTRATOR:
          Label administrator = new Label("pType", entry.source == null ? getString("gb.administrator") : entry.source);
          WicketUtils.setHtmlTooltip(administrator, getString("gb.administratorPermission"));
          WicketUtils.setCssClass(administrator, "label label-inverse");
          item.add(administrator);
          break;
        case OWNER:
          Label owner = new Label("pType", getString("gb.owner"));
          WicketUtils.setHtmlTooltip(owner, getString("gb.ownerPermission"));
          WicketUtils.setCssClass(owner, "label label-info");
          item.add(owner);
          break;
        case TEAM:
          Label team = new Label("pType", entry.source == null ? getString("gb.team") : entry.source);
          WicketUtils.setHtmlTooltip(team, MessageFormat.format(getString("gb.teamPermission"), entry.source));
          WicketUtils.setCssClass(team, "label label-success");
          item.add(team);
          break;
        case REGEX:
          Label regex = new Label("pType", "regex");
          if (!StringUtils.isEmpty(entry.source)) {
            WicketUtils.setHtmlTooltip(regex, MessageFormat.format(getString("gb.regexPermission"), entry.source));
          }
          WicketUtils.setCssClass(regex, "label");
          item.add(regex);
          break;
        default:
          if (entry.isMissing()) {
            // repository is missing, this permission will be removed on save
            Label missing = new Label("pType", getString("gb.missing"));
            WicketUtils.setCssClass(missing, "label label-important");
            WicketUtils.setHtmlTooltip(missing, getString("gb.missingPermission"));
            item.add(missing);
          } else {
            // standard permission
            item.add(new Label("pType", "").setVisible(false));
          }
          break;
        }

        item.setVisible(activeState.show(entry));

        // use ajax to get immediate update of permission level change
        // otherwise we can lose it if they change levels and then add
        // a new repository permission
        final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
            "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
        // only allow changing an explicitly defined permission
        // this is designed to prevent changing a regex permission in
        // a repository
        permissionChoice.setEnabled(entry.mutable);
        permissionChoice.setOutputMarkupId(true);
        if (entry.mutable) {
          permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
              target.addComponent(permissionChoice);
            }
          });
        }

        item.add(permissionChoice);
      }
    };
    add(dataView);
    setOutputMarkupId(true);

    // filter out registrants we already have permissions for
    final List<String> registrants = new ArrayList<String>(allRegistrants);
    for (RegistrantAccessPermission rp : permissions) {
      if (rp.mutable) {
        // remove editable duplicates
        // this allows for specifying an explicit permission
        registrants.remove(rp.registrant);
      } else if (rp.isAdmin()) {
        // administrators can not have their permission changed
        registrants.remove(rp.registrant);
      } else if (rp.isOwner()) {
        // owners can not have their permission changed
        registrants.remove(rp.registrant);
      }
    }

    /*
     * Add permission form
     */
    IModel<RegistrantAccessPermission> addPermissionModel = new CompoundPropertyModel<RegistrantAccessPermission>(new RegistrantAccessPermission(registrantType));
    Form<RegistrantAccessPermission> addPermissionForm = new Form<RegistrantAccessPermission>("addPermissionForm", addPermissionModel);
    addPermissionForm.add(new DropDownChoice<String>("registrant", registrants));
    addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
        .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
    AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {

      private static final long serialVersionUID = 1L;

      @Override
      protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        // add permission to our list
        RegistrantAccessPermission rp = (RegistrantAccessPermission) form.getModel().getObject();
        if (rp.permission == null) {
          return;
        }
        if (rp.registrant == null) {
          return;
        }
        RegistrantAccessPermission copy = DeepCopier.copy(rp);
        if (StringUtils.findInvalidCharacter(copy.registrant) != null) {
          copy.permissionType = PermissionType.REGEX;
          copy.source = copy.registrant;
        }
        permissions.add(copy);
View Full Code Here

    // TODO reconsider ownership as a user property
    // manually specify personal repository ownerships
    for (RepositoryModel rm : repositoryListCache.values()) {
      if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
        RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND,
            PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
        // user may be owner of a repository to which they've inherited
        // a team permission, replace any existing perm with owner perm
        set.remove(rp);
        set.add(rp);
View Full Code Here

      // no permissions needed, REWIND for authenticated!
      return list;
    }
    // NAMED users and teams
    for (UserModel user : userManager.getAllUsers()) {
      RegistrantAccessPermission ap = user.getRepositoryPermission(repository);
      if (ap.permission.exceeds(AccessPermission.NONE)) {
        list.add(ap);
      }
    }
    return list;
View Full Code Here

   */
  @Override
  public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
    List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
    for (TeamModel team : userManager.getAllTeams()) {
      RegistrantAccessPermission ap = team.getRepositoryPermission(repository);
      if (ap.permission.exceeds(AccessPermission.NONE)) {
        list.add(ap);
      }
    }
    Collections.sort(list);
View Full Code Here

        }
        if (permissionSelector.getSelectedIndex() < 0) {
          return;
        }

        RegistrantAccessPermission rp = new RegistrantAccessPermission(registrantType);
        rp.registrant = registrantSelector.getSelectedItem().toString();
        rp.permission = (AccessPermission) permissionSelector.getSelectedItem();
        if (StringUtils.findInvalidCharacter(rp.registrant) != null) {
          rp.permissionType = PermissionType.REGEX;
          rp.source = rp.registrant;
View Full Code Here

      setHorizontalAlignment(SwingConstants.CENTER);
    }

    @Override
    protected void setValue(Object value) {
      RegistrantAccessPermission ap = (RegistrantAccessPermission) value;
      switch (ap.permissionType) {
      case ADMINISTRATOR:
        setText(ap.source == null ? Translation.get("gb.administrator") : ap.source);
        setToolTipText(Translation.get("gb.administratorPermission"));
        break;
      case OWNER:
        setText(Translation.get("gb.owner"));
        setToolTipText(Translation.get("gb.ownerPermission"));
        break;
      case TEAM:
        setText(ap.source == null ? Translation.get("gb.team") : ap.source);
        setToolTipText(MessageFormat.format(Translation.get("gb.teamPermission"), ap.source));
        break;
      case REGEX:
        setText("regex");
        setToolTipText(MessageFormat.format(Translation.get("gb.regexPermission"), ap.source));
        break;
      default:
        if (ap.isMissing()) {
          setText(Translation.get("gb.missing"));
          setToolTipText(Translation.get("gb.missingPermission"));
        } else {
          setText("");
          setToolTipText(null);
View Full Code Here

    assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));

    List<RegistrantAccessPermission> permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,
        password.toCharArray());
    assertEquals("Unexpected permissions! " + permissions.toString(), 1, permissions.size());
    permissions.add(new RegistrantAccessPermission(testMember.username, AccessPermission.VIEW, PermissionType.EXPLICIT, RegistrantType.USER, null, true));
    assertTrue(
        "Failed to set member permissions!",
        RpcUtils.setRepositoryMemberPermissions(retrievedRepository, permissions, url, account,
            password.toCharArray()));
    permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,
View Full Code Here

TOP

Related Classes of com.gitblit.models.RegistrantAccessPermission

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.