From 9ee3a079b7bfa53e1c68e5510643de538db8a223 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 31 2017 09:41:48 +0000 Subject: Allow project maintainer to set metadata when creating a new issue This commit allows project maintainer to set some of the metadata when creating a new issue. This currently supports: tags, assignee, priority and milestone. Fixes #926 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/forms.py b/pagure/forms.py index a07b8f3..6e8080d 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -198,11 +198,39 @@ class IssueFormSimplied(PagureForm): [wtforms.validators.optional()], false_values=FALSE_VALUES, ) - milestone = wtforms.TextField( + milestone = wtforms.SelectField( 'Milestone', [wtforms.validators.Optional()], + choices=[], + coerce=convert_value + ) + priority = wtforms.SelectField( + 'Priority', + [wtforms.validators.Optional()], + choices=[], + coerce=convert_value ) + def __init__(self, *args, **kwargs): + """ Calls the default constructor with the normal argument but + uses the list of collection provided to fill the choices of the + drop-down list. + """ + super(IssueFormSimplied, self).__init__(*args, **kwargs) + + self.priority.choices = [] + if 'priorities' in kwargs: + for key in sorted(kwargs['priorities']): + self.priority.choices.append( + (key, kwargs['priorities'][key]) + ) + + self.milestone.choices = [] + if 'milestones' in kwargs and kwargs['milestones']: + for key in sorted(kwargs['milestones']): + self.milestone.choices.append((key, key)) + self.milestone.choices.insert(0, ('', '')) + class IssueForm(IssueFormSimplied): ''' Form to create or edit an issue. ''' diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 8e88c2f..16e6c42 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1417,7 +1417,8 @@ def new_project(session, user, name, blacklist, allowed_prefix, def new_issue(session, repo, title, content, user, ticketfolder, issue_id=None, issue_uid=None, private=False, status=None, close_status=None, - notify=True, date_created=None, milestone=None, priority=None): + notify=True, date_created=None, milestone=None, priority=None, + assignee=None, tags=None): ''' Create a new issue for the specified repo. ''' user_obj = get_user(session, user) @@ -1434,6 +1435,10 @@ def new_issue(session, repo, title, content, user, ticketfolder, issue_id=None, 'You are trying to create an issue with a priority that does ' 'not exist in the project.') + assignee_id = None + if assignee is not None: + assignee_id = get_user(session, assignee).id + issue = model.Issue( id=issue_id or get_next_id(session, repo.id), project_id=repo.id, @@ -1441,6 +1446,7 @@ def new_issue(session, repo, title, content, user, ticketfolder, issue_id=None, content=content, priority=priority, milestone=milestone, + assignee_id=assignee_id, user_id=user_obj.id, uid=issue_uid or uuid.uuid4().hex, private=private, @@ -1456,6 +1462,25 @@ def new_issue(session, repo, title, content, user, ticketfolder, issue_id=None, session.add(issue) # Make sure we won't have SQLAlchemy error before we create the issue session.flush() + + # Add the tags if any are specified + if tags is not None: + for lbl in tags: + tagobj = get_colored_tag(session, lbl, repo.id) + if not tagobj: + tagobj = model.TagColored( + tag=lbl, + project_id=repo.id + ) + session.add(tagobj) + session.flush() + + dbobjtag = model.TagIssueColored( + issue_uid=issue.uid, + tag_id=tagobj.id + ) + session.add(dbobjtag) + session.commit() pagure.lib.git.update_git( diff --git a/pagure/templates/new_issue.html b/pagure/templates/new_issue.html index a678f76..ac6e428 100644 --- a/pagure/templates/new_issue.html +++ b/pagure/templates/new_issue.html @@ -12,12 +12,29 @@ rel="stylesheet" /> + {% endblock %} {% block repo %}
-
+ {% if not type or type == 'new' %} +
+ + {% elif type and type == 'edit' %} + + {% endif %} +
{% if not type or type == 'new' %} @@ -27,21 +44,6 @@ {% endif %}
- {% if not type or type == 'new' %} - - - {% elif type and type == 'edit' %} - - {% endif %} {{ render_bootstrap_field(form.title, field_description="Gist of your issue") }} {% if type == 'edit' %} {{ render_bootstrap_field(form.status, field_description="bug status") }} @@ -102,9 +104,38 @@ Markdown Syntax

-
+
+ + {% if g.repo_user and not type or type == 'new' %} +
+
+
+ +
+ + +
+ +
+ + +
+ + {{ render_bootstrap_field(form.priority) }} + {{ render_bootstrap_field(form.milestone) }} + +
+
+
+ {% endif %} + {% if authenticated and g.repo_committer and type and type == 'edit' %}
+