summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-05-29 21:47:56 -0400
committerJames Moger <james.moger@gitblit.com>2014-06-03 10:34:51 -0400
commit2c50880dbd5de292e37d2533fccfcb62f6be9f95 (patch)
tree6d927aee1ad47a1992d4b586743c6d8011f329ec /src
parent8845b9aff37ee1cdc538ed4247933f7e3c06a49e (diff)
downloadgitblit-2c50880dbd5de292e37d2533fccfcb62f6be9f95.tar.gz
gitblit-2c50880dbd5de292e37d2533fccfcb62f6be9f95.zip
Extract authorization/access selection panel to re-usable class
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html13
-rw-r--r--src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java101
-rw-r--r--src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.html25
-rw-r--r--src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.java171
4 files changed, 205 insertions, 105 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html
index e9f12027..c59f29c8 100644
--- a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html
+++ b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html
@@ -32,18 +32,7 @@
<hr/>
- <span wicket:id="permissionsGroup">
- <div wicket:id="permissions">
- <div style="display: inline-block;vertical-align: top;">
- <input type="radio" wicket:id="radio" />
- <img wicket:id="image"></img>
- </div>
- <div style="display: inline-block;vertical-align: top;">
- <b><span wicket:id="name"></span></b><br/>
- <span wicket:id="description"></span>
- </div>
- </div>
- </span>
+ <span wicket:id="permissionPanel"></span>
<hr/>
diff --git a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
index a423ae62..cd0cef61 100644
--- a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
@@ -17,7 +17,6 @@ package com.gitblit.wicket.pages;
import java.io.File;
import java.io.IOException;
-import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -27,16 +26,11 @@ import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.behavior.SimpleAttributeModifier;
-import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.Radio;
-import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
@@ -67,15 +61,16 @@ import com.gitblit.utils.FileUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.panels.RepositoryPermissionPanel;
public class NewRepositoryPage extends RootSubPage {
private final RepositoryModel repositoryModel;
- private RadioGroup<Permission> permissionGroup;
private IModel<Boolean> addReadmeModel;
private Model<String> gitignoreModel;
private IModel<Boolean> addGitflowModel;
private IModel<Boolean> addGitignoreModel;
+ private RepositoryPermissionPanel permissionPanel;
public NewRepositoryPage() {
// create constructor
@@ -148,9 +143,7 @@ public class NewRepositoryPage extends RootSubPage {
repositoryModel.name = fullName;
repositoryModel.projectPath = null;
- Permission permission = permissionGroup.getModelObject();
- repositoryModel.authorizationControl = permission.control;
- repositoryModel.accessRestriction = permission.type;
+ permissionPanel.setPermission(repositoryModel);
repositoryModel.owners = new ArrayList<String>();
repositoryModel.owners.add(GitBlitWebSession.get().getUsername());
@@ -229,46 +222,7 @@ public class NewRepositoryPage extends RootSubPage {
form.add(new TextField<String>("name"));
form.add(new TextField<String>("description"));
- Permission anonymousPermission = new Permission(getString("gb.anonymousPush"),
- getString("gb.anonymousPushDescription"),
- "blank.png",
- AuthorizationControl.AUTHENTICATED,
- AccessRestrictionType.NONE);
-
- Permission authenticatedPermission = new Permission(getString("gb.pushRestrictedAuthenticated"),
- getString("gb.pushRestrictedAuthenticatedDescription"),
- "lock_go_16x16.png",
- AuthorizationControl.AUTHENTICATED,
- AccessRestrictionType.PUSH);
-
- Permission publicPermission = new Permission(getString("gb.pushRestrictedNamed"),
- getString("gb.pushRestrictedNamedDescription"),
- "lock_go_16x16.png",
- AuthorizationControl.NAMED,
- AccessRestrictionType.PUSH);
-
- Permission protectedPermission = new Permission(getString("gb.cloneRestricted"),
- getString("gb.cloneRestrictedDescription"),
- "lock_pull_16x16.png",
- AuthorizationControl.NAMED,
- AccessRestrictionType.CLONE);
-
- Permission privatePermission = new Permission(getString("gb.private"),
- getString("gb.privateRepoDescription"),
- "shield_16x16.png",
- AuthorizationControl.NAMED,
- AccessRestrictionType.VIEW);
-
- List<Permission> permissions = new ArrayList<Permission>();
- if (app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)) {
- permissions.add(anonymousPermission);
- }
- permissions.add(authenticatedPermission);
- permissions.add(publicPermission);
- permissions.add(protectedPermission);
- permissions.add(privatePermission);
-
- // determine default permission selection
+ // prepare the default access controls
AccessRestrictionType defaultRestriction = AccessRestrictionType.fromName(
app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));
if (AccessRestrictionType.NONE == defaultRestriction) {
@@ -281,31 +235,11 @@ public class NewRepositoryPage extends RootSubPage {
defaultRestriction = AccessRestrictionType.PUSH;
}
- Permission defaultPermission = publicPermission;
- for (Permission permission : permissions) {
- if (permission.type == defaultRestriction
- && permission.control == defaultControl) {
- defaultPermission = permission;
- }
- }
-
- permissionGroup = new RadioGroup<>("permissionsGroup", new Model<Permission>(defaultPermission));
- form.add(permissionGroup);
+ repositoryModel.authorizationControl = defaultControl;
+ repositoryModel.accessRestriction = defaultRestriction;
- ListView<Permission> permissionsList = new ListView<Permission>("permissions", permissions) {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void populateItem(ListItem<Permission> item) {
- Permission p = item.getModelObject();
- item.add(new Radio<Permission>("radio", item.getModel()));
- item.add(WicketUtils.newImage("image", p.image));
- item.add(new Label("name", p.name));
- item.add(new Label("description", p.description));
- }
- };
- permissionGroup.add(permissionsList);
+ permissionPanel = new RepositoryPermissionPanel("permissionPanel", repositoryModel);
+ form.add(permissionPanel);
//
// initial commit options
@@ -506,23 +440,4 @@ public class NewRepositoryPage extends RootSubPage {
}
return success;
}
-
- private static class Permission implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- final String name;
- final String description;
- final String image;
- final AuthorizationControl control;
- final AccessRestrictionType type;
-
- Permission(String name, String description, String img, AuthorizationControl control, AccessRestrictionType type) {
- this.name = name;
- this.description = description;
- this.image = img;
- this.control = control;
- this.type = type;
- }
- }
}
diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.html b/src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.html
new file mode 100644
index 00000000..6a4d5cef
--- /dev/null
+++ b/src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
+ xml:lang="en"
+ lang="en">
+
+<body>
+<wicket:panel>
+
+ <span wicket:id="permissionsGroup">
+ <div wicket:id="permissions">
+ <div style="display: inline-block;vertical-align: top;">
+ <input type="radio" wicket:id="radio" />
+ <img wicket:id="image"></img>
+ </div>
+ <div style="display: inline-block;vertical-align: top;">
+ <b><span wicket:id="name"></span></b><br/>
+ <span wicket:id="description"></span>
+ </div>
+ </div>
+ </span>
+
+</wicket:panel>
+</body>
+</html> \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.java b/src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.java
new file mode 100644
index 00000000..7c416b1b
--- /dev/null
+++ b/src/main/java/com/gitblit/wicket/panels/RepositoryPermissionPanel.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Radio;
+import org.apache.wicket.markup.html.form.RadioGroup;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.model.Model;
+
+import com.gitblit.Constants.AccessRestrictionType;
+import com.gitblit.Constants.AuthorizationControl;
+import com.gitblit.Keys;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.wicket.WicketUtils;
+
+/**
+ * A radio group panel of the 5 available authorization/access restriction combinations.
+ *
+ * @author James Moger
+ *
+ */
+public class RepositoryPermissionPanel extends BasePanel {
+
+ private static final long serialVersionUID = 1L;
+
+ private final RepositoryModel repository;
+
+ private RadioGroup<Permission> permissionGroup;
+
+ public RepositoryPermissionPanel(String wicketId, RepositoryModel repository) {
+ super(wicketId);
+ this.repository = repository;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ Permission anonymousPermission = new Permission(getString("gb.anonymousPush"),
+ getString("gb.anonymousPushDescription"),
+ "blank.png",
+ AuthorizationControl.AUTHENTICATED,
+ AccessRestrictionType.NONE);
+
+ Permission authenticatedPermission = new Permission(getString("gb.pushRestrictedAuthenticated"),
+ getString("gb.pushRestrictedAuthenticatedDescription"),
+ "lock_go_16x16.png",
+ AuthorizationControl.AUTHENTICATED,
+ AccessRestrictionType.PUSH);
+
+ Permission publicPermission = new Permission(getString("gb.pushRestrictedNamed"),
+ getString("gb.pushRestrictedNamedDescription"),
+ "lock_go_16x16.png",
+ AuthorizationControl.NAMED,
+ AccessRestrictionType.PUSH);
+
+ Permission protectedPermission = new Permission(getString("gb.cloneRestricted"),
+ getString("gb.cloneRestrictedDescription"),
+ "lock_pull_16x16.png",
+ AuthorizationControl.NAMED,
+ AccessRestrictionType.CLONE);
+
+ Permission privatePermission = new Permission(getString("gb.private"),
+ getString("gb.privateRepoDescription"),
+ "shield_16x16.png",
+ AuthorizationControl.NAMED,
+ AccessRestrictionType.VIEW);
+
+ List<Permission> permissions = new ArrayList<Permission>();
+ if (app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)) {
+ permissions.add(anonymousPermission);
+ }
+ permissions.add(authenticatedPermission);
+ permissions.add(publicPermission);
+ permissions.add(protectedPermission);
+ permissions.add(privatePermission);
+
+ AccessRestrictionType defaultRestriction = repository.accessRestriction;
+ if (defaultRestriction == null) {
+ defaultRestriction = AccessRestrictionType.fromName(app().settings().getString(Keys.git.defaultAccessRestriction,
+ AccessRestrictionType.PUSH.name()));
+ }
+
+ AuthorizationControl defaultControl = repository.authorizationControl;
+ if (defaultControl == null) {
+ defaultControl = AuthorizationControl.fromName(app().settings().getString(Keys.git.defaultAuthorizationControl,
+ AuthorizationControl.NAMED.name()));
+ }
+
+ Permission defaultPermission = publicPermission;
+ for (Permission permission : permissions) {
+ if (permission.type == defaultRestriction && permission.control == defaultControl) {
+ defaultPermission = permission;
+ }
+ }
+
+ permissionGroup = new RadioGroup<>("permissionsGroup", new Model<Permission>(defaultPermission));
+ ListView<Permission> permissionsList = new ListView<Permission>("permissions", permissions) {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void populateItem(ListItem<Permission> item) {
+ Permission p = item.getModelObject();
+ item.add(new Radio<Permission>("radio", item.getModel()));
+ item.add(WicketUtils.newImage("image", p.image));
+ item.add(new Label("name", p.name));
+ item.add(new Label("description", p.description));
+ }
+ };
+ permissionGroup.add(permissionsList);
+
+ setOutputMarkupId(true);
+
+ add(permissionGroup);
+ }
+
+ public void setPermission(RepositoryModel repository) {
+ Permission permission = permissionGroup.getModelObject();
+ repository.authorizationControl = permission.control;
+ repository.accessRestriction = permission.type;
+ }
+
+ @Override
+ protected boolean getStatelessHint() {
+ return false;
+ }
+
+ private static class Permission implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ final String name;
+ final String description;
+ final String image;
+ final AuthorizationControl control;
+ final AccessRestrictionType type;
+
+ Permission(String name, String description, String img, AuthorizationControl control, AccessRestrictionType type) {
+ this.name = name;
+ this.description = description;
+ this.image = img;
+ this.control = control;
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+}