Skip to content

Commit

Permalink
big ugly initial commit
Browse files Browse the repository at this point in the history
rref #5367
rref #5366
ref #66
ref #65
  • Loading branch information
evrenesat committed Jun 21, 2016
1 parent b81ef22 commit 287b722
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 68 deletions.
2 changes: 1 addition & 1 deletion tests/test_callactivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from zengine.lib.exceptions import HTTPError
from zengine.lib.test_utils import BaseTestCase
from zengine.models import User
from zengine.notifications.model import NotificationMessage
from zengine.messaging.model import Message
from zengine.signals import lane_user_change


Expand Down
2 changes: 1 addition & 1 deletion tests/test_jump_to_wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from zengine.lib.exceptions import HTTPError
from zengine.lib.test_utils import BaseTestCase
from zengine.models import User
from zengine.notifications.model import NotificationMessage
from zengine.messaging.model import Message
from zengine.signals import lane_user_change


Expand Down
8 changes: 4 additions & 4 deletions tests/test_multi_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from zengine.lib.exceptions import HTTPError
from zengine.lib.test_utils import BaseTestCase
from zengine.models import User
from zengine.notifications.model import NotificationMessage
from zengine.messaging.model import Message
from zengine.signals import lane_user_change


class TestCase(BaseTestCase):
def test_multi_user_mono(self):
test_user = User.objects.get(username='test_user')
self.prepare_client('/multi_user2/', user=test_user)
with BlockSave(NotificationMessage):
with BlockSave(Message):
resp = self.client.post()
assert resp.json['msgbox']['title'] == settings.MESSAGES['lane_change_message_title']
token, user = self.get_user_token('test_user2')
Expand All @@ -37,12 +37,12 @@ def mock(sender, *args, **kwargs):
self.old_lane = kwargs['old_lane']
self.owner = list(kwargs['possible_owners'])[0]

NotificationMessage.objects.delete()
Message.objects.delete()

lane_user_change.connect(mock)
wf_name = '/multi_user/'
self.prepare_client(wf_name, username='test_user')
with BlockSave(NotificationMessage):
with BlockSave(Message):
self.client.post()
token, user = self.get_user_token('test_user')
assert self.owner.username == 'test_user'
Expand Down
2 changes: 1 addition & 1 deletion zengine/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from zengine.lib.cache import WFCache
from zengine.lib.camunda_parser import CamundaBMPNParser
from zengine.log import log
from zengine.notifications import Notify
from zengine.messaging import Notify

