analytics: Refactor legacy 'zulip_internal' decorator.

Rename 'zulip_internal' decorator to 'require_server_admin', add
documentation for 'server_admin', explaining how to give permission
for ./activity page.

Fixes: #1463.
This commit is contained in:
Maxim Averin 2017-04-06 13:59:18 +03:00 committed by Tim Abbott
parent 6ec32b37c3
commit 73a1dd63d5
4 changed files with 17 additions and 7 deletions

View File

@ -17,7 +17,7 @@ from analytics.lib.time_utils import time_range
from analytics.models import BaseCount, InstallationCount, RealmCount, \
UserCount, StreamCount, last_successful_fill
from zerver.decorator import has_request_variables, REQ, zulip_internal, \
from zerver.decorator import has_request_variables, REQ, require_server_admin, \
zulip_login_required, to_non_negative_int, to_utc_datetime
from zerver.lib.request import JsonableError
from zerver.lib.response import json_success
@ -743,7 +743,7 @@ def ad_hoc_queries():
return pages
@zulip_internal
@require_server_admin
@has_request_variables
def get_activity(request):
# type: (HttpRequest) -> HttpResponse
@ -1037,7 +1037,7 @@ def realm_user_summary_table(all_records, admin_emails):
content = make_table(title, cols, rows, has_row_class=True)
return user_records, content
@zulip_internal
@require_server_admin
def get_realm_activity(request, realm_str):
# type: (HttpRequest, str) -> HttpResponse
data = [] # type: List[Tuple[str, str]]
@ -1076,7 +1076,7 @@ def get_realm_activity(request, realm_str):
context=dict(data=data, realm_link=realm_link, title=title),
)
@zulip_internal
@require_server_admin
def get_user_activity(request, email):
# type: (HttpRequest, str) -> HttpResponse
records = get_user_activity_records_for_email(email)

View File

@ -208,3 +208,13 @@ Tips and tricks:
bars in a bar graph) in your browser, since there is an interaction layer
on top of it. But if you hunt around the document tree you should be able
to find it.
### /activity page
- There's a somewhat less developed /activity page, for server
administrators, showing data on all the realms on a server. To
access it, you need to have the `is_staff` bit set on your
UserProfile object. You can set it using `manage.py shell` and
editing the UserProfile object directly. A great future project is
to clean up that page's data sources, and make this a documented
interface.

View File

@ -343,7 +343,7 @@ def zulip_login_required(function=None,
return actual_decorator(add_logging_data(function))
return actual_decorator
def zulip_internal(view_func):
def require_server_admin(view_func):
# type: (ViewFuncT) -> ViewFuncT
@zulip_login_required
@wraps(view_func)

View File

@ -1040,8 +1040,8 @@ class TestZulipLoginRequiredDecorator(ZulipTestCase):
result = self.client_get('/accounts/accept_terms/')
self.assertEqual(result.status_code, 302)
class TestZulipInternalDecorator(ZulipTestCase):
def test_zulip_internal_decorator(self):
class TestRequireServerAdminDecorator(ZulipTestCase):
def test_require_server_admin_decorator(self):
# type: () -> None
user_email = 'hamlet@zulip.com'
self.login(user_email)