From 2ea85bfe371215ef21fcd528bc40fa57c48ee698 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 31 Oct 2012 16:38:03 -0400
Subject: [PATCH] Personal repositories must always be owned by the account the repo is stored in
---
src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java | 88 +++++++++++++++++++++++++++++++++++--------
1 files changed, 71 insertions(+), 17 deletions(-)
diff --git a/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java b/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
index b6ed890..805db9d 100644
--- a/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
+++ b/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
@@ -28,16 +28,21 @@
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
+import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.OddEvenItem;
import org.apache.wicket.markup.repeater.RefreshingView;
import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
+import org.eclipse.jgit.lib.PersonIdent;
import com.gitblit.Constants.AccessPermission;
+import com.gitblit.Constants.PermissionType;
import com.gitblit.Constants.RegistrantType;
+import com.gitblit.GitBlit;
import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.models.UserModel;
import com.gitblit.utils.DeepCopier;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.WicketUtils;
@@ -52,8 +57,9 @@
private static final long serialVersionUID = 1L;
- public RegistrantPermissionsPanel(String wicketId, List<String> allRegistrants, final List<RegistrantAccessPermission> permissions, final Map<AccessPermission, String> translations) {
+ public RegistrantPermissionsPanel(String wicketId, RegistrantType registrantType, List<String> allRegistrants, final List<RegistrantAccessPermission> permissions, final Map<AccessPermission, String> translations) {
super(wicketId);
+ setOutputMarkupId(true);
// update existing permissions repeater
RefreshingView<RegistrantAccessPermission> dataView = new RefreshingView<RegistrantAccessPermission>("permissionRow") {
@@ -80,22 +86,52 @@
public void populateItem(final Item<RegistrantAccessPermission> item) {
final RegistrantAccessPermission entry = item.getModelObject();
- if (RegistrantType.REPOSITORY.equals(entry.type)) {
- // repository, strip .git and show swatch
+ if (RegistrantType.REPOSITORY.equals(entry.registrantType)) {
String repoName = StringUtils.stripDotGit(entry.registrant);
- Label registrant = new Label("registrant", repoName);
- WicketUtils.setCssClass(registrant, "repositorySwatch");
- WicketUtils.setCssBackground(registrant, repoName);
- item.add(registrant);
+ if (StringUtils.findInvalidCharacter(repoName) == null) {
+ // repository, strip .git and show swatch
+ Label registrant = new Label("registrant", repoName);
+ WicketUtils.setCssClass(registrant, "repositorySwatch");
+ WicketUtils.setCssBackground(registrant, repoName);
+ item.add(registrant);
+ } else {
+ // likely a regex
+ 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, null);
+ UserModel user = GitBlit.self().getUserModel(entry.registrant);
+ if (user != null) {
+ ident = new PersonIdent(user.getDisplayName(), user.emailAddress);
+ }
+
+ Fragment userFragment = new Fragment("registrant", "userRegistrant", RegistrantPermissionsPanel.this);
+ userFragment.add(new GravatarImage("userAvatar", ident, 16, false));
+ userFragment.add(new Label("userName", entry.registrant));
+ item.add(userFragment);
} else {
- item.add(new Label("registrant", entry.registrant));
+ // team
+ Fragment teamFragment = new Fragment("registrant", "teamRegistrant", RegistrantPermissionsPanel.this);
+ teamFragment.add(new Label("teamName", entry.registrant));
+ item.add(teamFragment);
}
- if (entry.isExplicit) {
- item.add(new Label("regex", "").setVisible(false));
- } else {
- Label regex = new Label("regex", "regex");
+ switch (entry.permissionType) {
+ case OWNER:
+ Label owner = new Label("pType", "owner");
+ WicketUtils.setHtmlTooltip(owner, getString("gb.ownerPermission"));
+ item.add(owner);
+ break;
+ case REGEX:
+ Label regex = new Label("pType", "regex");
WicketUtils.setHtmlTooltip(regex, getString("gb.regexPermission"));
item.add(regex);
+ break;
+ default:
+ item.add(new Label("pType", "").setVisible(false));
+ break;
}
// use ajax to get immediate update of permission level change
@@ -106,8 +142,9 @@
// only allow changing an explicitly defined permission
// this is designed to prevent changing a regex permission in
// a repository
- permissionChoice.setEnabled(entry.isExplicit);
- if (entry.isExplicit) {
+ permissionChoice.setEnabled(entry.isEditable);
+ permissionChoice.setOutputMarkupId(true);
+ if (entry.isEditable) {
permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@@ -127,11 +164,15 @@
// filter out registrants we already have permissions for
final List<String> registrants = new ArrayList<String>(allRegistrants);
for (RegistrantAccessPermission rp : permissions) {
- registrants.remove(rp.registrant);
+ if (rp.isEditable) {
+ // only remove editable duplicates
+ // this allows for specifying an explicit permission
+ registrants.remove(rp.registrant);
+ }
}
// add new permission form
- IModel<RegistrantAccessPermission> addPermissionModel = new CompoundPropertyModel<RegistrantAccessPermission>(new RegistrantAccessPermission());
+ 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
@@ -144,7 +185,14 @@
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
// add permission to our list
RegistrantAccessPermission rp = (RegistrantAccessPermission) form.getModel().getObject();
- permissions.add(DeepCopier.copy(rp));
+ if (rp.permission == null) {
+ return;
+ }
+ RegistrantAccessPermission copy = DeepCopier.copy(rp);
+ if (StringUtils.findInvalidCharacter(copy.registrant) != null) {
+ copy.permissionType = PermissionType.REGEX;
+ }
+ permissions.add(copy);
// remove registrant from available choices
registrants.remove(rp.registrant);
@@ -159,6 +207,12 @@
add(addPermissionForm.setVisible(registrants.size() > 0));
}
+ protected boolean getStatelessHint()
+ {
+ return false;
+ }
+
+
private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
private static final long serialVersionUID = 1L;
--
Gitblit v1.9.1