Adding in a new message data model and the corresponding methods to in the API.
This commit is contained in:
parent
7d8cc1fc34
commit
1e733ddffb
8 changed files with 60 additions and 4 deletions
|
@ -774,6 +774,8 @@ class LogEntry(BaseModel):
|
|||
(('repository', 'datetime', 'kind'), False),
|
||||
)
|
||||
|
||||
class Message(BaseModel):
|
||||
content = TextField()
|
||||
|
||||
class RepositoryActionCount(BaseModel):
|
||||
repository = ForeignKeyField(Repository)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
"""Adding in messages table
|
||||
|
||||
Revision ID: a3002f7638d5
|
||||
Revises: c9b91bee7554
|
||||
Create Date: 2016-10-07 11:14:15.054546
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'a3002f7638d5'
|
||||
down_revision = 'c9b91bee7554'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
def upgrade(tables):
|
||||
op.create_table('messages',
|
||||
sa.Column("id", sa.INTEGER, primary_key=True),
|
||||
sa.Column("content", sa.UnicodeText, nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_messages'))
|
||||
)
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
op.drop_table('messages')
|
|
@ -124,6 +124,7 @@ from data.model import (
|
|||
image,
|
||||
label,
|
||||
log,
|
||||
message,
|
||||
modelutil,
|
||||
notification,
|
||||
oauth,
|
||||
|
|
12
data/model/message.py
Normal file
12
data/model/message.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from data.database import Message
|
||||
|
||||
|
||||
def get_messages():
|
||||
messages = []
|
||||
for message in Message.select():
|
||||
messages.append({'id': message.id, 'content': message.content})
|
||||
return messages
|
||||
|
||||
def create(messages):
|
||||
for message in messages:
|
||||
Message.create(content=message['content'])
|
|
@ -820,7 +820,7 @@ class SuperUserServiceKeyApproval(ApiResource):
|
|||
|
||||
abort(403)
|
||||
|
||||
@resource('/v1/superuser/messages')
|
||||
@resource('/v1/messages')
|
||||
@show_if(features.SUPER_USERS)
|
||||
class Messages(ApiResource):
|
||||
""" Resource for getting a list of super user messages """
|
||||
|
@ -838,6 +838,10 @@ class Messages(ApiResource):
|
|||
'type': 'object',
|
||||
'description': 'A single message',
|
||||
'properties': {
|
||||
'id':{
|
||||
'type': 'integer',
|
||||
'description': 'The message id',
|
||||
},
|
||||
'content': {
|
||||
'type': 'string',
|
||||
'description': 'The actual message',
|
||||
|
@ -852,12 +856,16 @@ class Messages(ApiResource):
|
|||
@nickname('getMessages')
|
||||
def get(self):
|
||||
""" Return a super users messages """
|
||||
messages = []
|
||||
messages = model.message.get_messages()
|
||||
return {
|
||||
'messages': messages,
|
||||
}
|
||||
|
||||
@require_scope(scopes.SUPERUSER)
|
||||
@verify_not_prod
|
||||
@nickname('createMessages')
|
||||
def post(self):
|
||||
""" Create a message """
|
||||
pass
|
||||
body = request.get_json()
|
||||
print body
|
||||
model.message.create(body['messages'])
|
||||
|
|
|
@ -776,6 +776,8 @@ 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!'}])
|
||||
|
||||
fake_queue = WorkQueue('fakequeue', tf)
|
||||
fake_queue.put(['canonical', 'job', 'name'], '{}')
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ angular.module('quay').directive('quayMessageBar', function () {
|
|||
scope: {},
|
||||
controller: function ($scope, $element, ApiService) {
|
||||
$scope.messages = [];
|
||||
ApiService.getMessages().then(function(data){ $scope.messages = data['messages'] || []; });
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
@ -4283,7 +4283,11 @@ class TestSuperUserManagement(ApiTestCase):
|
|||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Create a message
|
||||
self.postJsonResponse(Messages)
|
||||
self.postJsonResponse(Messages, data=dict(messages=[{"content": "new message"}]))
|
||||
|
||||
json = self.getJsonResponse(Messages)
|
||||
|
||||
self.assertEquals(len(json['messages']), 2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Reference in a new issue