DEFAULT_LANE_CHANGE_MSG = {
'title': settings.MESSAGES['lane_change_message_title'],
Expand Down
4 changes: 2 additions & 2 deletions zengine/lib/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from zengine.wf_daemon import Worker

from zengine.models import User
from zengine.notifications.model import NotificationMessage
from zengine.messaging.model import Message


class ResponseWrapper(object):
Expand Down Expand Up @@ -224,6 +224,6 @@ def _do_login(self):
@staticmethod
def get_user_token(username):
user = User.objects.get(username=username)
msg = NotificationMessage.objects.filter(receiver=user)[0]
msg = Message.objects.filter(receiver=user)[0]
token = msg.url.split('/')[-1]
return token, user
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import time
import six
from zengine.lib.cache import Cache, KeepAlive
from .model import NotificationMessage
from .model import Message

class Notify(Cache, ClientQueue):
"""
Expand Down Expand Up @@ -56,10 +56,10 @@ def _delayed_send(self, offline_messages):
def set_message(self, title, msg, typ, url=None, sender=None):
message = {'title': title, 'body': msg, 'type': typ, 'url': url, 'id': uuid4().hex}
if sender and isinstance(sender, six.string_types):
sender = NotificationMessage.sender.objects.get(sender)
receiver = NotificationMessage.receiver.objects.get(self.user_id)
NotificationMessage(typ=typ, msg_title=title, body=msg, url=url,
sender=sender, receiver=receiver).save()
sender = Message.sender.objects.get(sender)
receiver = Message.receiver.objects.get(self.user_id)
Message(typ=typ, msg_title=title, body=msg, url=url,
sender=sender, receiver=receiver).save()
if KeepAlive(user_id=self.user_id).is_alive():
client_message = {'cmd': 'notification', 'notifications': [message, ]}
self.send_to_queue(client_message)
Expand Down
150 changes: 150 additions & 0 deletions zengine/messaging/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# -*- coding: utf-8 -*-
"""
"""

# Copyright (C) 2015 ZetaOps Inc.
#
# This file is licensed under the GNU General Public License v3
# (GPLv3). See LICENSE.txt for details.
import pika

from pyoko import Model, field, ListNode
from pyoko.conf import settings
from pyoko.lib.utils import get_object_from_path
from zengine.client_queue import BLOCKING_MQ_PARAMS

UserModel = get_object_from_path(settings.USER_MODEL)

MSG_TYPES = (
(1, "Info"),
(11, "Error"),
(111, "Success"),
(2, "Direct Message"),
(3, "Broadcast Message")
(4, "Channel Message")
)

CHANNEL_TYPES = (
(10, "System Broadcast"),
(10, "User Broadcast"),
(15, "Direct"),
(20, "Chat"),
)


MESSAGE_STATUS = (
(1, "Created"),
(11, "Transmitted"),
(22, "Seen"),
(33, "Read"),
(44, "Archived"),

)
ATTACHMENT_TYPES = (
(1, "Document"),
(11, "Spreadsheet"),
(22, "Image"),
(33, "PDF"),

)


def get_mq_connection():
connection = pika.BlockingConnection(BLOCKING_MQ_PARAMS)
channel = connection.channel()
return connection, channel

class Channel(Model):
name = field.String("Name")
code_name = field.String("Internal name")
description = field.String("Description")
owner = UserModel(reverse_name='created_channels')
typ = field.Integer("Type", choices=CHANNEL_TYPES)

class Managers(ListNode):
user = UserModel(reverse_name='managed_channels')


def _connect_mq(self):
self.connection, self.channel = get_mq_connection()
return self.channel

def create_exchange(self):
"""
This method creates MQ exch
which actually needed to be defined only once.
"""
channel = self._connect_mq()
channel.exchange_declare(exchange=self.code_name)

class Subscription(Model):
"""
Permission model
"""

channel = Channel()
user = UserModel(reverse_name='channels')
is_muted = field.Boolean("Mute the channel")
inform_me = field.Boolean("Inform when I'm mentioned")
can_leave = field.Boolean("Membership is not obligatory", default=True)
# status = field.Integer("Status", choices=SUBSCRIPTION_STATUS)

def _connect_mq(self):
self.connection, self.channel = get_mq_connection()
return self.channel

def create_exchange(self):
"""
This method creates user's private exchange
which actually needed to be defined only once.
"""
channel = self._connect_mq()
channel.exchange_declare(exchange=self.user.key)




def __unicode__(self):
return "%s in %s" % (self.user, self.channel.name)

class Message(Model):
"""
Permission model
"""

typ = field.Integer("Type", choices=MSG_TYPES)
status = field.Integer("Status", choices=MESSAGE_STATUS)
msg_title = field.String("Title")
body = field.String("Body")
url = field.String("URL")
channel = Channel()
sender = UserModel(reverse_name='sent_messages')
receiver = UserModel(reverse_name='received_messages')

def __unicode__(self):
content = self.msg_title or self.body
return "%s%s" % (content[:30], '...' if len(content) > 30 else '')


class Attachment(Model):
"""
A model to store message attachments
"""
file = field.File("File", random_name=True, required=False)
typ = field.Integer("Type", choices=ATTACHMENT_TYPES)
name = field.String("Name")
description = field.String("Description")
channel = Channel()
message = Message()

def __unicode__(self):
return self.name


class Favorite(Model):
"""
A model to store users favorited messages
"""
channel = Channel()
user = UserModel()
message = Message()
2 changes: 1 addition & 1 deletion zengine/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# This file is licensed under the GNU General Public License v3
# (GPLv3). See LICENSE.txt for details.
from .auth import *
from ..notifications.model import *
from ..messaging.model import *
2 changes: 1 addition & 1 deletion zengine/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_role(self, role_id):
return self.role_set.node_dict[role_id]

def send_message(self, title, message, sender=None):
from zengine.notifications import Notify
from zengine.messaging import Notify
Notify(self.key).set_message(title, message, typ=Notify.Message, sender=sender)


Expand Down
49 changes: 0 additions & 49 deletions zengine/notifications/model.py

This file was deleted.

2 changes: 1 addition & 1 deletion zengine/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def send_message_for_lane_change(sender, *args, **kwargs):
from zengine.lib.catalog_data import gettxt as _
from pyoko.lib.utils import get_object_from_path
UserModel = get_object_from_path(settings.USER_MODEL)
from zengine.notifications import Notify
from zengine.messaging import Notify
current = kwargs['current']
old_lane = kwargs['old_lane']
owners = kwargs['possible_owners']
Expand Down
3 changes: 2 additions & 1 deletion zengine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@

#: View URL list for non-workflow views.
#:
#: ('falcon URI template', 'python path to view method/class'),
#: ('URI template', 'python path to view method/class'),
VIEW_URLS = {
'dashboard': 'zengine.views.menu.Menu',
'ping': 'zengine.views.dev_utils.Ping',

}

if DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion zengine/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pyoko import fields
from zengine.forms.json_form import JsonForm
from zengine.lib.cache import UserSessionID, KeepAlive
from zengine.notifications import Notify
from zengine.messaging import Notify
from zengine.views.base import SimpleView


Expand Down

0 comments on commit 287b722

Please sign in to comment.