diff --git a/alembic/versions/3ffec872dfdf_add_a_description_to_api_token.py b/alembic/versions/3ffec872dfdf_add_a_description_to_api_token.py new file mode 100644 index 0000000..2fddac7 --- /dev/null +++ b/alembic/versions/3ffec872dfdf_add_a_description_to_api_token.py @@ -0,0 +1,29 @@ +"""Add a description to api token + +Revision ID: 3ffec872dfdf +Revises: 770149d96e24 +Create Date: 2017-03-23 11:30:34.827399 + +""" + +# revision identifiers, used by Alembic. +revision = '3ffec872dfdf' +down_revision = '770149d96e24' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ''' Add the column description to the table tokens + ''' + op.add_column( + 'tokens', + sa.Column('description', sa.Text, nullable=True) + ) + + +def downgrade(): + ''' Drop the column description from the table tokens. + ''' + op.drop_column('tokens', 'description') diff --git a/pagure/forms.py b/pagure/forms.py index d6edf53..9e91727 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -288,6 +288,9 @@ class StatusForm(PagureForm): class NewTokenForm(PagureForm): ''' Form to add/change the status of an issue. ''' + description = wtforms.TextField( + 'description', [wtforms.validators.Optional()] + ) acls = wtforms.SelectMultipleField( 'ACLs', [wtforms.validators.Required()], diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 43ad605..4138ea5 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3272,7 +3272,7 @@ def get_acls(session, restrict=None): return query.all() -def add_token_to_user(session, project, acls, username): +def add_token_to_user(session, project, acls, username, description=None): """ Create a new token for the specified user on the specified project with the given ACLs. """ @@ -3288,6 +3288,7 @@ def add_token_to_user(session, project, acls, username): id=pagure.lib.login.id_generator(64), user_id=user.id, project_id=project.id if project else None, + description=description, expiration=datetime.datetime.utcnow() + datetime.timedelta(days=60) ) session.add(token) diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 3651f0e..6657d56 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -2171,6 +2171,7 @@ class Token(BASE): ), nullable=True, index=True) + description = sa.Column(sa.Text(), nullable=True) expiration = sa.Column( sa.DateTime, nullable=False, default=datetime.datetime.utcnow) created = sa.Column( diff --git a/pagure/templates/add_token.html b/pagure/templates/add_token.html index a9f6b53..8d6b0d7 100644 --- a/pagure/templates/add_token.html +++ b/pagure/templates/add_token.html @@ -3,7 +3,7 @@ {% else %} {% extends "master.html" %} {% endif %} -{% from "_formhelper.html" import render_field_in_row %} +{% from "_formhelper.html" import render_bootstrap_field %} {% set tag = "home" %} {% block title %}Create token{% endblock %} @@ -33,16 +33,18 @@ {% else %}