TNl-6610 Fix "more" menu on discussion post for global staff.
This commit is contained in:
@@ -1405,6 +1405,26 @@ class PermissionsTestCase(ModuleStoreTestCase):
|
||||
'can_report': True
|
||||
})
|
||||
|
||||
def test_get_ability_with_global_staff(self):
|
||||
"""
|
||||
Tests that global staff has rights to report other user's post inspite
|
||||
of enrolled in the course or not.
|
||||
"""
|
||||
content = {'user_id': '1', 'type': 'thread'}
|
||||
|
||||
with mock.patch('django_comment_client.utils.check_permissions_by_view') as check_perm:
|
||||
# check_permissions_by_view returns false because user is not enrolled in the course.
|
||||
check_perm.return_value = False
|
||||
global_staff = UserFactory(username='global_staff', email='global_staff@edx.org', is_staff=True)
|
||||
self.assertEqual(utils.get_ability(None, content, global_staff), {
|
||||
'editable': False,
|
||||
'can_reply': False,
|
||||
'can_delete': False,
|
||||
'can_openclose': False,
|
||||
'can_vote': False,
|
||||
'can_report': True
|
||||
})
|
||||
|
||||
def test_is_content_authored_by(self):
|
||||
content = {}
|
||||
user = mock.Mock()
|
||||
|
||||
@@ -29,6 +29,7 @@ from openedx.core.djangoapps.course_groups.cohorts import (
|
||||
)
|
||||
from openedx.core.djangoapps.course_groups.models import CourseUserGroup
|
||||
from request_cache.middleware import request_cached
|
||||
from student.roles import GlobalStaff
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -525,12 +526,12 @@ def get_ability(course_id, content, user):
|
||||
content,
|
||||
"vote_for_thread" if content['type'] == 'thread' else "vote_for_comment"
|
||||
),
|
||||
'can_report': not is_content_authored_by(content, user) and check_permissions_by_view(
|
||||
'can_report': not is_content_authored_by(content, user) and (check_permissions_by_view(
|
||||
user,
|
||||
course_id,
|
||||
content,
|
||||
"flag_abuse_for_thread" if content['type'] == 'thread' else "flag_abuse_for_comment"
|
||||
)
|
||||
) or GlobalStaff().has_user(user))
|
||||
}
|
||||
|
||||
# TODO: RENAME
|
||||
|
||||
Reference in New Issue
Block a user