Commit Graph

143 Commits

Author SHA1 Message Date
Tim Abbott
a2011b5a48 decorator: Simplify control flow in validate_api_key.
This technically changes the behavior in the case that
!settings.ZILENCER_ENABLED but is_remote_zulip_server(role).
Fortunately, that case is mostly irrelevant (in that remote zulip
servers is a Zilencer feature).  The old behavior was also probably
slightly wrong, in that you'd get a zilencer-specific error message in
that case.
2017-08-15 10:52:46 -07:00
Tim Abbott
a6647f335f decorator: Reorganize remote Zulip server code into one block. 2017-08-15 10:51:29 -07:00
Tim Abbott
052e173aae decorator: Simplify invalid API key error messages. 2017-08-15 10:51:29 -07:00
Tim Abbott
928a93bb9a decorator: Swap order of remote server if statements. 2017-08-15 10:51:29 -07:00
Tim Abbott
3157618b80 decorators: Extract access_user_by_api_key. 2017-08-15 10:51:29 -07:00
Umair Khan
ef1b880082 rate_limiter: Upgrade api_calls_left to generic API. 2017-08-02 18:01:39 -07:00
Umair Khan
81e2128774 rate_limiter: Upgrade incr_ratelimit to generic API. 2017-08-02 18:01:39 -07:00
Umair Khan
dd281367ae rate_limited: Upgrade is_ratelimited to generic API. 2017-08-02 18:01:39 -07:00
Tim Abbott
04729a0e79 mypy: Remove some now-unused type: ignores. 2017-07-27 16:12:26 -07:00
Greg Price
a5597e91a1 exceptions: Move zerver/exceptions.py under zerver/lib/.
Seems like a more appropriate place for it.  Preparation for
moving a bit more into that file.
2017-07-24 16:41:22 -07:00
Greg Price
e18baff32c JsonableError: Rename message from error to msg.
The whole thing is an error, so "message" is a more apt word for the
error message specifically.  We abbreviate that as `msg` in the actual
HTTP responses and in the signatures of `json_error` and friends, so
do the same here.
2017-07-24 16:41:22 -07:00
Eeshan Garg
a24ea56c53 decorator: Handle invalid JSON in api_key_only_webhook_view.
Exception logging within api_key_only_webhook_view fails when
ValueError is raised if the request.body passed to ujson.loads
isn't valid JSON. In this case, we now just convert the payload
to a string and log that. This allows us to inspect JSON payloads
that aren't being decoded properly.
2017-07-19 10:42:35 -07:00
Vaida Plankyte
8c4ee83980 decorator.py: Use the singular 'they' pronoun. 2017-07-05 09:27:43 -07:00
Umair Khan
1e9c87855c Django 1.11: is_authenticated is now a property. 2017-06-13 15:04:04 -07:00
Aditya Bansal
4679da87c4 pep8: Add compliance with rule E261 decorator.py. 2017-06-04 09:18:22 -07:00
Ethan
d1bd19a1b8 mypy: correct user_passes_test first argument. 2017-05-25 15:41:48 -07:00
Ethan
c284d913cc mypy: request.body is bytes, should be str. 2017-05-25 15:41:46 -07:00
Umair Khan
4e2a6834d8 authenticated_rest_api_view: Use is_remote_server.
Using is_remote_server is more readable and future-proof since
it provides a level of abstraction.
2017-05-16 12:26:55 -07:00
Tim Abbott
0b46be2fed Avoid UserActivity logging for RemoteZulipServer requests.
We had a somewhat messy bug where we were sending invalid entries to
the UserActivity queue when using the push notification bouncer.
2017-05-15 17:15:01 -07:00
Eeshan Garg
10dcc99983 zerver/decorators: Log all exceptions raised in api_key_only_webhook_view.
Fixes #4742.
2017-05-13 14:53:47 -07:00
Umair Khan
faf190ff34 validate_api_key: Use is_remote_server. 2017-05-11 12:02:26 -07:00
Rishi Gupta
e46cbaffa2 email: Remove Mandrill pathways and dependency.
Everything it was doing (send_future_email) can now be done using
ScheduledJob.
2017-05-05 14:38:23 -07:00
Eeshan Garg
e87e246fcb zerver/decorator: Set request.client in api_key_only_webhook_view.
Previously, api_key_only_webhook_view passed 3 positional arguments
(request, user_profile, and client) into a function. However, most
of our other auth decorators only pass 2 positional arguments. For
the sake of consistency, we now make api_key_only_webhook_view set
request.client and pass only request and user_profile as positional
arguments.
2017-05-01 23:44:07 -07:00
Maxim Averin
73a1dd63d5 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.
2017-04-22 11:42:02 -07:00
Tim Abbott
cddee49e75 Add support infrastructure for push notification bouncer service.
This is an incomplete cleaned-up continuation of Lisa Neigut's push
notification bouncer work.  It supports registration and
deregistration of individual push tokens with a central push
notification bouncer server.

