]> source.dussan.org Git - gitblit.git/commitdiff
Allow selection of integration branch in new ticket page
authorJames Moger <james.moger@gitblit.com>
Sat, 8 Mar 2014 16:53:01 +0000 (11:53 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 8 Mar 2014 16:53:01 +0000 (11:53 -0500)
src/main/java/com/gitblit/models/UserModel.java
src/main/java/com/gitblit/wicket/pages/EditTicketPage.java
src/main/java/com/gitblit/wicket/pages/NewTicketPage.html
src/main/java/com/gitblit/wicket/pages/NewTicketPage.java
src/main/java/com/gitblit/wicket/pages/TicketPage.java

index fee9c172f15269984e406ba49c1458d9c9410817..675835d3a8f97e1fb28d960046de718928d92bf5 100644 (file)
@@ -449,9 +449,15 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
 \r
        public boolean canEdit(TicketModel ticket, RepositoryModel repository) {\r
                 return isAuthenticated() &&\r
-                                (username.equals(ticket.createdBy)\r
-                                || username.equals(ticket.responsible)\r
-                                || canPush(repository));\r
+                                (canPush(repository)\r
+                                || (ticket != null && username.equals(ticket.responsible))\r
+                                || (ticket != null && username.equals(ticket.createdBy)));\r
+       }\r
+\r
+       public boolean canAdmin(TicketModel ticket, RepositoryModel repository) {\r
+                return isAuthenticated() &&\r
+                                (canPush(repository)\r
+                                || ticket != null && username.equals(ticket.responsible));\r
        }\r
 \r
        public boolean canReviewPatchset(RepositoryModel model) {\r
index ac7595893b4e841c5c16a148a47aa19d40008d4f..b5004861150be64c58b33726ca8422dbd37d8753 100644 (file)
@@ -250,71 +250,77 @@ public class EditTicketPage extends RepositoryPage {
                status.add(new DropDownChoice<TicketModel.Status>("status", statusModel, statusChoices));\r
                form.add(status);\r
 \r
-               // responsible\r
-               Set<String> userlist = new TreeSet<String>(ticket.getParticipants());\r
+               if (currentUser.canAdmin(ticket, getRepositoryModel())) {\r
+                       // responsible\r
+                       Set<String> userlist = new TreeSet<String>(ticket.getParticipants());\r
 \r
-               for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {\r
-                       if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) {\r
-                               userlist.add(rp.registrant);\r
+                       for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {\r
+                               if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) {\r
+                                       userlist.add(rp.registrant);\r
+                               }\r
                        }\r
-               }\r
 \r
-               List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();\r
-               for (String username : userlist) {\r
-                       UserModel user = app().users().getUserModel(username);\r
-                       if (user != null) {\r
-                               TicketResponsible responsible = new TicketResponsible(user);\r
-                               responsibles.add(responsible);\r
-                               if (user.username.equals(ticket.responsible)) {\r
-                                       responsibleModel.setObject(responsible);\r
+                       List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();\r
+                       for (String username : userlist) {\r
+                               UserModel user = app().users().getUserModel(username);\r
+                               if (user != null) {\r
+                                       TicketResponsible responsible = new TicketResponsible(user);\r
+                                       responsibles.add(responsible);\r
+                                       if (user.username.equals(ticket.responsible)) {\r
+                                               responsibleModel.setObject(responsible);\r
+                                       }\r
                                }\r
                        }\r
-               }\r
-               Collections.sort(responsibles);\r
-               responsibles.add(new TicketResponsible(NIL, "", ""));\r
-               Fragment responsible = new Fragment("responsible", "responsibleFragment", this);\r
-               responsible.add(new DropDownChoice<TicketResponsible>("responsible", responsibleModel, responsibles));\r
-               form.add(responsible.setVisible(!responsibles.isEmpty()));\r
-\r
-               // milestone\r
-               List<TicketMilestone> milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open);\r
-               for (TicketMilestone milestone : milestones) {\r
-                       if (milestone.name.equals(ticket.milestone)) {\r
-                               milestoneModel.setObject(milestone);\r
-                               break;\r
+                       Collections.sort(responsibles);\r
+                       responsibles.add(new TicketResponsible(NIL, "", ""));\r
+                       Fragment responsible = new Fragment("responsible", "responsibleFragment", this);\r
+                       responsible.add(new DropDownChoice<TicketResponsible>("responsible", responsibleModel, responsibles));\r
+                       form.add(responsible.setVisible(!responsibles.isEmpty()));\r
+\r
+                       // milestone\r
+                       List<TicketMilestone> milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open);\r
+                       for (TicketMilestone milestone : milestones) {\r
+                               if (milestone.name.equals(ticket.milestone)) {\r
+                                       milestoneModel.setObject(milestone);\r
+                                       break;\r
+                               }\r
+                       }\r
+                       if (milestoneModel.getObject() == null && !StringUtils.isEmpty(ticket.milestone)) {\r
+                               // ensure that this unrecognized milestone is listed\r
+                               // so that we get the <nil> selection.\r
+                               TicketMilestone tms = new TicketMilestone(ticket.milestone);\r
+                               milestones.add(tms);\r
+                               milestoneModel.setObject(tms);\r
+                       }\r
+                       if (!milestones.isEmpty()) {\r
+                               milestones.add(new TicketMilestone(NIL));\r
                        }\r
-               }\r
-               if (milestoneModel.getObject() == null && !StringUtils.isEmpty(ticket.milestone)) {\r
-                       // ensure that this unrecognized milestone is listed\r
-                       // so that we get the <nil> selection.\r
-                       TicketMilestone tms = new TicketMilestone(ticket.milestone);\r
-                       milestones.add(tms);\r
-                       milestoneModel.setObject(tms);\r
-               }\r
-               if (!milestones.isEmpty()) {\r
-                       milestones.add(new TicketMilestone(NIL));\r
-               }\r
 \r
-               Fragment milestone = new Fragment("milestone", "milestoneFragment", this);\r
+                       Fragment milestone = new Fragment("milestone", "milestoneFragment", this);\r
 \r
-               milestone.add(new DropDownChoice<TicketMilestone>("milestone", milestoneModel, milestones));\r
-               form.add(milestone.setVisible(!milestones.isEmpty()));\r
+                       milestone.add(new DropDownChoice<TicketMilestone>("milestone", milestoneModel, milestones));\r
+                       form.add(milestone.setVisible(!milestones.isEmpty()));\r
 \r
-               // mergeTo (integration branch)\r
-               List<String> branches = new ArrayList<String>();\r
-               for (String branch : getRepositoryModel().getLocalBranches()) {\r
-                       // exclude ticket branches\r
-                       if (!branch.startsWith(Constants.R_TICKET)) {\r
-                               branches.add(Repository.shortenRefName(branch));\r
+                       // mergeTo (integration branch)\r
+                       List<String> branches = new ArrayList<String>();\r
+                       for (String branch : getRepositoryModel().getLocalBranches()) {\r
+                               // exclude ticket branches\r
+                               if (!branch.startsWith(Constants.R_TICKET)) {\r
+                                       branches.add(Repository.shortenRefName(branch));\r
+                               }\r
                        }\r
-               }\r
-               branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD));\r
-               branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD));\r
-\r
-               Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this);\r
-               mergeto.add(new DropDownChoice<String>("mergeto", mergeToModel, branches));\r
-               form.add(mergeto.setVisible(!branches.isEmpty()));\r
+                       branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD));\r
+                       branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD));\r
 \r
