Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e8d93a88
Commit
e8d93a88
authored
May 07, 2015
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support in API to mark a notification as read
parent
89e51ecc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
5 deletions
+62
-5
lms/djangoapps/api_manager/users/tests.py
+34
-0
lms/djangoapps/api_manager/users/urls.py
+1
-0
lms/djangoapps/api_manager/users/views.py
+18
-1
lms/envs/aws.py
+7
-3
lms/envs/common.py
+2
-1
No files found.
lms/djangoapps/api_manager/users/tests.py
View file @
e8d93a88
...
...
@@ -40,6 +40,10 @@ from xmodule.modulestore import Location
from
django.contrib.auth.models
import
User
from
notification_prefs
import
NOTIFICATION_PREF_KEY
from
edx_notifications.lib.publisher
import
register_notification_type
,
publish_notification_to_user
from
edx_notifications.lib.consumer
import
get_notifications_count_for_user
from
edx_notifications.data
import
NotificationMessage
,
NotificationType
MODULESTORE_CONFIG
=
mixed_store_config
(
settings
.
COMMON_TEST_DATA_ROOT
,
{},
include_xml
=
False
)
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
...
...
@@ -1874,3 +1878,33 @@ class UsersApiTests(ModuleStoreTestCase):
delete_uri
=
'{}invalid_role/courses/{}'
.
format
(
test_uri
,
unicode
(
self
.
course
.
id
))
response
=
self
.
do_delete
(
delete_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_mark_notification_as_read
(
self
):
user_id
=
self
.
_create_test_user
()
msg_type
=
NotificationType
(
name
=
'open-edx.edx_notifications.lib.tests.test_publisher'
,
renderer
=
'edx_notifications.renderers.basic.BasicSubjectBodyRenderer'
,
)
register_notification_type
(
msg_type
)
msg
=
NotificationMessage
(
namespace
=
'test-runner'
,
msg_type
=
msg_type
,
payload
=
{
'foo'
:
'bar'
}
)
# now do happy path
sent_user_msg
=
publish_notification_to_user
(
user_id
,
msg
)
# verify unread count
self
.
assertEqual
(
get_notifications_count_for_user
(
user_id
,
filters
=
{
'read'
:
False
}),
1
)
# mark as read
test_uri
=
'{}/{}/notifications/{}/'
.
format
(
self
.
users_base_uri
,
user_id
,
sent_user_msg
.
msg
.
id
)
response
=
self
.
do_post
(
test_uri
,
{
"read"
:
True
})
self
.
assertEqual
(
response
.
status_code
,
200
)
# then verify unread count, which should be 0
self
.
assertEqual
(
get_notifications_count_for_user
(
user_id
,
filters
=
{
'read'
:
False
}),
0
)
lms/djangoapps/api_manager/users/urls.py
View file @
e8d93a88
...
...
@@ -26,6 +26,7 @@ urlpatterns = patterns(
url
(
r'^(?P<user_id>[a-zA-Z0-9]+)/roles/(?P<role>[a-z_]+)/courses/(?P<course_id>[a-zA-Z0-9_+\/:]+)$'
,
users_views
.
UsersRolesCoursesDetail
.
as_view
(),
name
=
'users-roles-courses-detail'
),
url
(
r'^(?P<user_id>[a-zA-Z0-9]+)/roles/*$'
,
users_views
.
UsersRolesList
.
as_view
(),
name
=
'users-roles-list'
),
url
(
r'^(?P<user_id>[a-zA-Z0-9]+)/workgroups/$'
,
users_views
.
UsersWorkgroupsList
.
as_view
(),
name
=
'users-workgroups-list'
),
url
(
r'^(?P<user_id>[a-zA-Z0-9]+)/notifications/(?P<msg_id>[0-9]+)/$'
,
users_views
.
UsersNotificationsDetail
.
as_view
(),
name
=
'users-notifications-detail'
),
url
(
r'^(?P<user_id>[a-zA-Z0-9]+)$'
,
users_views
.
UsersDetail
.
as_view
(),
name
=
'apimgr-users-detail'
),
url
(
r'/*$^'
,
users_views
.
UsersList
.
as_view
(),
name
=
'apimgr-users-list'
),
)
...
...
lms/djangoapps/api_manager/users/views.py
View file @
e8d93a88
...
...
@@ -57,7 +57,7 @@ from api_manager.utils import generate_base_uri, dict_has_items, extract_data_pa
from
projects.serializers
import
BasicWorkgroupSerializer
from
.serializers
import
UserSerializer
,
UserCountByCitySerializer
,
UserRolesSerializer
from
edx_notifications.lib.consumer
import
mark_notification_read
log
=
logging
.
getLogger
(
__name__
)
AUDIT_LOG
=
logging
.
getLogger
(
"audit"
)
...
...
@@ -1387,3 +1387,20 @@ class UsersRolesCoursesDetail(SecureAPIView):
return
Response
({},
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
({},
status
=
status
.
HTTP_204_NO_CONTENT
)
class
UsersNotificationsDetail
(
SecureAPIView
):
"""
Allows for a caller to delete a user's notification, passed in by msg_id. Note that the
user_msg_id must belong to the user_id passed in
"""
def
post
(
self
,
request
,
user_id
,
msg_id
):
"""
POST /api/users/{user_id}/notifications/{msg_id}
"""
read
=
bool
(
request
.
DATA
[
'read'
])
mark_notification_read
(
int
(
user_id
),
int
(
msg_id
),
read
=
read
)
return
Response
({},
status
=
status
.
HTTP_200_OK
)
lms/envs/aws.py
View file @
e8d93a88
...
...
@@ -602,9 +602,13 @@ NOTIFICATION_EMAIL_FROM_ADDRESS = ENV_TOKENS.get(
'NOTIFICATION_EMAIL_FROM_ADDRESS'
,
NOTIFICATION_EMAIL_FROM_ADDRESS
)
NOTIFICATION_EMAIL_CLICK_LINK_ROOT
=
ENV_TOKENS
.
get
(
'NOTIFICATION_EMAIL_CLICK_LINK_ROOT'
,
NOTIFICATION_EMAIL_CLICK_LINK_ROOT
NOTIFICATION_APP_HOSTNAME
=
ENV_TOKENS
.
get
(
'NOTIFICATION_APP_HOSTNAME'
,
SITE_NAME
)
NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT
=
ENV_TOKENS
.
get
(
'NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT'
,
NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT
)
NOTIFICATION_DIGEST_SEND_TIMEFILTERED
=
ENV_TOKENS
.
get
(
'NOTIFICATION_DIGEST_SEND_TIMEFILTERED'
,
...
...
lms/envs/common.py
View file @
e8d93a88
...
...
@@ -2104,7 +2104,8 @@ NOTIFICATION_DAILY_DIGEST_SUBJECT = "Your unread notifications for '{display_nam
NOTIFICATION_WEEKLY_DIGEST_SUBJECT
=
"Your unread notifications for '{display_name}'"
NOTIFICATION_BRANDED_DEFAULT_LOGO
=
'edx_notifications/img/edx-openedx-logo-tag.png'
NOTIFICATION_EMAIL_FROM_ADDRESS
=
''
NOTIFICATION_EMAIL_CLICK_LINK_ROOT
=
'http://localhost'
NOTIFICATION_APP_HOSTNAME
=
SITE_NAME
NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT
=
"http://{hostname}{url_path}"
NOTIFICATION_DIGEST_SEND_TIMEFILTERED
=
True
# Country code overrides
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment