Add docstrings to globalmessages data interface
This commit is contained in:
parent
4ca6c37e54
commit
0d239e08c2
3 changed files with 34 additions and 8 deletions
|
@ -102,7 +102,10 @@ class GlobalUserMessages(ApiResource):
|
|||
abort(404)
|
||||
|
||||
if SuperUserPermission().can():
|
||||
model.create_message(request.get_json()['message'])
|
||||
message_req = request.get_json()['message']
|
||||
message = model.create_message(message_req['severity'], message_req['media_type'], message_req['content'])
|
||||
if message is None:
|
||||
abort(400)
|
||||
return make_response('', 201)
|
||||
|
||||
abort(403)
|
||||
|
|
|
@ -23,17 +23,32 @@ class GlobalMessage(
|
|||
|
||||
@add_metaclass(ABCMeta)
|
||||
class GlobalMessageDataInterface(object):
|
||||
"""
|
||||
Data interface for globalmessages API
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_all_messages(self):
|
||||
pass
|
||||
"""
|
||||
|
||||
Returns:
|
||||
list(GlobalMessage)
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def create_message(self):
|
||||
pass
|
||||
def create_message(self, severity, media_type_name, content):
|
||||
"""
|
||||
|
||||
Returns:
|
||||
GlobalMessage or None
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def delete_message(self):
|
||||
pass
|
||||
def delete_message(self, uuid):
|
||||
"""
|
||||
|
||||
Returns:
|
||||
void
|
||||
"""
|
||||
|
||||
|
|
@ -8,13 +8,21 @@ class GlobalMessagePreOCI(GlobalMessageDataInterface):
|
|||
messages = model.message.get_messages()
|
||||
return [self._message(m) for m in messages]
|
||||
|
||||
def create_message(self, content):
|
||||
model.message.create([content])
|
||||
def create_message(self, severity, media_type_name, content):
|
||||
message = {
|
||||
'severity': severity,
|
||||
'media_type': media_type_name,
|
||||
'content': content
|
||||
}
|
||||
messages = model.message.create([message])
|
||||
return self._message(messages[0])
|
||||
|
||||
def delete_message(self, uuid):
|
||||
model.message.delete_message([uuid])
|
||||
|
||||
def _message(self, message_obj):
|
||||
if message_obj is None:
|
||||
return None
|
||||
return GlobalMessage(
|
||||
uuid=message_obj.uuid,
|
||||
content=message_obj.content,
|
||||
|
|
Reference in a new issue