Commit Graph

24 Commits (68836e7e237d82a377b2b2262cf85f031cb0bba1)

Author SHA1 Message Date
Manuel Kaufmann 7d08eed428 Run add-trailing-comma over all the files 2019-01-21 18:49:11 +01:00
Manuel Kaufmann d8dacdee8f Merge branch 'master' of github.com:rtfd/readthedocs.org into humitos/deprecate-python2 2019-01-21 18:04:42 +01:00
Manuel Kaufmann a8814b3599 Notify users about the usage of deprecated webhooks (#4898)
* Notify users about the usage of deprecated webhooks

Each time a deprecated webhook is hit, a notification is
created (without duplicating it) to be sent.

* Extend notification to support de-dup and delayed email sent

* Improve decorator to support generic and specific VCS webhook views

* Remove no necessary settings

* DeprecatedWebhookEndpointNotification tests and improvements

* Better docstring

* Lint

* Update copy on notifications for github services deprecation (#5067)

* Updated copy on webhooks

* Drop "deprecated webhook endpoint" copy, this is core team nomenclature, not user
nomenclature.
* Add small amount of docs to point to

* Update docs and point to docs in notification message

* Add year

* Split up deprecated view notification to GitHub and other webhook endpoints (#5083)

* Updated copy on webhooks

* Drop "deprecated webhook endpoint" copy, this is core team nomenclature, not user
nomenclature.
* Add small amount of docs to point to

* Update docs and point to docs in notification message

* Split up deprecated view notification to GitHub and other webhook endpoints

This sets a date for deprecated of these endpoints as Mar 1st 2019. Too
soon?

* Reduce complexity and drop decorator pattern for Notification
  classmethod pattern used in other notifications
* Add notifications for non-GitHub incoming webhooks
* Add docs as well

* More renaming and slight refactor

Found out 2x messages are being generated, so this stops the automated
mechanism for triggering these messages.

* Update dates

* Also update docs

* Typo on date

* Back out some more of the changes to notifications to make them operable without automation

* Add admin method for notification

* Add admin filter for project features
2019-01-10 18:51:40 -07:00
Manuel Kaufmann 632e18c121 pre-commit all the files again 2019-01-09 13:19:00 +01:00
Manuel Kaufmann f1820596f0 pre-commit run on some missing files (manually applyed) 2019-01-09 12:53:25 +01:00
Manuel Kaufmann 0c535feb20 More linting issues fixed 2019-01-09 12:51:48 +01:00
Manuel Kaufmann 3219f7acbd Run pre-commit on all the files
$ pre-commit run --files `find readthedocs -name '*'`
2019-01-08 21:51:36 +01:00
Manuel Kaufmann c78187b62f isort all the files
$ pre-commit run python-import-sorter --files `find readthedocs -name '*.py'`

It was ran with this configuration: https://github.com/rtfd/common/pull/28
2019-01-08 20:56:20 +01:00
Manuel Kaufmann f7dea72b86 pyupgrade 1.11.0 on all code
pyupgrade --py3-plus --py3-only (*.py)
2019-01-03 16:56:33 +01:00
Manuel Kaufmann bd33e1d402 Use is_authenticated and is_anonymous as attribute 2018-12-04 12:20:54 +01:00
Santos Gallegos 2ba2a2547d Fix some typos in docs and code (#4646) 2018-09-19 13:11:43 -06:00
Manuel Kaufmann 8b7c2797f8 Upgrade all packages using pur (#4318)
* Upgrade all packages using pur

for reqs in `ls requirements`;
do
  pur
  --skip django-tastypie,django,docker,elasticsearch,pyelasticsearch,commonmark,stripe,djangorestframework,mkdocs,django-allauth,django-filter,mercurial
  --requirement requirements/$reqs;
done

* Run lint with Python 3.6

* Downgrade gitpython to 2.1.10

* Linting error fixed

* Upgrade common

Branch: https://github.com/rtfd/common/pull/17

* Remove old note for testing

* Add note for django-filter

* no-else-return fixed in all the files

Some block needed to be re-idented to fulfill this check.

Basically, if you have a "if something: return another" the "else"
clause is not needed since it will be the common case for the flow to
continue if the condition is not met.

* Only # noqa comment

* Note about gitpython
2018-09-05 09:34:49 -06:00
Manuel Kaufmann cedda9bf53 Allow to hook the initial build from outside (#4033)
* Allow to hook the initial build from outside

Add a new attribute to `trigger_build` to do not execute the task but
just return the immutable signature of it, so it can be chained into a
bigger task from outside when it's needed to do something else
before/after it's execution.

* Remove unused basic attribute on trigger build

* Split trigger_build to be able to prepare_build first

Added a ``ImportWizard.trigger_initial_build`` method to be override
from corporate site.

Also, instead of using ``trigger_build`` to create the Celery task and
call it immediately, split it to use ``prepare_build`` first to create
the task and use ``trigger_build`` to effectively triggers it.

* Remove now unused signal

* Fix Celery signature creation

* Fix testcases with basic on trigger_build

* Fix mock calls in test cases

* Fix test mock check

* Use async task to attach webhook

* Use proper context object

* Make it compatible with newer Django versions

* Py2 and Py3 compatible line

* Dismiss the sticky message and stay in the same page

* Use Context to render the template

* Lint errors fixed

* Call the task in a sync way properly

* Update common submodule to latest

* Define NonPersistentStorage for one-time notifications

NonPersistentNotification backed together with SiteNotification class
helps us to create one-time site notifications and attach it to a user
without the needs of a request/session object.

The message/notification is saved into the database as a
PersistentMessage and it's marked as read while it's retrived the
first time.

This system is useful for notifications that need to be attached from
a Celery task where we know the user but we don't have the request.

* Make string translatable

* Fix merge conflicts

* Recover accidentally deleted line

* Fixed linting errors

* Replace message_key with reason to be clearer

* Rename non persistent storage class

* Remove old templates

* Make SiteNotification more flexible

- render strings messages as Django Templates
- accept extra_context for the template
- do not crash if the reason is incorrect

* Adapt AttachWebhookNotification to the new features

* Refactor the task to attach a webhook

Instantiate only once the notification and adapt it depending the
context.

Also, if there are no connected services into our application do not
show a message to the user, but log it as a warning.

* Test cases for SiteNotification and NonPersistentStorage

* Remove unnecessary lines

* Show a persistent message for invalid project webhook

If we can setup a valid webhook, we show a persistent message with an
actionable link using our notifications abstraction.

At this point, the message is duplicated because we have a "fixed
template message" also which is planned to be removed soon.

* Improve copy

* Allow to hook the initial build from outside

Add a new attribute to `trigger_build` to do not execute the task but
just return the immutable signature of it, so it can be chained into a
bigger task from outside when it's needed to do something else
before/after it's execution.

* Remove unused basic attribute on trigger build

* Split trigger_build to be able to prepare_build first

Added a ``ImportWizard.trigger_initial_build`` method to be override
from corporate site.

Also, instead of using ``trigger_build`` to create the Celery task and
call it immediately, split it to use ``prepare_build`` first to create
the task and use ``trigger_build`` to effectively triggers it.

* Remove now unused signal

* Fix Celery signature creation

* Fix testcases with basic on trigger_build

* Fix mock calls in test cases

* Fix test mock check

* Use proper context object

* Make it compatible with newer Django versions

* Py2 and Py3 compatible line

* Dismiss the sticky message and stay in the same page

* Use Context to render the template

* Lint errors fixed

* Call the task in a sync way properly

* Update common submodule to latest

* Define NonPersistentStorage for one-time notifications

NonPersistentNotification backed together with SiteNotification class
helps us to create one-time site notifications and attach it to a user
without the needs of a request/session object.

The message/notification is saved into the database as a
PersistentMessage and it's marked as read while it's retrived the
first time.

This system is useful for notifications that need to be attached from
a Celery task where we know the user but we don't have the request.

* Make string translatable

* Use async task to attach webhook

* Fix merge conflicts

* Recover accidentally deleted line

* Fixed linting errors

* Replace message_key with reason to be clearer

* Rename non persistent storage class

* Remove old templates

* Make SiteNotification more flexible

- render strings messages as Django Templates
- accept extra_context for the template
- do not crash if the reason is incorrect

* Adapt AttachWebhookNotification to the new features

* Refactor the task to attach a webhook

Instantiate only once the notification and adapt it depending the
context.

Also, if there are no connected services into our application do not
show a message to the user, but log it as a warning.

* Test cases for SiteNotification and NonPersistentStorage

* Remove unnecessary lines

* Show a persistent message for invalid project webhook

If we can setup a valid webhook, we show a persistent message with an
actionable link using our notifications abstraction.

At this point, the message is duplicated because we have a "fixed
template message" also which is planned to be removed soon.

* Improve copy

* Remove fixed template notification about Project.has_valid_webhook
2018-06-14 12:29:08 -06:00
Manuel Kaufmann 1fa6cf6e57 Handle revoked oauth permissions by the user (#4074)
* Handle general oauth services errors

This is a way to protect ourselves from random errors when syncing
OAuth services (create repository/organizations).

If a global exception is raised, we just skip this service and
continue with the rest of the connected ones.

* Handle revoked oauth permissions by the user

If the user revoked our app permission from the external service web
page, we are not notified. So, next time we try to use it, we will
receive a 401 status code in the first request.

Here we handle this case and we show a Persistent Notification to the
user so he/she knows that a reconnection of the account is needed.

* Remove unnecessary exception handling

* Style

* Add a user persistent notification when social access is revoked

* Raise an Exception when permissions revoked

Raise a simple Exception when the permissions from a particular social
service are revoked instead of using a persistent notification.

We want an Exception because it's immediately communicated using the
PublicTask mechanism. Otherwise, the user needs to refresh the page to
see the notification.

* Remove invalid imports

* Improve comment

* Add final dot to the phrase

* Remove unused return
2018-06-14 11:22:40 -06:00
Manuel Kaufmann 745dc7483c Fix some linting 2018-01-25 20:43:54 -05:00
Manuel Kaufmann 4d10f2e287 Fix D213 using docformatter
prospector \
  --profile-path=/home/humitos/rtfd/code/readthedocs.org \
  --profile=prospector --die-on-tool-error \
  | \
  grep -e "^[a-z] \
  > \
  list-files.txt

for x in `cat list-files.txt`; do \
  docformatter \
    --wrap-summaries=80 \
    --wrap-descriptions=80 \
    --pre-summary-newline \
    --no-blank \
    --in-place readthedocs/$x\
; done
2017-12-15 20:18:06 -05:00
Hank Gay 64116bc541 Make a pass with futurize on stage 2.
Depend on futurize.
2017-05-30 18:10:44 -04:00
Hank Gay f201d150dd Make a pass w/ python-modernize. 2017-05-30 17:55:56 -04:00
Daniel Pope a2cf44b43b Fix lint issues for notifications app (#2881) 2017-05-23 10:54:00 -07:00
Anthony d6aa24bff7 Alter usage of message extends (#2567)
* Alter usage of message extends

Instead of using the messages.add method directly, add message for the message
notification backend using the storage adapter directly. This also removes the
limitation on the storage backend that requires a request.user is authenticated,
as we are likely going to be mostly adding messages through celery or other
request-less mechanisms.

* Fix tests

* Make sure we can't add messages for anonymous users and fix tests
2017-01-04 17:32:58 -08:00
Anthony 864739c305 Fix bug with on site notification (#2478)
* Fix bug with on site notification

It would help if the notification went to the correct user.

* Fix tests

* Replace monkey patched add_message with actual method for linting fix
2016-10-28 11:44:36 -07:00
Anthony 402c0e3944 Fix signup issues and brand allauth emails (#2448)
* Fix signup issues and brand allauth emails

This fixes a bug with the notification system on logged out users and overrides
the allauth email templates. The base emails are very generic, aren't themed like
the rest of our emails, and had very generic copy.

* Lint fix
2016-10-10 15:42:00 -07:00
Anthony 4c595b4eed Add prefix URI for notifications in context data (#2440)
* Add prefix URI for notifications in context data

This adds context data for constructing full URIs.

* Lint fix
2016-10-06 17:58:51 -07:00
Anthony 285bbf13f6 Integrate on-site messaging that is persistent, combine message transports (#2406)
* WIP for integrating persistent messaging for users

Combines notifications so that email/on site messaging will all be maintained in
the same place, and can extend from each other using normal template semantics.

* Add email support, clean up implementation

* Add reqs

* Drop unnecessary string conversion

* Change admin email form to look at templates, not ask for template source

* Add docs, tests, views for processing redirects

* Do the thing I meant to do

* Drop views, just use javascript instead

This adds javascript that intercepts link clicks in notifications,
hits the dismiss url defined on the dom object, and then redirects 
to the correct url of the original link.

* Move classes around and rename module

* Drop unused notification for testing

* Clean up usage, drop test uses of the views/notifications

* Add example usage that will be used for notification on resource usage

* Fix mock module path

* Add more docs around implementation
2016-10-01 10:19:51 -07:00