From 138ab4df826322f19d225eea8c1c7c0d732b71d5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 22 2017 14:40:26 +0000 Subject: Allow priorities and milestones to be 0 or -1 Up until now priorities could not be 0 or -1, not 0 because we weren't explicitly when doing ``if issue.priority`` and not ``-1`` because it was a reserved value that meant to say: neither a value nor None. With this change, the default value is a random object which allows us to set the value to anything we like including ``None`` (which means resetting the priority). Fixes https://pagure.io/pagure/issue/2482 Fixes https://pagure.io/pagure/issue/1888 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 537eafc..89a5b27 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -63,6 +63,13 @@ PAGURE_CI = None _log = logging.getLogger(__name__) +class NoneObject(object): + """ Custom None object not to be used anywhere but allowing to set + values to None. + """ + pass + + def set_redis(host, port, dbname): """ Set the redis connection with the specified information. """ global REDIS @@ -1622,9 +1629,26 @@ def new_tag(session, tag_name, tag_description, tag_color, project_id): def edit_issue(session, issue, ticketfolder, user, repo=None, - title=None, content=None, status=None, close_status=-1, - priority=-1, milestone=-1, private=None): + title=None, content=None, status=None, + close_status=NoneObject, priority=NoneObject, + milestone=NoneObject, private=None): ''' Edit the specified issue. + + :arg session: the session to use to connect to the database. + :arg issue: the pagure.lib.model.Issue object to edit. + :arg ticketfolder: the path to the git repo storing the meta-data of + the issues of this repo + :arg user: the username of the user editing the issue, + :kwarg repo: somehow this isn't used anywhere here... + :kwarg title: the new title of the issue if it's being changed + :kwarg content: the new content of the issue if it's being changed + :kwarg status: the new status of the issue if it's being changed + :kwarg close_status: the new close_status of the issue if it's being + changed + :kwarg priority: the new priority of the issue if it's being changed + :kwarg milestone: the new milestone of the issue if it's being changed + :kwarg private: the new private of the issue if it's being changed + ''' user_obj = get_user(session, user) if status and status != 'Open' and issue.parents: @@ -1649,12 +1673,12 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, issue.closed_at = datetime.datetime.utcnow() elif issue.close_status: issue.close_status = None - close_status = -1 + close_status = NoneObject edit.append('close_status') edit.append('status') messages.append( 'Issue status updated to: %s (was: %s)' % (status, old_status)) - if close_status != -1 and close_status != issue.close_status: + if close_status != NoneObject and close_status != issue.close_status: old_status = issue.close_status issue.close_status = close_status edit.append('close_status') @@ -1666,7 +1690,7 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, issue.closed_at = datetime.datetime.utcnow() edit.append('status') messages.append(msg) - if priority != -1: + if priority != NoneObject: priorities = issue.project.priorities try: priority = int(priority) @@ -1694,7 +1718,7 @@ def edit_issue(session, issue, ticketfolder, user, repo=None, if old_private: msg += ' (was: %s)' % old_private messages.append(msg) - if milestone != -1 and milestone != issue.milestone: + if milestone != NoneObject and milestone != issue.milestone: old_milestone = issue.milestone issue.milestone = milestone edit.append('milestone') diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 34c21e0..2fb1d90 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -274,7 +274,7 @@