Commit bcf13ede authored by John Red Medrano's avatar John Red Medrano

add new key cms_privilege on current user, install pusher for realtime, added...

add new key cms_privilege on current user, install pusher for realtime, added new function rms_websocket at utils
parent 5aa699eb
...@@ -24,15 +24,17 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer): ...@@ -24,15 +24,17 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer):
applications = serializers.SerializerMethodField() applications = serializers.SerializerMethodField()
department = serializers.SerializerMethodField() department = serializers.SerializerMethodField()
company = serializers.SerializerMethodField() company = serializers.SerializerMethodField()
create_form = serializers.SerializerMethodField() cms_privilege = serializers.SerializerMethodField()
create_template = serializers.SerializerMethodField() # create_form = serializers.SerializerMethodField()
# create_template = serializers.SerializerMethodField()
class Meta: class Meta:
model = User model = User
fields = ( fields = (
'id', 'id',
'create_form', "cms_privilege",
'create_template', # 'create_form',
# 'create_template',
'code', 'name', 'code', 'name',
'username', 'contact_no', 'username', 'contact_no',
'image', 'company', 'image', 'company',
...@@ -60,27 +62,18 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer): ...@@ -60,27 +62,18 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer):
} }
return data return data
def get_create_form(self, user): def get_cms_privilege(self, user):
check_user = AllowedCompany.objects.filter(
Q(id_number=user.code) & test = AllowedCompany.objects.extra(
Q(create_change_request=True) select={
).count() 'create_form': "create_change_request=True",
if check_user <= 0: 'create_template': "create_change_request_template=True",
permission = False }
else: ).filter(id_number=user.code).values('create_form', "create_template")
permission = True # print(test.count())
return permission
if test.count() >= 1:
def get_create_template(self, user): return {**test.values("create_form","create_template")[0]}
check_user = AllowedCompany.objects.filter(
Q(id_number=user.code) &
Q(create_change_request_template=True)
).count()
if check_user <= 0:
permission = False
else:
permission = True
return permission
def get_image(self, user): def get_image(self, user):
request = self.context.get('request') request = self.context.get('request')
......
...@@ -13,8 +13,38 @@ from rest_framework import status ...@@ -13,8 +13,38 @@ from rest_framework import status
from rest_framework import serializers from rest_framework import serializers
import copy import copy
import json import json
import pusher
import os
import configparser
config = configparser.ConfigParser()
config_file = os.path.join('./', 'env.ini')
config.read(config_file)
REALTIMESERVER_IP = settings.REALTIMESERVER_IP REALTIMESERVER_IP = settings.REALTIMESERVER_IP
app_id = config['SETTINGS']['app_id'],
key = config['SETTINGS']['key']
secret = config['SETTINGS']['secret']
cluster = config['SETTINGS']['cluster']
ssl = True if config['SETTINGS']['ssl'] == 1 else False
cms_notification = config['SETTINGS']['cms_notification']
def rms_websocket(my_channel, my_event, msg):
pusher_client = pusher.Pusher(
app_id=app_id,
key=key,
secret=secret,
cluster=cluster,
ssl=ssl
)
pusher_client.trigger(
my_channel, my_event, msg
# 'my-channel', 'my-event', {'message': 'hello world'}
)
def error_message(code, message, status, status_code): def error_message(code, message, status, status_code):
...@@ -207,13 +237,25 @@ def notification_create(form_code, message, account_no, ...@@ -207,13 +237,25 @@ def notification_create(form_code, message, account_no,
) )
ROOM = account_no ROOM = account_no
SENDER = sender_account_no # SENDER = sender_account_no
send_broadcast_message( # send_broadcast_message(
ROOM, # ROOM,
SENDER, # SENDER,
'NEW NOTIFICATIONS' # 'NEW NOTIFICATIONS'
) # )
if ssl != 1:
send_broadcast_message(
ROOM,
SENDER,
'NEW NOTIFICATIONS'
)
else:
rms_websocket(
ROOM,
'NEW NOTIFICATIONS'
)
return True return True
......
...@@ -5,7 +5,7 @@ DATABASE_ENGINE = django.db.backends.mysql ...@@ -5,7 +5,7 @@ DATABASE_ENGINE = django.db.backends.mysql
DATABASE_NAME = rms_db DATABASE_NAME = rms_db
DATABASE_USER = red_database DATABASE_USER = red_database
DATABASE_PASSWORD = password123 DATABASE_PASSWORD = password123
DATABASE_HOST = 10.0.75.1 DATABASE_HOST = localhost
DATABASE_PORT = 3306 DATABASE_PORT = 3306
SESSION_TIMEOUT = 30 SESSION_TIMEOUT = 30
FRONT_END_URL = http://devweb.rmsv2.oneberrysystem.com FRONT_END_URL = http://devweb.rmsv2.oneberrysystem.com
...@@ -14,6 +14,13 @@ USER_DEFAULT_PASSWORD = password ...@@ -14,6 +14,13 @@ USER_DEFAULT_PASSWORD = password
CATCH_EMAIL = gladys@tirsolutions.com CATCH_EMAIL = gladys@tirsolutions.com
CR_LINK = http://localhost:8000/cms/change-request/form/view CR_LINK = http://localhost:8000/cms/change-request/form/view
REALTIMESERVER_IP = 127.0.0.1:8000 REALTIMESERVER_IP = 127.0.0.1:8000
DEBUG = False
app_id = 957253
key = c29a7f6579108991e79e
secret = b3df5d55196b5fbd3eff
cluster = api
cms_notification = cms_notification
[NOTIFICATION_EMAIL] [NOTIFICATION_EMAIL]
......
...@@ -15,7 +15,7 @@ channels-redis==2.4.0 ...@@ -15,7 +15,7 @@ channels-redis==2.4.0
chardet==3.0.4 chardet==3.0.4
colorama==0.4.1 colorama==0.4.1
constantly==15.1.0 constantly==15.1.0
cryptography==2.7 cryptography==2.8
cssselect2==0.2.2 cssselect2==0.2.2
daphne==2.3.0 daphne==2.3.0
defusedxml==0.6.0 defusedxml==0.6.0
...@@ -40,15 +40,20 @@ Markdown==3.1 ...@@ -40,15 +40,20 @@ Markdown==3.1
mccabe==0.6.1 mccabe==0.6.1
msgpack==0.6.1 msgpack==0.6.1
mysqlclient==1.4.2.post1 mysqlclient==1.4.2.post1
ndg-httpsclient==0.5.1
numpy==1.17.3 numpy==1.17.3
openpyxl==3.0.0 openpyxl==3.0.0
pandas==0.25.3 pandas==0.25.3
pep8==1.7.1 pep8==1.7.1
Pillow==6.0.0 Pillow==6.0.0
pusher==2.1.4
pyasn1==0.4.8
pycodestyle==2.5.0 pycodestyle==2.5.0
pycparser==2.19 pycparser==2.19
PyHamcrest==1.9.0 PyHamcrest==1.9.0
pylint==2.3.1 pylint==2.3.1
PyNaCl==1.3.0
pyOpenSSL==19.1.0
PyPDF2==1.26.0 PyPDF2==1.26.0
Pyphen==0.9.5 Pyphen==0.9.5
python-dateutil==2.8.1 python-dateutil==2.8.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment