From 6a437ec4a6853bdd15f7c33f7fbafdd247a3790c Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 31 May 2014 10:23:56 -0400 Subject: Use AccessPolicyPanel in EditRepositoryPage --- .../com/gitblit/wicket/GitBlitWebApp.properties | 4 +- .../gitblit/wicket/pages/EditRepositoryPage.html | 4 +- .../gitblit/wicket/pages/EditRepositoryPage.java | 91 +++------------------- .../gitblit/wicket/pages/NewRepositoryPage.html | 6 +- .../gitblit/wicket/pages/NewRepositoryPage.java | 10 +-- .../gitblit/wicket/panels/AccessPolicyPanel.java | 17 +++- 6 files changed, 33 insertions(+), 99 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index d2d1454e..13abcc06 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -687,7 +687,7 @@ gb.plugins = plugins gb.extensions = extensions gb.pleaseSelectProject = Please select the project! gb.accessPolicy = Access Policy -gb.accessPolicyDescription = Choose an access policy to control visibility, cloning, and pushing to this repository. +gb.accessPolicyDescription = Choose an access policy to control repository visibility and git permissions. gb.anonymousPolicy = Anonymous View, Clone, & Push gb.anonymousPolicyDescription = Anyone can see, clone, and push to this repository. gb.authenticatedPushPolicy = Restrict Push (Authenticated) @@ -704,5 +704,3 @@ gb.initWithReadme = Include a README gb.initWithReadmeDescription = This will generate a simple README document for your repository. gb.initWithGitignore = Include a .gitignore file gb.initWithGitignoreDescription = This will insert a config file that instructs your Git clients to ignore files or directories that match defined patterns. -gb.initWithGitflow = Include a .gitflow file -gb.initWithGitflowDescription = This will generate a config file which guides Git clients in setting up Gitflow branches. \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html index ccb60a5c..ab448038 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html @@ -58,9 +58,7 @@
-   diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java index 4759fd0d..e86bd1ee 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -29,7 +29,6 @@ import java.util.Set; import org.apache.wicket.PageParameters; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior; -import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.extensions.markup.html.form.palette.Palette; import org.apache.wicket.markup.html.WebMarkupContainer; @@ -40,7 +39,6 @@ import org.apache.wicket.markup.html.form.ChoiceRenderer; 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.form.RadioChoice; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.list.ListItem; @@ -69,6 +67,7 @@ import com.gitblit.utils.StringUtils; import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.StringChoiceRenderer; import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.panels.AccessPolicyPanel; import com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation; import com.gitblit.wicket.panels.BulletListPanel; import com.gitblit.wicket.panels.RegistrantPermissionsPanel; @@ -80,6 +79,8 @@ public class EditRepositoryPage extends RootSubPage { RepositoryNamePanel namePanel; + AccessPolicyPanel accessPolicyPanel; + private boolean isAdmin; RepositoryModel repositoryModel; @@ -396,9 +397,6 @@ public class EditRepositoryPage extends RootSubPage { form.add(ownersPalette); form.add(new CheckBox("allowForks").setEnabled(app().settings().getBoolean(Keys.web.allowForking, true))); - DropDownChoice accessRestriction = new DropDownChoice("accessRestriction", - AccessRestrictionType.choices(app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)), new AccessRestrictionRenderer()); - form.add(accessRestriction); form.add(new CheckBox("isFrozen")); // TODO enable origin definition form.add(new TextField("origin").setEnabled(false/* isCreate */)); @@ -456,11 +454,6 @@ public class EditRepositoryPage extends RootSubPage { form.add(new TextField("mailingLists", mailingLists)); form.add(indexedBranchesPalette); - List acList = Arrays.asList(AuthorizationControl.values()); - final RadioChoice authorizationControl = new RadioChoice( - "authorizationControl", acList, new AuthorizationControlRenderer()); - form.add(authorizationControl); - final CheckBox verifyCommitter = new CheckBox("verifyCommitter"); verifyCommitter.setOutputMarkupId(true); form.add(verifyCommitter); @@ -484,12 +477,10 @@ public class EditRepositoryPage extends RootSubPage { // anonymous everything, disable all controls usersPalette.setEnabled(false); teamsPalette.setEnabled(false); - authorizationControl.setEnabled(false); verifyCommitter.setEnabled(false); } else { // authenticated something // enable authorization controls - authorizationControl.setEnabled(true); verifyCommitter.setEnabled(true); boolean allowFineGrainedControls = repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED); @@ -497,15 +488,15 @@ public class EditRepositoryPage extends RootSubPage { teamsPalette.setEnabled(allowFineGrainedControls); } - accessRestriction.add(new AjaxFormComponentUpdatingBehavior("onchange") { + AjaxFormChoiceComponentUpdatingBehavior callback = new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { - // enable/disable permissions panel based on access restriction + accessPolicyPanel.updateModel(repositoryModel); + boolean allowAuthorizationControl = repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE); - authorizationControl.setEnabled(allowAuthorizationControl); verifyCommitter.setEnabled(allowAuthorizationControl); boolean allowFineGrainedControls = allowAuthorizationControl && repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED); @@ -516,36 +507,14 @@ public class EditRepositoryPage extends RootSubPage { repositoryModel.authorizationControl = AuthorizationControl.NAMED; } - target.addComponent(authorizationControl); target.addComponent(verifyCommitter); target.addComponent(usersPalette); target.addComponent(teamsPalette); } - }); - - authorizationControl.add(new AjaxFormChoiceComponentUpdatingBehavior() { - - private static final long serialVersionUID = 1L; - - @Override - protected void onUpdate(AjaxRequestTarget target) { - // enable/disable permissions panel based on access restriction - boolean allowAuthorizationControl = repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE); - authorizationControl.setEnabled(allowAuthorizationControl); - - boolean allowFineGrainedControls = allowAuthorizationControl && repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED); - usersPalette.setEnabled(allowFineGrainedControls); - teamsPalette.setEnabled(allowFineGrainedControls); + }; - if (allowFineGrainedControls) { - repositoryModel.authorizationControl = AuthorizationControl.NAMED; - } - - target.addComponent(authorizationControl); - target.addComponent(usersPalette); - target.addComponent(teamsPalette); - } - }); + accessPolicyPanel = new AccessPolicyPanel("accessPolicyPanel", repositoryModel, callback); + form.add(accessPolicyPanel); List renderers = Arrays.asList(CommitMessageRenderer.values()); DropDownChoice messageRendererChoice = new DropDownChoice("commitMessageRenderer", renderers); @@ -656,27 +625,6 @@ public class EditRepositoryPage extends RootSubPage { } } - private class AccessRestrictionRenderer implements IChoiceRenderer { - - private static final long serialVersionUID = 1L; - - private final Map map; - - public AccessRestrictionRenderer() { - map = getAccessRestrictions(); - } - - @Override - public String getDisplayValue(AccessRestrictionType type) { - return map.get(type); - } - - @Override - public String getIdValue(AccessRestrictionType type, int index) { - return Integer.toString(index); - } - } - private class FederationTypeRenderer implements IChoiceRenderer { private static final long serialVersionUID = 1L; @@ -698,27 +646,6 @@ public class EditRepositoryPage extends RootSubPage { } } - private class AuthorizationControlRenderer implements IChoiceRenderer { - - private static final long serialVersionUID = 1L; - - private final Map map; - - public AuthorizationControlRenderer() { - map = getAuthorizationControls(); - } - - @Override - public String getDisplayValue(AuthorizationControl type) { - return map.get(type); - } - - @Override - public String getIdValue(AuthorizationControl type, int index) { - return Integer.toString(index); - } - } - private class GCPeriodRenderer implements IChoiceRenderer { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html index 8e4e74ac..df55381a 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html +++ b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.html @@ -14,7 +14,7 @@
-
+

@@ -39,8 +39,8 @@
- -

+ Include a .gitflow file +

This will generate a config file which guides Git clients in setting up Gitflow branches.

diff --git a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java index 0adb1ddd..d5ae3440 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java @@ -59,8 +59,8 @@ 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.RepositoryNamePanel; import com.gitblit.wicket.panels.AccessPolicyPanel; +import com.gitblit.wicket.panels.RepositoryNamePanel; public class NewRepositoryPage extends RootSubPage { @@ -69,7 +69,7 @@ public class NewRepositoryPage extends RootSubPage { private Model gitignoreModel; private IModel addGitflowModel; private IModel addGitignoreModel; - private AccessPolicyPanel permissionPanel; + private AccessPolicyPanel accessPolicyPanel; private RepositoryNamePanel namePanel; public NewRepositoryPage() { @@ -108,7 +108,7 @@ public class NewRepositoryPage extends RootSubPage { if (!namePanel.updateModel(repositoryModel)) { return; } - permissionPanel.updateModel(repositoryModel); + accessPolicyPanel.updateModel(repositoryModel); repositoryModel.owners = new ArrayList(); repositoryModel.owners.add(GitBlitWebSession.get().getUsername()); @@ -174,8 +174,8 @@ public class NewRepositoryPage extends RootSubPage { repositoryModel.authorizationControl = defaultControl; repositoryModel.accessRestriction = defaultRestriction; - permissionPanel = new AccessPolicyPanel("permissionPanel", repositoryModel); - form.add(permissionPanel); + accessPolicyPanel = new AccessPolicyPanel("accessPolicyPanel", repositoryModel); + form.add(accessPolicyPanel); // // initial commit options diff --git a/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java b/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java index a115e251..057b96f4 100644 --- a/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java @@ -19,6 +19,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Radio; import org.apache.wicket.markup.html.form.RadioGroup; @@ -44,11 +45,18 @@ public class AccessPolicyPanel extends BasePanel { private final RepositoryModel repository; + private final AjaxFormChoiceComponentUpdatingBehavior callback; + private RadioGroup policiesGroup; public AccessPolicyPanel(String wicketId, RepositoryModel repository) { + this(wicketId, repository, null); + } + + public AccessPolicyPanel(String wicketId, RepositoryModel repository, AjaxFormChoiceComponentUpdatingBehavior callback) { super(wicketId); this.repository = repository; + this.callback = callback; } @Override @@ -128,10 +136,13 @@ public class AccessPolicyPanel extends BasePanel { } }; policiesGroup.add(policiesList); + if (callback != null) { + policiesGroup.add(callback); + policiesGroup.setOutputMarkupId(true); + } + add(policiesGroup); setOutputMarkupId(true); - - add(policiesGroup); } public void updateModel(RepositoryModel repository) { @@ -145,7 +156,7 @@ public class AccessPolicyPanel extends BasePanel { return false; } - private static class AccessPolicy implements Serializable { + public static class AccessPolicy implements Serializable { private static final long serialVersionUID = 1L; -- cgit v1.2.3