From: James Moger Date: Sat, 8 Mar 2014 16:53:01 +0000 (-0500) Subject: Allow selection of integration branch in new ticket page X-Git-Tag: v1.4.0~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cc1c3ffa7d261d2e8bcdc600253528e8d09e1d06;p=gitblit.git Allow selection of integration branch in new ticket page --- diff --git a/src/main/java/com/gitblit/models/UserModel.java b/src/main/java/com/gitblit/models/UserModel.java index fee9c172..675835d3 100644 --- a/src/main/java/com/gitblit/models/UserModel.java +++ b/src/main/java/com/gitblit/models/UserModel.java @@ -449,9 +449,15 @@ public class UserModel implements Principal, Serializable, Comparable public boolean canEdit(TicketModel ticket, RepositoryModel repository) { return isAuthenticated() && - (username.equals(ticket.createdBy) - || username.equals(ticket.responsible) - || canPush(repository)); + (canPush(repository) + || (ticket != null && username.equals(ticket.responsible)) + || (ticket != null && username.equals(ticket.createdBy))); + } + + public boolean canAdmin(TicketModel ticket, RepositoryModel repository) { + return isAuthenticated() && + (canPush(repository) + || ticket != null && username.equals(ticket.responsible)); } public boolean canReviewPatchset(RepositoryModel model) { diff --git a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java index ac759589..b5004861 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java @@ -250,71 +250,77 @@ public class EditTicketPage extends RepositoryPage { status.add(new DropDownChoice("status", statusModel, statusChoices)); form.add(status); - // responsible - Set userlist = new TreeSet(ticket.getParticipants()); + if (currentUser.canAdmin(ticket, getRepositoryModel())) { + // responsible + Set userlist = new TreeSet(ticket.getParticipants()); - for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) { - if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) { - userlist.add(rp.registrant); + for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) { + if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) { + userlist.add(rp.registrant); + } } - } - List responsibles = new ArrayList(); - for (String username : userlist) { - UserModel user = app().users().getUserModel(username); - if (user != null) { - TicketResponsible responsible = new TicketResponsible(user); - responsibles.add(responsible); - if (user.username.equals(ticket.responsible)) { - responsibleModel.setObject(responsible); + List responsibles = new ArrayList(); + for (String username : userlist) { + UserModel user = app().users().getUserModel(username); + if (user != null) { + TicketResponsible responsible = new TicketResponsible(user); + responsibles.add(responsible); + if (user.username.equals(ticket.responsible)) { + responsibleModel.setObject(responsible); + } } } - } - Collections.sort(responsibles); - responsibles.add(new TicketResponsible(NIL, "", "")); - Fragment responsible = new Fragment("responsible", "responsibleFragment", this); - responsible.add(new DropDownChoice("responsible", responsibleModel, responsibles)); - form.add(responsible.setVisible(!responsibles.isEmpty())); - - // milestone - List milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open); - for (TicketMilestone milestone : milestones) { - if (milestone.name.equals(ticket.milestone)) { - milestoneModel.setObject(milestone); - break; + Collections.sort(responsibles); + responsibles.add(new TicketResponsible(NIL, "", "")); + Fragment responsible = new Fragment("responsible", "responsibleFragment", this); + responsible.add(new DropDownChoice("responsible", responsibleModel, responsibles)); + form.add(responsible.setVisible(!responsibles.isEmpty())); + + // milestone + List milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open); + for (TicketMilestone milestone : milestones) { + if (milestone.name.equals(ticket.milestone)) { + milestoneModel.setObject(milestone); + break; + } + } + if (milestoneModel.getObject() == null && !StringUtils.isEmpty(ticket.milestone)) { + // ensure that this unrecognized milestone is listed + // so that we get the selection. + TicketMilestone tms = new TicketMilestone(ticket.milestone); + milestones.add(tms); + milestoneModel.setObject(tms); + } + if (!milestones.isEmpty()) { + milestones.add(new TicketMilestone(NIL)); } - } - if (milestoneModel.getObject() == null && !StringUtils.isEmpty(ticket.milestone)) { - // ensure that this unrecognized milestone is listed - // so that we get the selection. - TicketMilestone tms = new TicketMilestone(ticket.milestone); - milestones.add(tms); - milestoneModel.setObject(tms); - } - if (!milestones.isEmpty()) { - milestones.add(new TicketMilestone(NIL)); - } - Fragment milestone = new Fragment("milestone", "milestoneFragment", this); + Fragment milestone = new Fragment("milestone", "milestoneFragment", this); - milestone.add(new DropDownChoice("milestone", milestoneModel, milestones)); - form.add(milestone.setVisible(!milestones.isEmpty())); + milestone.add(new DropDownChoice("milestone", milestoneModel, milestones)); + form.add(milestone.setVisible(!milestones.isEmpty())); - // mergeTo (integration branch) - List branches = new ArrayList(); - for (String branch : getRepositoryModel().getLocalBranches()) { - // exclude ticket branches - if (!branch.startsWith(Constants.R_TICKET)) { - branches.add(Repository.shortenRefName(branch)); + // mergeTo (integration branch) + List branches = new ArrayList(); + for (String branch : getRepositoryModel().getLocalBranches()) { + // exclude ticket branches + if (!branch.startsWith(Constants.R_TICKET)) { + branches.add(Repository.shortenRefName(branch)); + } } - } - branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD)); - branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD)); - - Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this); - mergeto.add(new DropDownChoice("mergeto", mergeToModel, branches)); - form.add(mergeto.setVisible(!branches.isEmpty())); + branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD)); + branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD)); + Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this); + mergeto.add(new DropDownChoice("mergeto", mergeToModel, branches)); + form.add(mergeto.setVisible(!branches.isEmpty())); + } else { + // user can not admin this ticket + form.add(new Label("responsible").setVisible(false)); + form.add(new Label("milestone").setVisible(false)); + form.add(new Label("mergeto").setVisible(false)); + } form.add(new Button("update")); Button cancel = new Button("cancel") { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html index 71570df4..447c6aa4 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html +++ b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html @@ -41,6 +41,7 @@ * + @@ -62,5 +63,9 @@ + + + + \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java index 17ad1d1b..25fe48f4 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java @@ -29,7 +29,9 @@ import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; +import org.eclipse.jgit.lib.Repository; +import com.gitblit.Constants; import com.gitblit.Constants.AccessPermission; import com.gitblit.models.RegistrantAccessPermission; import com.gitblit.models.TicketModel; @@ -61,6 +63,8 @@ public class NewTicketPage extends RepositoryPage { private IModel topicModel; + private IModel mergeToModel; + private IModel responsibleModel; private IModel milestoneModel; @@ -83,6 +87,7 @@ public class NewTicketPage extends RepositoryPage { typeModel = Model.of(TicketModel.Type.defaultType); titleModel = Model.of(); topicModel = Model.of(); + mergeToModel = Model.of(Repository.shortenRefName(getRepositoryModel().HEAD)); responsibleModel = Model.of(); milestoneModel = Model.of(); @@ -123,6 +128,12 @@ public class NewTicketPage extends RepositoryPage { change.setField(Field.milestone, milestone.name); } + // integration branch + String mergeTo = mergeToModel.getObject(); + if (!StringUtils.isEmpty(mergeTo)) { + change.setField(Field.mergeTo, mergeTo); + } + TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change); if (ticket != null) { TicketNotifier notifier = app().tickets().createNotifier(); @@ -149,7 +160,7 @@ public class NewTicketPage extends RepositoryPage { descriptionEditor.setRepository(repositoryName); form.add(descriptionEditor); - if (currentUser != null && currentUser.isAuthenticated && currentUser.canPush(getRepositoryModel())) { + if (currentUser.canAdmin(null, getRepositoryModel())) { // responsible List responsibles = new ArrayList(); for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) { @@ -170,10 +181,26 @@ public class NewTicketPage extends RepositoryPage { Fragment milestone = new Fragment("milestone", "milestoneFragment", this); milestone.add(new DropDownChoice("milestone", milestoneModel, milestones)); form.add(milestone.setVisible(!milestones.isEmpty())); + + // integration branch + List branches = new ArrayList(); + for (String branch : getRepositoryModel().getLocalBranches()) { + // exclude ticket branches + if (!branch.startsWith(Constants.R_TICKET)) { + branches.add(Repository.shortenRefName(branch)); + } + } + branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD)); + branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD)); + + Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this); + mergeto.add(new DropDownChoice("mergeto", mergeToModel, branches)); + form.add(mergeto.setVisible(!branches.isEmpty())); } else { - // user does not have permission to assign milestone or responsible + // user does not have permission to assign milestone, responsible, or mergeto form.add(new Label("responsible").setVisible(false)); form.add(new Label("milestone").setVisible(false)); + form.add(new Label("mergeto").setVisible(false)); } form.add(new Button("create")); diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index 7b492dc2..1c0544c8 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -327,7 +327,7 @@ public class TicketPage extends TicketBasePage { * UPDATE FORM (DISCUSSION TAB) */ if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) { - if (ticket.isOpen()) { + if (user.canAdmin(ticket, repository) && ticket.isOpen()) { /* * OPEN TICKET */