\r
<hr/>\r
\r
- <span wicket:id="permissionsGroup">\r
- <div wicket:id="permissions">\r
- <div style="display: inline-block;vertical-align: top;">\r
- <input type="radio" wicket:id="radio" />\r
- <img wicket:id="image"></img> \r
- </div>\r
- <div style="display: inline-block;vertical-align: top;">\r
- <b><span wicket:id="name"></span></b><br/>\r
- <span wicket:id="description"></span>\r
- </div>\r
- </div>\r
- </span>\r
+ <span wicket:id="permissionPanel"></span>\r
\r
<hr/>\r
\r
\r
import java.io.File;\r
import java.io.IOException;\r
-import java.io.Serializable;\r
import java.io.UnsupportedEncodingException;\r
import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import org.apache.wicket.ajax.AjaxRequestTarget;\r
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;\r
import org.apache.wicket.behavior.SimpleAttributeModifier;\r
-import org.apache.wicket.markup.html.basic.Label;\r
import org.apache.wicket.markup.html.form.Button;\r
import org.apache.wicket.markup.html.form.CheckBox;\r
import org.apache.wicket.markup.html.form.DropDownChoice;\r
import org.apache.wicket.markup.html.form.Form;\r
-import org.apache.wicket.markup.html.form.Radio;\r
-import org.apache.wicket.markup.html.form.RadioGroup;\r
import org.apache.wicket.markup.html.form.TextField;\r
-import org.apache.wicket.markup.html.list.ListItem;\r
-import org.apache.wicket.markup.html.list.ListView;\r
import org.apache.wicket.model.CompoundPropertyModel;\r
import org.apache.wicket.model.IModel;\r
import org.apache.wicket.model.Model;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.panels.RepositoryPermissionPanel;\r
\r
public class NewRepositoryPage extends RootSubPage {\r
\r
private final RepositoryModel repositoryModel;\r
- private RadioGroup<Permission> permissionGroup;\r
private IModel<Boolean> addReadmeModel;\r
private Model<String> gitignoreModel;\r
private IModel<Boolean> addGitflowModel;\r
private IModel<Boolean> addGitignoreModel;\r
+ private RepositoryPermissionPanel permissionPanel;\r
\r
public NewRepositoryPage() {\r
// create constructor\r
repositoryModel.name = fullName;\r
repositoryModel.projectPath = null;\r
\r
- Permission permission = permissionGroup.getModelObject();\r
- repositoryModel.authorizationControl = permission.control;\r
- repositoryModel.accessRestriction = permission.type;\r
+ permissionPanel.setPermission(repositoryModel);\r
\r
repositoryModel.owners = new ArrayList<String>();\r
repositoryModel.owners.add(GitBlitWebSession.get().getUsername());\r
form.add(new TextField<String>("name"));\r
form.add(new TextField<String>("description"));\r
\r
- Permission anonymousPermission = new Permission(getString("gb.anonymousPush"),\r
- getString("gb.anonymousPushDescription"),\r
- "blank.png",\r
- AuthorizationControl.AUTHENTICATED,\r
- AccessRestrictionType.NONE);\r
-\r
- Permission authenticatedPermission = new Permission(getString("gb.pushRestrictedAuthenticated"),\r
- getString("gb.pushRestrictedAuthenticatedDescription"),\r
- "lock_go_16x16.png",\r
- AuthorizationControl.AUTHENTICATED,\r
- AccessRestrictionType.PUSH);\r
-\r
- Permission publicPermission = new Permission(getString("gb.pushRestrictedNamed"),\r
- getString("gb.pushRestrictedNamedDescription"),\r
- "lock_go_16x16.png",\r
- AuthorizationControl.NAMED,\r
- AccessRestrictionType.PUSH);\r
-\r
- Permission protectedPermission = new Permission(getString("gb.cloneRestricted"),\r
- getString("gb.cloneRestrictedDescription"),\r
- "lock_pull_16x16.png",\r
- AuthorizationControl.NAMED,\r
- AccessRestrictionType.CLONE);\r
-\r
- Permission privatePermission = new Permission(getString("gb.private"),\r
- getString("gb.privateRepoDescription"),\r
- "shield_16x16.png",\r
- AuthorizationControl.NAMED,\r
- AccessRestrictionType.VIEW);\r
-\r
- List<Permission> permissions = new ArrayList<Permission>();\r
- if (app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)) {\r
- permissions.add(anonymousPermission);\r
- }\r
- permissions.add(authenticatedPermission);\r
- permissions.add(publicPermission);\r
- permissions.add(protectedPermission);\r
- permissions.add(privatePermission);\r
-\r
- // determine default permission selection\r
+ // prepare the default access controls\r
AccessRestrictionType defaultRestriction = AccessRestrictionType.fromName(\r
app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));\r
if (AccessRestrictionType.NONE == defaultRestriction) {\r
defaultRestriction = AccessRestrictionType.PUSH;\r
}\r
\r
- Permission defaultPermission = publicPermission;\r
- for (Permission permission : permissions) {\r
- if (permission.type == defaultRestriction\r
- && permission.control == defaultControl) {\r
- defaultPermission = permission;\r
- }\r
- }\r
-\r
- permissionGroup = new RadioGroup<>("permissionsGroup", new Model<Permission>(defaultPermission));\r
- form.add(permissionGroup);\r
+ repositoryModel.authorizationControl = defaultControl;\r
+ repositoryModel.accessRestriction = defaultRestriction;\r
\r
- ListView<Permission> permissionsList = new ListView<Permission>("permissions", permissions) {\r
-\r
- private static final long serialVersionUID = 1L;\r
-\r
- @Override\r
- protected void populateItem(ListItem<Permission> item) {\r
- Permission p = item.getModelObject();\r
- item.add(new Radio<Permission>("radio", item.getModel()));\r
- item.add(WicketUtils.newImage("image", p.image));\r
- item.add(new Label("name", p.name));\r
- item.add(new Label("description", p.description));\r
- }\r
- };\r
- permissionGroup.add(permissionsList);\r
+ permissionPanel = new RepositoryPermissionPanel("permissionPanel", repositoryModel);\r
+ form.add(permissionPanel);\r
\r
//\r
// initial commit options\r
}\r
return success;\r
}\r
-\r
- private static class Permission implements Serializable {\r
-\r
- private static final long serialVersionUID = 1L;\r
-\r
- final String name;\r
- final String description;\r
- final String image;\r
- final AuthorizationControl control;\r
- final AccessRestrictionType type;\r
-\r
- Permission(String name, String description, String img, AuthorizationControl control, AccessRestrictionType type) {\r
- this.name = name;\r
- this.description = description;\r
- this.image = img;\r
- this.control = control;\r
- this.type = type;\r
- }\r
- }\r
}\r
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml" \r
+ xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" \r
+ xml:lang="en" \r
+ lang="en"> \r
+\r
+<body>\r
+<wicket:panel>\r
+\r
+ <span wicket:id="permissionsGroup">\r
+ <div wicket:id="permissions">\r
+ <div style="display: inline-block;vertical-align: top;">\r
+ <input type="radio" wicket:id="radio" />\r
+ <img wicket:id="image"></img> \r
+ </div>\r
+ <div style="display: inline-block;vertical-align: top;">\r
+ <b><span wicket:id="name"></span></b><br/>\r
+ <span wicket:id="description"></span>\r
+ </div>\r
+ </div>\r
+ </span>\r
+ \r
+</wicket:panel>\r
+</body>\r
+</html>
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright 2014 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.wicket.panels;\r
+\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.apache.wicket.markup.html.form.Radio;\r
+import org.apache.wicket.markup.html.form.RadioGroup;\r
+import org.apache.wicket.markup.html.list.ListItem;\r
+import org.apache.wicket.markup.html.list.ListView;\r
+import org.apache.wicket.model.Model;\r
+\r
+import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.Constants.AuthorizationControl;\r
+import com.gitblit.Keys;\r
+import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.wicket.WicketUtils;\r
+\r
+/**\r
+ * A radio group panel of the 5 available authorization/access restriction combinations.\r
+ *\r
+ * @author James Moger\r
+ *\r
+ */\r
+public class RepositoryPermissionPanel extends BasePanel {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ private final RepositoryModel repository;\r
+\r
+ private RadioGroup<Permission> permissionGroup;\r
+\r
+ public RepositoryPermissionPanel(String wicketId, RepositoryModel repository) {\r
+ super(wicketId);\r
+ this.repository = repository;\r
+ }\r
+\r
+ @Override\r
+ protected void onInitialize() {\r
+ super.onInitialize();\r
+\r
+ Permission anonymousPermission = new Permission(getString("gb.anonymousPush"),\r
+ getString("gb.anonymousPushDescription"),\r
+ "blank.png",\r
+ AuthorizationControl.AUTHENTICATED,\r
+ AccessRestrictionType.NONE);\r
+\r
+ Permission authenticatedPermission = new Permission(getString("gb.pushRestrictedAuthenticated"),\r
+ getString("gb.pushRestrictedAuthenticatedDescription"),\r
+ "lock_go_16x16.png",\r
+ AuthorizationControl.AUTHENTICATED,\r
+ AccessRestrictionType.PUSH);\r
+\r
+ Permission publicPermission = new Permission(getString("gb.pushRestrictedNamed"),\r
+ getString("gb.pushRestrictedNamedDescription"),\r
+ "lock_go_16x16.png",\r
+ AuthorizationControl.NAMED,\r
+ AccessRestrictionType.PUSH);\r
+\r
+ Permission protectedPermission = new Permission(getString("gb.cloneRestricted"),\r
+ getString("gb.cloneRestrictedDescription"),\r
+ "lock_pull_16x16.png",\r
+ AuthorizationControl.NAMED,\r
+ AccessRestrictionType.CLONE);\r
+\r
+ Permission privatePermission = new Permission(getString("gb.private"),\r
+ getString("gb.privateRepoDescription"),\r
+ "shield_16x16.png",\r
+ AuthorizationControl.NAMED,\r
+ AccessRestrictionType.VIEW);\r
+\r
+ List<Permission> permissions = new ArrayList<Permission>();\r
+ if (app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)) {\r
+ permissions.add(anonymousPermission);\r
+ }\r
+ permissions.add(authenticatedPermission);\r
+ permissions.add(publicPermission);\r
+ permissions.add(protectedPermission);\r
+ permissions.add(privatePermission);\r
+\r
+ AccessRestrictionType defaultRestriction = repository.accessRestriction;\r
+ if (defaultRestriction == null) {\r
+ defaultRestriction = AccessRestrictionType.fromName(app().settings().getString(Keys.git.defaultAccessRestriction,\r
+ AccessRestrictionType.PUSH.name()));\r
+ }\r
+\r
+ AuthorizationControl defaultControl = repository.authorizationControl;\r
+ if (defaultControl == null) {\r
+ defaultControl = AuthorizationControl.fromName(app().settings().getString(Keys.git.defaultAuthorizationControl,\r
+ AuthorizationControl.NAMED.name()));\r
+ }\r
+\r
+ Permission defaultPermission = publicPermission;\r
+ for (Permission permission : permissions) {\r
+ if (permission.type == defaultRestriction && permission.control == defaultControl) {\r
+ defaultPermission = permission;\r
+ }\r
+ }\r
+\r
+ permissionGroup = new RadioGroup<>("permissionsGroup", new Model<Permission>(defaultPermission));\r
+ ListView<Permission> permissionsList = new ListView<Permission>("permissions", permissions) {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ @Override\r
+ protected void populateItem(ListItem<Permission> item) {\r
+ Permission p = item.getModelObject();\r
+ item.add(new Radio<Permission>("radio", item.getModel()));\r
+ item.add(WicketUtils.newImage("image", p.image));\r
+ item.add(new Label("name", p.name));\r
+ item.add(new Label("description", p.description));\r
+ }\r
+ };\r
+ permissionGroup.add(permissionsList);\r
+\r
+ setOutputMarkupId(true);\r
+\r
+ add(permissionGroup);\r
+ }\r
+\r
+ public void setPermission(RepositoryModel repository) {\r
+ Permission permission = permissionGroup.getModelObject();\r
+ repository.authorizationControl = permission.control;\r
+ repository.accessRestriction = permission.type;\r
+ }\r
+\r
+ @Override\r
+ protected boolean getStatelessHint() {\r
+ return false;\r
+ }\r
+\r
+ private static class Permission implements Serializable {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ final String name;\r
+ final String description;\r
+ final String image;\r
+ final AuthorizationControl control;\r
+ final AccessRestrictionType type;\r
+\r
+ Permission(String name, String description, String img, AuthorizationControl control, AccessRestrictionType type) {\r
+ this.name = name;\r
+ this.description = description;\r
+ this.image = img;\r
+ this.control = control;\r
+ this.type = type;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return name;\r
+ }\r
+ }\r
+}\r