+                       Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this);\r
+                       mergeto.add(new DropDownChoice<String>("mergeto", mergeToModel, branches));\r
+                       form.add(mergeto.setVisible(!branches.isEmpty()));\r
+               } else {\r
+                       // user can not admin this ticket\r
+                       form.add(new Label("responsible").setVisible(false));\r
+                       form.add(new Label("milestone").setVisible(false));\r
+                       form.add(new Label("mergeto").setVisible(false));\r
+               }\r
                form.add(new Button("update"));\r
                Button cancel = new Button("cancel") {\r
                        private static final long serialVersionUID = 1L;\r
index 71570df4bf67e32572a0e92d9c9163330731b8aa..447c6aa4f396bd3caa27b2d8af0aae1fe37a162c 100644 (file)
@@ -41,6 +41,7 @@
                        <tr><th><wicket:message key="gb.type"></wicket:message><span style="color:red;">*</span></th><td class="edit"><select class="input-large" wicket:id="type"></select></td></tr>\r
                        <tr wicket:id="responsible"></tr>\r
                        <tr wicket:id="milestone"></tr>\r
+                       <tr wicket:id="mergeto"></tr>\r
                </table>\r
        </div>\r
        </div>  \r
@@ -62,5 +63,9 @@
        <th><wicket:message key="gb.milestone"></wicket:message></th><td class="edit"><select class="input-large" wicket:id="milestone"></select></td>\r
 </wicket:fragment>\r
 \r
+<wicket:fragment wicket:id="mergeToFragment">\r
+       <th><wicket:message key="gb.mergeTo"></wicket:message></th><td class="edit"><select class="input-large" wicket:id="mergeto"></select></td>\r
+</wicket:fragment>\r
+\r
 </wicket:extend>\r
 </html>
\ No newline at end of file
index 17ad1d1b10104c38e6a7e23cd499adc471cb36a1..25fe48f4023b14b94cd60122ad4d66decb53e07d 100644 (file)
@@ -29,7 +29,9 @@ import org.apache.wicket.markup.html.form.TextField;
 import org.apache.wicket.markup.html.panel.Fragment;\r
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
+import org.eclipse.jgit.lib.Repository;\r
 \r
+import com.gitblit.Constants;\r
 import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.TicketModel;\r
@@ -61,6 +63,8 @@ public class NewTicketPage extends RepositoryPage {
 \r
        private IModel<String> topicModel;\r
 \r
+       private IModel<String> mergeToModel;\r
+\r
        private IModel<TicketResponsible> responsibleModel;\r
 \r
        private IModel<TicketMilestone> milestoneModel;\r
@@ -83,6 +87,7 @@ public class NewTicketPage extends RepositoryPage {
                typeModel = Model.of(TicketModel.Type.defaultType);\r
                titleModel = Model.of();\r
                topicModel = Model.of();\r
+               mergeToModel = Model.of(Repository.shortenRefName(getRepositoryModel().HEAD));\r
                responsibleModel = Model.of();\r
                milestoneModel = Model.of();\r
 \r
@@ -123,6 +128,12 @@ public class NewTicketPage extends RepositoryPage {
                                        change.setField(Field.milestone, milestone.name);\r
                                }\r
 \r
+                               // integration branch\r
+                               String mergeTo = mergeToModel.getObject();\r
+                               if (!StringUtils.isEmpty(mergeTo)) {\r
+                                       change.setField(Field.mergeTo, mergeTo);\r
+                               }\r
+\r
                                TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change);\r
                                if (ticket != null) {\r
                                        TicketNotifier notifier = app().tickets().createNotifier();\r
@@ -149,7 +160,7 @@ public class NewTicketPage extends RepositoryPage {
                descriptionEditor.setRepository(repositoryName);\r
                form.add(descriptionEditor);\r
 \r
-               if (currentUser != null && currentUser.isAuthenticated && currentUser.canPush(getRepositoryModel())) {\r
+               if (currentUser.canAdmin(null, getRepositoryModel())) {\r
                        // responsible\r
                        List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();\r
                        for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {\r
@@ -170,10 +181,26 @@ public class NewTicketPage extends RepositoryPage {
                        Fragment milestone = new Fragment("milestone", "milestoneFragment", this);\r
                        milestone.add(new DropDownChoice<TicketMilestone>("milestone", milestoneModel, milestones));\r
                        form.add(milestone.setVisible(!milestones.isEmpty()));\r
+\r
+                       // integration branch\r
+                       List<String> branches = new ArrayList<String>();\r
+                       for (String branch : getRepositoryModel().getLocalBranches()) {\r
+                               // exclude ticket branches\r
+                               if (!branch.startsWith(Constants.R_TICKET)) {\r
+                                       branches.add(Repository.shortenRefName(branch));\r
+                               }\r
+                       }\r
+                       branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD));\r
+                       branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD));\r
+\r
+                       Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this);\r
+                       mergeto.add(new DropDownChoice<String>("mergeto", mergeToModel, branches));\r
+                       form.add(mergeto.setVisible(!branches.isEmpty()));\r
                } else {\r
-                       // user does not have permission to assign milestone or responsible\r
+                       // user does not have permission to assign milestone, responsible, or mergeto\r
                        form.add(new Label("responsible").setVisible(false));\r
                        form.add(new Label("milestone").setVisible(false));\r
+                       form.add(new Label("mergeto").setVisible(false));\r
                }\r
 \r
                form.add(new Button("create"));\r
index 7b492dc270326ed767e7646f2cdc6a77e13db949..1c0544c8fad75e8ec27b74325b4091cc4c3438be 100644 (file)
@@ -327,7 +327,7 @@ public class TicketPage extends TicketBasePage {
                 * UPDATE FORM (DISCUSSION TAB)\r
                 */\r
                if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) {\r
-                       if (ticket.isOpen()) {\r
+                       if (user.canAdmin(ticket, repository) && ticket.isOpen()) {\r
                                /*\r
                                 * OPEN TICKET\r
                                 */\r