fix api 001

This commit is contained in:
odex 2024-07-11 12:13:55 +03:00
parent 964b74ebdc
commit a00ba03604
6 changed files with 40 additions and 23 deletions

View File

@ -18,7 +18,7 @@ _logger = logging.getLogger(__name__)
class NotificationController(http.Controller):
@http.route(['/rest_api/v2/notifications/','/rest_api/v2/notifications/page/<int:page>'], type='http', auth='none', csrf=False, methods=['GET'], website=True)
@http.route(['/rest_api/v2/notifications/', '/rest_api/v2/notifications/page/<int:page>'], type='http', auth='none', csrf=False, methods=['GET'], website=True)
def index(self, page=1, **kw):
"""
fetch notifications
@ -41,7 +41,7 @@ class NotificationController(http.Controller):
# partner_ids
# search([('partner_ids','in',user.partner_id.id)])
#
domain = [("sent", "=", True),'&',("is_system", "=", True),('partner_ids','in',user.partner_id.id)]
domain = [("sent", "=", True), '&', ("is_system", "=", True), ('partner_ids', 'in', user.partner_id.id)]
ids = user.env['firebase.notification'].search(domain, order="create_date desc")
notifications = []
pager = request.website.pager(
@ -54,11 +54,10 @@ class NotificationController(http.Controller):
records = user.env['firebase.notification'].search(domain).search(
domain, limit=20, offset=pager['offset'])
for res in records:
notifications.append({
'notification':{"title":res.title,
"body": res.body,},
"body": res.body, },
"id":res.id,
"title":res.title,
"body": res.body,
@ -66,7 +65,9 @@ class NotificationController(http.Controller):
"sent": res.sent,
"viewed": res.viewed,
"meta": res.meta,
"data": res.iso_date,
"write_date": str(res.write_date),
"iso_date": str(res.iso_date),
"create_date": str(res.create_date),
"uuid": res.uid,
})
prev = pager['page_previous']['url']
@ -126,10 +127,11 @@ class NotificationController(http.Controller):
"sent": res.sent,
"viewed": res.viewed,
"meta": res.meta,
"data": str(res.create_date),
"write_date": str(res.write_date),
"iso_date": str(res.iso_date),
"create_date": str(res.create_date),
"uuid": res.uid,
})
values = {
'links': None,
@ -202,7 +204,7 @@ class NotificationController(http.Controller):
# security check done successfully
#
domain = [("sent", "=", True),'&',("is_system", "=", True),('partner_ids','in',user.partner_id.id)]
domain = [("sent", "=", True), '&', ("is_system", "=", True), ('partner_ids', 'in', user.partner_id.id)]
ids = user.env['firebase.notification'].search(domain).unlink()
values = {
@ -212,4 +214,4 @@ class NotificationController(http.Controller):
},
"count": None,
}
return http_helper.response(message="Delete successfully", data=values)
return http_helper.response(message="Delete successfully", data=values)

View File

@ -232,6 +232,7 @@ class LeaveController(http.Controller):
'res_id': holidays.id,
})
if holidays:
# holidays.confirm()
holidays.number_of_days_temp = holidays._get_number_of_days(body['start_date'], body['end_date'],
employee)
data = self.get_return_data(holidays)

View File

@ -56,7 +56,7 @@ class FirebaseNotification(models.Model):
#@api.multi
def send(self, **kwargs):
print("**********************************************")
# print("**********************************************")
if kwargs is None:
kwargs = {}
for notif in self:

View File

@ -95,7 +95,7 @@ class HrHolidays(models.Model):
})
}
_logger.warning(type(data))
_logger.warning(data)
# _logger.warning(data)
if users:
partner = users.mapped('partner_id')
for part in partner:

View File

@ -22,8 +22,6 @@ class Partner(models.Model):
"sent": True,
}
notification = self.env['firebase.notification'].sudo().create(notification_data)
print(notification)
print(notification_data)
if all_device:
for reg in self.firebase_registration_ids:
reg.with_context(lang=self.lang).send_message(

View File

@ -16,13 +16,8 @@ NODE = "workflow.mobile.node"
# filtered_domain
# mapped
class RestApi(Controller):
@route(
["/rest_api/workflows/", "/rest_api/workflow/<mobile_id>", "/workflows/", "/workflow/<mobile_id>"],
type="http",
auth="none",
method=["GET"],
csrf=False,
)
@route(["/rest_api/workflows/", "/rest_api/workflow/<mobile_id>", "/workflows/", "/workflow/<mobile_id>"], type="http", auth="none", method=["GET"], csrf=False,)
def get_all_workflow(self, mobile_id=None, **kw):
try:
http_method, body, headers, token = http_helper.parse_request()
@ -85,7 +80,7 @@ class RestApi(Controller):
@route([
"/rest_api/workflow/record_btns/<mobile_id>/<active_id>",
"/workflow/record_btns/<mobile_id>/<active_id>",],
"/workflow/record_btns/<mobile_id>/<active_id>", ],
type="http",
auth="none",
method=["GET"],
@ -206,7 +201,7 @@ class RestApi(Controller):
@route(
[
"/rest_api/workflow/execute_btn/<active_id>/<btn_id>",
"/workflow/execute_btn/<active_id>/<btn_id>",],
"/workflow/execute_btn/<active_id>/<btn_id>", ],
type="http",
auth="none",
method=["GET"],
@ -263,7 +258,11 @@ class RestApi(Controller):
[],
)
)
users = btn_new.mapped("group_ids").mapped("users") or None
group_ids = btn_new.mapped("group_ids")
users = group_ids.mapped("users") or None
print("***************************************users", users)
users_list = self.access_users(group_ids, btn)
print("***************************************users_list", users_list)
if reject_reason:
obj.write({"reason": reject_reason})
obj.firebase_notification(users)
@ -274,3 +273,20 @@ class RestApi(Controller):
return http_helper.response(code=400, message=str(error), success=False)
except Exception as e:
return http_helper.response_500(str(e))
def has_access(self, user_id, record, mode='read'):
try:
access = record.with_user(user_id).check_access_rule(mode)
print("-----------------------",access)
return True
except:
return False
def access_users(self, groups, record):
users = []
print(groups,record)
for group in groups:
for user in group.users:
if self.has_access(user_id=user.id, record=record, mode='read'):
users.append(user)
return users