diff options
-rw-r--r-- | taskapp/events/request.py | 21 | ||||
-rw-r--r-- | taskapp/utilities/notification.py | 2 | ||||
-rw-r--r-- | taskapp/views/user.py | 2 | ||||
-rw-r--r-- | templates/index.html | 4 |
4 files changed, 25 insertions, 4 deletions
diff --git a/taskapp/events/request.py b/taskapp/events/request.py index 2ad066b..747626a 100644 --- a/taskapp/events/request.py +++ b/taskapp/events/request.py @@ -64,6 +64,16 @@ def reply_to_request(request_obj, reply, replied_by): ## drop a welcome message to that fucker changeRole(role=request_obj.role, user=request_obj.replied_by) create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, requested_by=request_obj.sent_by) + + ## here we look for requests that are similar => requesting for DV and make them invalid + ## also we drop a notification to user who made request + pending_requests = request_obj.replied_by.request_sent_to.filter(is_valid=True,is_replied=False,role="DV") + for req in pending_requests: + req.is_valid = False + req.save() + create_notification(role = req.role, sent_to = req.sent_by, sent_from = replied_by, reply = False, \ + remarks = "User has accepted a similar request and has rights same or higher privileged than the request", \ + requested_by = req.sent_by ) else: create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by) @@ -75,6 +85,17 @@ def reply_to_request(request_obj, reply, replied_by): alerting_users = Profile.objects.filter(user__is_active=True).exclude(rights="CT").exclude(rights="DV") for a_profile in alerting_users: create_notification(request_obj.role, a_profile.user, request_obj.replied_by, reply, requested_by=request_obj.sent_by) + + ## here we look for requests that less or similar => requesting for DV or MG and make them invalid + ## also we drop a notification to user who made request + active_requests = request_obj.replied_by.request_sent_to.filter(is_valid=True,is_replied=False) + pending_requests = active_requests.filter(role="DV") | active_requests.filter(role="MG") + for req in pending_requests: + req.is_valid = False + req.save() + create_notification(role = req.role, sent_to = req.sent_by, sent_from = replied_by, reply = False, \ + remarks = "User has accepted a similar request and has rights same or higher privileged than the request", \ + requested_by = req.sent_by ) else: create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by) diff --git a/taskapp/utilities/notification.py b/taskapp/utilities/notification.py index 7ef646f..b1bc8a9 100644 --- a/taskapp/utilities/notification.py +++ b/taskapp/utilities/notification.py @@ -82,7 +82,7 @@ def create_notification(role, sent_to, sent_from=None, reply=None, task=None, re notification.message = "%s has accepted request made by %s asking him to act as %s %s for the website.<br />"%(user_url, requested_by_url, a_or_an, role_rights) else: notification.sub = "Rejected your request to act as %s"%role_rights - notification.message = "%s has rejected your request asking him to act as a %s.<br />"%(new_mentor_url, task_url) + notification.message = "%s has rejected your request asking him to act as a %s.<br />"%(user_url, role_rights) if remarks: notification.message += "Remarks: %s<br />"%remarks diff --git a/taskapp/views/user.py b/taskapp/views/user.py index 9ccdcaf..9daae3c 100644 --- a/taskapp/views/user.py +++ b/taskapp/views/user.py @@ -279,7 +279,7 @@ def change_rights(request, role): user_profile = user.get_profile() user_rights = user_profile.rights - user_can_view = True if user_rights == "AD" or ( user_rights == "MG" and role in ["mg", "dv"] ) else False + user_can_view = True if user_rights == "AD" or ( user_rights == "MG" and role in ["MG", "DV"] ) else False if user_can_view: if role == "DV": diff --git a/templates/index.html b/templates/index.html index 99287b2..3298ddd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -69,11 +69,11 @@ <a href="/task/create/">Create a task</a><br /> {% endif %} {% ifequal user.get_profile.rights "MG" %} - <a href="/user/make/dv/">Request another to be a Developer</a> + <a href="/user/make/dv/">Request another user to be a Developer</a><br /> <a href="/user/make/mg/">Request another user to act as manager</a><br /> {% endifequal %} {% ifequal user.get_profile.rights "AD" %} - <a href="/user/make/dv/">Request another to be a Developer</a><br /> + <a href="/user/make/dv/">Request another user to be a Developer</a><br /><br /> <a href="/user/make/mg/">Request another user to act as a Manager</a><br /> <a href="/user/make/ad">Request another user to act as an Admin</a><br /> {% endifequal %} |