It still is missing a few things before we can complete this effort:
* A registration form for server admins to configure their server for
  this service, with tests.
* Code (and tests) for actually bouncing the notifications.
2017-04-18 23:03:06 -07:00
Tim Abbott
ae788b2e98 zilencer: Remove decorators Deployment code. 2017-04-18 23:00:10 -07:00
Tim Abbott
cbc731963f decorator: Add support for Django internal_notify_view. 2017-04-18 09:59:07 -07:00
Rishi Gupta
e14c940ecc decorator: Add human_users_only decorator.
Applies it to presence.update_active_status_backend as an example of usage.
2017-04-16 12:51:23 -07:00
hackerkid
b2504084ab Replace timezone.now with timezone_now. 2017-04-16 12:28:56 -07:00
Tim Abbott
033fd98e5f decorator: Add rate limiting to zulip_login_required. 2017-03-26 13:10:43 -07:00
Tim Abbott
385551ff62 decorator: Add rate-limiting to JSON views. 2017-03-26 13:10:43 -07:00
Tim Abbott
6c4c8178f0 zulip_login_required: Set request._query.
This fixes an exception we had in the user_activity queue processor
when changing email addresses, since the URL containing the
confirmation key was longer than 50 characters.
2017-03-26 13:10:43 -07:00
K.Kanakhin
234a1f8e61 retention-period: Add retention period to front-end admin organization settings.
- Add message retention period field to organization settings form.
- Add css for retention period field.
- Add convertor to not negative int or to None.
- Add retention period setting processing to back-end.
- Fix tests.

Modified by tabbott to hide the setting, since it doesn't work yet.
The goal of merging this setting code now is to avoid unnecessary
merge conflicts in the future.

Part of #106.
2017-03-25 17:57:18 -07:00
Umair Khan
149b0c30df capitalization: Fix Only Basic authentication is supported. 2017-03-08 23:40:57 -08:00
Tim Abbott
75e81253f2 mypy: Work around several new mypy bugs in 0.501. 2017-03-04 15:33:39 -08:00
Rishi Gupta
15d60fa7ed Change now() to timezone.now() throughout codebase.
Change `from django.utils.timezone import now` to
`from django.utils import timezone`.

This is both because now() is ambiguous (could be datetime.datetime.now),
and more importantly to make it easier to write a lint rule against
datetime.datetime.now().
2017-02-28 16:03:37 -08:00
Tim Abbott
20f9c04ab5 decorator: Add logging data to zulip_login_required.
This fixes an issue that many logged=in pages such as /stats did not
correctly report either the connecting client or the user in server
logs.
2017-02-20 21:15:44 -08:00
Tim Abbott
c9126e772e decorator: Don't block ZulipElectron name in json views.
This fixes the logging of the ZulipElectron client in server logs.
Message sending is still logged as "website"; that will be fixed soon.
2017-02-17 15:19:10 -08:00
Tim Abbott
2bba7755e3 decorator: Improve user agent parsing. 2017-02-10 23:53:44 -08:00
Tim Abbott
bc63407e6a decorator: Cleanup api_key_legacy code readability. 2017-02-10 23:53:44 -08:00
Tim Abbott
bb5d81281c mypy: Upgrade to new package name and version 0.571.
Fixes #3448.
2017-02-10 23:53:44 -08:00
Tim Abbott
70af09539f Fix unnecessary traceback in authenticated_rest_api_view.
Apparently, we weren't returning the `json_error`, resulting in users
encountering this condition receiving a 500, rather than the proper
40x error.

This fixes a regresion introduced in 9ae68ade8b.
2017-01-29 12:48:10 -08:00
Tim Abbott
4e171ce787 lint: Clean up E126 PEP-8 rule. 2017-01-23 22:06:13 -08:00
Tim Abbott
22d1aa396b lint: Clean up W503 PEP-8 warning. 2017-01-23 20:50:04 -08:00
Tommy Ip
008663abd8 zerver: Fix bare except clause. 2017-01-09 00:38:31 +00:00
Tim Abbott
0847515203 Fix text_type->Type mypy merge conflict error. 2016-12-29 15:03:37 -08:00
Rishi Gupta
7b057392c6 decorator.py: Add to_utc_datetime converter function. 2016-12-29 14:20:13 -08:00
Juan Verhook
cfa9c2eaf2 mypy: Update zerver directory to use Text 2016-12-29 09:12:15 -08:00
Tim Abbott
7e8f8551de decorator: Change /activity to be gated on is_staff.
Zulip doesn't previously make use of the standard Django is_staff flag
(in that the Django admin site is disabled), but since conceptually
the /activity page would be part of the Django admin site if we were
using it (i.e. for server-level administrators), it makes sense to key
off of that rather than the previous, fragile, check for the realm
domain name.
2016-12-13 21:06:27 -08:00
nikolay
abc2ff4a06 pep8: Fix many rule E128 violations.
[Tweaked by tabbott to adjust some approaches used in wrapping]
2016-12-03 13:33:31 -08:00