diff --git a/data/database.py b/data/database.py index be727238f..1c84a9477 100644 --- a/data/database.py +++ b/data/database.py @@ -828,11 +828,6 @@ class LogEntry(BaseModel): (('repository', 'datetime', 'kind'), False), ) -class Messages(BaseModel): - content = TextField() - - # TODO: This should be non-nullable and indexed - uuid = CharField(default=uuid_generator, max_length=36, null=True) class RepositoryActionCount(BaseModel): repository = ForeignKeyField(Repository) @@ -1022,6 +1017,13 @@ class MediaType(BaseModel): name = CharField(index=True, unique=True) +class Messages(BaseModel): + content = TextField() + uuid = CharField(default=uuid_generator, max_length=36, index=True) + severity = CharField(default='info', index=True) + media_type = ForeignKeyField(MediaType) + + class LabelSourceType(BaseModel): """ LabelSourceType is an enumeration of the possible sources for a label. """ name = CharField(index=True, unique=True) diff --git a/data/migrations/versions/3e8cc74a1e7b_add_severity_and_media_type_to_global_.py b/data/migrations/versions/3e8cc74a1e7b_add_severity_and_media_type_to_global_.py new file mode 100644 index 000000000..b88ff3875 --- /dev/null +++ b/data/migrations/versions/3e8cc74a1e7b_add_severity_and_media_type_to_global_.py @@ -0,0 +1,54 @@ +"""Add severity and media_type to global messages + +Revision ID: 3e8cc74a1e7b +Revises: fc47c1ec019f +Create Date: 2017-01-17 16:22:28.584237 + +""" + +# revision identifiers, used by Alembic. +revision = '3e8cc74a1e7b' +down_revision = 'fc47c1ec019f' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +def upgrade(tables): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('messages', sa.Column('media_type_id', sa.Integer(), nullable=False, server_default='1')) + op.add_column('messages', sa.Column('severity', sa.String(length=255), nullable=False, server_default='info')) + op.alter_column('messages', 'uuid', + existing_type=mysql.VARCHAR(length=36), + server_default='', + nullable=False) + op.create_index('messages_media_type_id', 'messages', ['media_type_id'], unique=False) + op.create_index('messages_severity', 'messages', ['severity'], unique=False) + op.create_index('messages_uuid', 'messages', ['uuid'], unique=False) + op.create_foreign_key(op.f('fk_messages_media_type_id_mediatype'), 'messages', 'mediatype', ['media_type_id'], ['id']) + # ### end Alembic commands ### + + op.bulk_insert(tables.mediatype, + [ + {'name': 'text/markdown'}, + ]) + + +def downgrade(tables): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(op.f('fk_messages_media_type_id_mediatype'), 'messages', type_='foreignkey') + op.drop_index('messages_uuid', table_name='messages') + op.drop_index('messages_severity', table_name='messages') + op.drop_index('messages_media_type_id', table_name='messages') + op.alter_column('messages', 'uuid', + existing_type=mysql.VARCHAR(length=36), + nullable=True) + op.drop_column('messages', 'severity') + op.drop_column('messages', 'media_type_id') + # ### end Alembic commands ### + + op.execute(tables + .mediatype + .delete() + .where(tables. + mediatype.c.name == op.inline_literal('text/markdown'))) diff --git a/data/model/message.py b/data/model/message.py index 47b92a485..24df4d0ba 100644 --- a/data/model/message.py +++ b/data/model/message.py @@ -1,15 +1,20 @@ -from data.database import Messages +from data.database import Messages, MediaType def get_messages(): """Query the data base for messages and returns a container of database message objects""" - return Messages.select() + return Messages.select(Messages, MediaType).join(MediaType) def create(messages): """Insert messages into the database.""" inserted = [] for message in messages: - inserted.append(Messages.create(content=message['content'])) + severity = message['severity'] + media_type_name = message['media_type'] + media_type = MediaType.get(name=media_type_name) + + inserted.append(Messages.create(content=message['content'], media_type=media_type, + severity=severity)) return inserted def delete_message(uuids): diff --git a/endpoints/api/globalmessages.py b/endpoints/api/globalmessages.py index 6874a8d2c..b27683a17 100644 --- a/endpoints/api/globalmessages.py +++ b/endpoints/api/globalmessages.py @@ -35,6 +35,16 @@ class GlobalUserMessages(ApiResource): 'type': 'string', 'description': 'The actual message', }, + 'media_type': { + 'type': 'string', + 'description': 'The media type of the message', + 'enum': ['text/plain', 'text/markdown'], + }, + 'severity': { + 'type': 'string', + 'description': 'The severity of the message', + 'enum': ['info', 'warning', 'error'], + }, }, }, }, @@ -53,6 +63,16 @@ class GlobalUserMessages(ApiResource): 'type': 'string', 'description': 'The actual message', }, + 'media_type': { + 'type': 'string', + 'description': 'The media type of the message', + 'enum': ['text/plain', 'text/markdown'], + }, + 'severity': { + 'type': 'string', + 'description': 'The severity of the message', + 'enum': ['info', 'warning', 'error'], + }, }, }, }, @@ -104,4 +124,6 @@ def message_view(message): return { 'uuid': message.uuid, 'content': message.content, + 'severity': message.severity, + 'media_type': message.media_type.name, } diff --git a/initdb.py b/initdb.py index 3288b82a3..0e92aec80 100644 --- a/initdb.py +++ b/initdb.py @@ -395,6 +395,7 @@ def initialize_database(): MediaType.create(name='text/plain') MediaType.create(name='application/json') + MediaType.create(name='text/markdown') LabelSourceType.create(name='manifest') LabelSourceType.create(name='api', mutable=True) @@ -798,7 +799,11 @@ def populate_database(minimal=False, with_storage=False): 'trigger_id': trigger.uuid, 'config': json.loads(trigger.config), 'service': trigger.service.name}) - model.message.create([{'content': 'We love you, Quay customers!'}]) + model.message.create([{'content': 'We love you, Quay customers!', 'severity': 'info', + 'media_type': 'text/plain'}]) + + model.message.create([{'content': 'This is a **development** install of Quay', + 'severity': 'warning', 'media_type': 'text/markdown'}]) fake_queue = WorkQueue('fakequeue', tf) fake_queue.put(['canonical', 'job', 'name'], '{}') diff --git a/static/css/directives/ui/global-message-tab.css b/static/css/directives/ui/global-message-tab.css new file mode 100644 index 000000000..cc7841cf6 --- /dev/null +++ b/static/css/directives/ui/global-message-tab.css @@ -0,0 +1,29 @@ +.global-message-tab-element .message-content p { + display: inline-block; + margin: 0px; +} + +.global-message-tab-element .fa { + margin-right: 4px; +} + +.global-message-tab-element .ci-stop { + color: red; +} + +.global-message-tab-element .fa-exclamation-triangle { + color: #E4C212; +} + +.global-message-tab-element .fa-info-circle { + color: #124fd8; +} + +.global-message-tab-element label { + margin-top: 20px; + font-size: 16px; +} + +.global-message-tab-element label:first-child { + margin-top: 4px; +} diff --git a/static/css/directives/ui/quay-message-bar.css b/static/css/directives/ui/quay-message-bar.css new file mode 100644 index 000000000..ec660a0ff --- /dev/null +++ b/static/css/directives/ui/quay-message-bar.css @@ -0,0 +1,34 @@ +.quay-message-bar-element .markdown-view p { + margin: 0px; + display: inline-block; +} + +.quay-message-bar-element .quay-service-status-description.warning { + background: #FFFBF0; + color: black; +} + +.quay-message-bar-element .quay-service-status-description.warning:before { + font-family: FontAwesome; + content: "\f071"; + font-size: 22px; + color: #E4C212; + display: inline-block; + vertical-align: middle; + margin-right: 10px; +} + +.quay-message-bar-element .quay-service-status-description.error { + background: #FFF0F0; + color: black; +} + +.quay-message-bar-element .quay-service-status-description.error:before { + font-family: core-icons; + content: "\f109"; + font-size: 22px; + color: red; + display: inline-block; + vertical-align: middle; + margin-right: 10px; +} \ No newline at end of file diff --git a/static/directives/global-message-tab.html b/static/directives/global-message-tab.html index b4adb5a29..50c6face6 100644 --- a/static/directives/global-message-tab.html +++ b/static/directives/global-message-tab.html @@ -11,12 +11,26 @@
Message | +Severity |
- {{ message.content }} + | +