diff --git a/alembic/versions/38581a8fbae2_add_custom_field_data.py b/alembic/versions/38581a8fbae2_add_custom_field_data.py new file mode 100644 index 0000000..238b487 --- /dev/null +++ b/alembic/versions/38581a8fbae2_add_custom_field_data.py @@ -0,0 +1,22 @@ +"""Add custom field data + +Revision ID: 38581a8fbae2 +Revises: 208b0cd232ab +Create Date: 2017-01-16 13:03:36.683188 + +""" + +# revision identifiers, used by Alembic. +revision = '38581a8fbae2' +down_revision = '208b0cd232ab' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('issue_keys', sa.Column('key_data', sa.Text())) + + +def downgrade(): + op.drop_column('issue_keys', 'key_data') diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index d28b2af..358142d 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3460,9 +3460,9 @@ def save_report(session, repo, name, url, username): session.add(repo) -def set_custom_key_fields(session, project, fields, types): +def set_custom_key_fields(session, project, fields, types, data): """ Set or update the custom key fields of a project with the values - provided. + provided. "data" is currently only used for lists """ current_keys = {} @@ -3470,14 +3470,19 @@ def set_custom_key_fields(session, project, fields, types): current_keys[key.name] = key for idx, key in enumerate(fields): + if types[idx] != "list": + # Only Lists use data, strip it otherwise + data[idx] = "" if key in current_keys: issuekey = current_keys[key] issuekey.key_type = types[idx] + issuekey.key_data = data[idx] else: issuekey = model.IssueKeys( project_id=project.id, name=key, key_type=types[idx], + key_data=data[idx] ) session.add(issuekey) diff --git a/pagure/lib/model.py b/pagure/lib/model.py index f982f9e..79516d7 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -820,6 +820,7 @@ class Issue(BASE): name=field.key.name, key_type=field.key.key_type, value=field.value, + key_data=field.key.key_data ) for field in self.other_fields ] @@ -988,6 +989,7 @@ class IssueKeys(BASE): nullable=False) name = sa.Column(sa.Text(), nullable=False) key_type = sa.Column(sa.String(255), nullable=False) + key_data = sa.Column(sa.Text()) __table_args__ = (sa.UniqueConstraint('project_id', 'name'),) diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index a2ba336..7864e24 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -367,7 +367,7 @@

- {% if field.name in knowns_keys %} + {% if field.name in knowns_keys %} {% if field.key_type == 'link' %} {% for link in knowns_keys[field.name].value.split(',') %} {{ link }} @@ -383,15 +383,25 @@ {% if authenticated and g.repo_admin %}

- + {% if field.key_type == 'list' %} + + {% else %} + + {% endif %}
{% endif %} {% endfor %} diff --git a/pagure/templates/settings.html b/pagure/templates/settings.html index 5955328..90933c2 100644 --- a/pagure/templates/settings.html +++ b/pagure/templates/settings.html @@ -684,7 +684,9 @@

- Set some custom fields for your issues. + Set some custom fields for your issues. Field Values are currently + only used for Lists, and it accepts a comma separated list of items + for the drop down list.

-
+
Fields
+
+ Field Type +
+
+ Field Values (Lists only) +
{% for field in repo.issue_keys or [dict(key_type="", name="")] | sort %}
-
+
-
- + endif %}>Text + endif %}>Boolean + endif %}>Link +
+
+ +
{% endfor %}
@@ -837,7 +852,7 @@

Quick replies will be offered in a new comment form on Issue or - Pull Request page. This allows you to reply to common probles with a + Pull Request page. This allows you to reply to common problems with a click of a button.

The reply can use the same Markdown formatting as regular comments. The list you will choose the reply from will only show the diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 6997e05..aca1db1 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -2289,10 +2289,13 @@ def update_custom_keys(repo, username=None, namespace=None): w.strip() for w in flask.request.form.getlist('custom_keys_type') if w.strip() ] + custom_keys_data = [ + w.strip() for w in flask.request.form.getlist('custom_keys_data') + ] try: msg = pagure.lib.set_custom_key_fields( - SESSION, repo, custom_keys, custom_keys_type) + SESSION, repo, custom_keys, custom_keys_type, custom_keys_data) SESSION.commit() flask.flash(msg) except SQLAlchemyError as err: # pragma: no cover diff --git a/tests/test_pagure_flask_api_issue.py b/tests/test_pagure_flask_api_issue.py index 8ab292e..f33c8ea 100644 --- a/tests/test_pagure_flask_api_issue.py +++ b/tests/test_pagure_flask_api_issue.py @@ -1900,10 +1900,22 @@ class PagureFlaskApiIssuetests(tests.Modeltests): repo = pagure.lib.get_project(self.session, 'test') msg = pagure.lib.set_custom_key_fields( self.session, repo, - ['bugzilla', 'upstream'], ['link', 'boolean']) + ['bugzilla', 'upstream', 'reviewstatus'], + ['link', 'boolean', 'list'], + ['unused data for non-list type', '', 'ack, nack, needs review']) self.session.commit() self.assertEqual(msg, 'List of custom fields updated') + # Check the project custom fields were correctly set + for key in repo.issue_keys: + # Check that the bugzilla field correctly had its data removed + if key.name == "bugzilla" and key.key_data != "": + assert False + # Check that the reviewstatus list field still has its list + if (key.name == "reviewstatus" and + key.key_data != 'ack, nack, needs review'): + assert False + # No value specified while we try to create the field output = self.app.post( '/api/0/test/issue/1/custom/bugzilla', headers=headers)