Граф коммитов

149 Коммитов

Автор SHA1 Сообщение Дата
Mathieu Pillard 7e0ccffc55
Add Elasticsearch score value to the search API results (#9660)
Add Elasticsearch score value to the search API results

Also remove the unused ESAddonSerializerWithUnlistedData.
2018-10-12 12:11:29 +02:00
Mathieu Pillard c2828a51f9
Mark views as non-atomic if the request method is "safe" (#9548)
Mark views as non-atomic if the request method is "safe"

This avoid unnecessary transactions for GET / HEAD / OPTIONS / TRACE
http methods. Also only set ATOMIC_REQUESTS on the default database
(the one used for writes)
2018-10-02 12:27:18 +02:00
Mathieu Pillard 2445f3602f
Don't throttle API requests on dev to ease development (#9567)
Don't throttle API requests on dev to ease development
2018-10-02 11:54:08 +02:00
Andrew Williamson e3f0f35f81
v4 enable l10n_flat_input_output drf gate + add v4dev (#9502) 2018-09-25 15:33:52 +01:00
Andrew Williamson 534e8f56f9
unsigned, PositiveAutoFields (#9377) 2018-09-24 07:47:03 +01:00
Christopher Grebs 92e9fb2aed
Fix deprecation warnings (Django 2.x, DRF etc) (#9431)
This should fix most of our current Django 2.x and DRF deprecation warnings that we see during test runs.

* Uses `remote_field.model` in amo/utils instead of `remote_field.to`
* Uses `is_anonymous` and `is_authenticated` as properties instead of functions
* Replaces drf `@detail_route` with `@action(detail=True)`

Fixes #9432
2018-09-17 09:24:14 +02:00
Mathieu Pillard 50c17df8aa Handle JWTs created with broken iat/exp type (string containing an int)
Also included is a refactor of some test classes related to JWT tests
that should actually be mixins.
2018-09-07 15:02:08 +02:00
Andrew Williamson 3d7ab2abc1
Upgrade use of MIDDLEWARE_CLASSES to newer MIDDLEWARE setting in django1.10+ (#9318) 2018-09-04 09:59:31 +01:00
Andrew Williamson 8ce8e014d0
Add is_api to Request object in middleware to only test for api once. (#9264) 2018-08-28 13:49:48 +01:00
Mathieu Pillard d1a5fe81fb Make sure last_login and last_login_ip are always set (#9120)
- Refactor auth register and login to *both* send `user_logged_in` signal
- Use that signal to set `last_login_ip` (django uses it to set `last_login`)
- Also send that signal when authenticating through JWT tokens
- Deprecate the `*_attempt` fields that no longer make sense with FxA auth

Fix #7333
2018-08-14 08:02:14 +02:00
Christopher Grebs 7407b70aa2
Update to Django 1.11 (#8738)
Port code and tests to Django 1.11.

* Update requirements to Django 1.11.14, remove session_csrf
* Use --run-syncdb for migration calls
* Remove unused setup-docker script
* Port code and tests to Django 1.11.
* Remove django-session-csrf everywhere, it got replaced by django's own
  session csrf protection
* Make sure we are calling `client.get()` with `follow=True` where necessary
* Replace django.core.urlresolvers import with django.urls
* Port custom `IconWidgetRenderer` to Django 1.11 as `IconTypeSelect`
* Properly use `_queryset_class` for custom manager classes
* Make use of `base_manager_name` on our models `Meta` instead of `use_for_related_objects`
  on the manager where appropriate. This is required to make translations, soft-delete
  and more work. See comment on Addons.Meta for more details.
* Various fixes along the way to make tests work
* Port form errors for locale editing forms to Django 1.11 and make use of
  form.add_error instead of our own custom process
* Mark TestDetailPage.test_304 as xfail for now, somehow Etags seem to be broken
  for that view during tests but work fine in manual tests
* Fix amo.celery, we cannot have any imports at the module-level that may
  import the ORM
* Fix global_settings context processor for 500-server error cases
* Fix `changed_data` handling in `AMOModelForm`
* Remove `queryset_transform` and implement it directly in amo/models
* Fix pagination, Django changed how `num_pages` work and how `count` can be overwritten
* Add a new test that tests database transforms as `BaseQuerysetTestCase`
* Make sure `legacy_redirect` only appends `?` if there are actual GET parameters
* Re-implement `LicenseRadioChoiceInput` as `LicenseRadioSelect` which is now Django 1.11 compatible
* Remove our custom `form_kwargs` uplift from Django 1.9
* Correct how we're using `Category.objects.create` and only pass `db_name` instead of `name`, previously
  this didn't error but now it (luckily!) does
* Update `FileSelectWidget` to correctly work with Django 1.11, use custom rendering
* Fix decorator ordering for `files.views:browse`
* Update database settings to correctly use `TEST` object
* Fix `select_related` call in `RatingViewSet`
* Remove custom `DateTimeCast` implementation
* Fix `addon_factory` calls in `reviewers/tests/test_views.py` to correctly set
  `is_webextension`
* Port our `TranslationDescriptor` and `TranslatedField` to Django 1.11. Also, make sure form error handling works
* Add a new test that checks that `default=None` is a valid setting for translation fields
* Add a new test that checks that translations from related fields are correctly fetched
* Remove possible ambiguity from translations `TestWidget` tests
* Make sure that the correct `MEDIA_URL` is set in `TestDownloadsUnlistedVersions` to fix
  external cdn tests

* Remove custom happyforms code. Django cleans text fields now by default
* Move translations app to the top of INSTALLED_APPS, add a lengthy comment
* Pass additional arguments to contribute_to_class, fix smaller nits
* Set MEDIA_URL and STATIC_URL to an external value by default. That's how they're configured in dev, stage and prod anyway.

Please note that we didn't replace all our custom form rendering with proper templated widgets yet. This will
happening in some follow-up work.

Fixes #5271, Fixes #1569
2018-07-11 06:56:54 +02:00
Andrew Williamson 447f632bbe
dicts should always be returned for TranslatedFields; add gate for old behavior (#8795) 2018-07-10 18:44:56 +01:00
Mathieu Pillard 31be530b52
Remove ability to edit any collection through the frontend with Collections:Edit permission (#8651)
Remove ability to edit any collection through the frontend with Collections:Edit permission

Admin:Curation gives you the ability to edit collections owned by mozilla through
the frontend. Anything else (i.e., modifying other collections) must be done
through the admin tools.
2018-06-27 15:25:40 +02:00
Andrew Williamson 50c32aa39d
use a custom reverse in tests so no need to specify explicit namespaces (#8557) 2018-06-20 16:30:49 +01:00
Andrew Williamson b457a5cece
some py3 friendly syntax changes (#8372) 2018-05-30 11:29:13 +01:00
Andrew Williamson f568f8bf26
allow more granular throttle periods and change rating replies to 1 per 5 second (#8376) 2018-05-29 16:43:16 +01:00
Andrew Williamson 2d8cf8c6b3
add api feature gates (+ reviews shim as example case) (#8332) 2018-05-25 12:30:45 +02:00
Andrew Williamson 7504b7dcdf
/api/v4/reviews/ to /api/v4/ratings/ (#8303) 2018-05-24 14:42:35 +02:00
Andrew Williamson cb4dfb52c2
add v4 api. Initially the same as v3. (#8229) 2018-05-14 19:09:27 +01:00
Mathieu Pillard dcfe291086 Add comment explaining why is_active is now a NullBooleanField 2018-05-11 16:39:48 +02:00
Mathieu Pillard a6481b3b10 Prevent developers from having several active api keys at the same time 2018-05-11 15:26:24 +02:00
Andrew Williamson 675d8aaf4f
add addon recommendation endpoint (#8126) 2018-04-26 15:53:13 +02:00
Christopher Grebs 5a26782e19
Remove statistics archiving.
I couldn't find *any* usage data for the statistics archive APIs both in
DataDog and NewRelic so I declare them as safe to remove for now.

From what I can tell we don't limit stats lookups in the dashboard as #1416
never got implemented.

This eases our load on EFS and saves money, especially if that data never really got
used.

Let's think about more future-proof stats solutions instead of keeping
all these hacks.

Fixes #1415
2018-04-20 14:49:30 +02:00
Mathieu Pillard af4d84788c Refactor reviewer permission checks to allow Content/Post/Theme reviewers to access more tools 2018-03-30 12:31:30 +02:00
Mathieu Pillard 61a2893461 Remove addons_reviewer_required decorator, it's not specific enough
Now that we have post-reviewers, content reviewers, legacy reviewers,
we want to get rid of this old decorator and do something a little
more fine-grained
2018-03-29 16:23:27 +02:00
Mathieu Pillard f393b21d53 Send reviewers notifications to all kinds of reviewer, not just legacy 2018-01-29 13:57:20 +01:00
Mathieu Pillard f2b0b8781c Fix flake8 errors 2018-01-23 12:47:14 +01:00
Mathieu Pillard 8931c9fd23 Implement extra inline actions on the review page for reviewers and admins
- Subscribing to notifications
- Force disabling/enabling of an add-on (admins)
- Clear needs admin code/content review flag (admins)
2018-01-19 16:25:25 +01:00
Christopher Grebs 57915e2480
Add isort to our codebase. (#7118)
* Add isort to our codebase.

This is the first draft, please feel free to discuss this but I'm
generally open to change that style later on.

I just want to start making more and more of our code-style a rule
instead of something we have to take care of during code reviews.

* Ignore safe_xml file

* Don't change safe_lxml_etree

* Fix import unifification going bonkers, I don't blame isort though, this was creepy.

* Fix signin.test_views

* More flake8

* Use style number 4, hanging grid

* django group only contains django now, move above 3rd party group

* Remove pytest-isort for now to avoid isort being imported during tests.

isort has a super bad module that sets the defaultsystemencoding to
utf-8 and breaks our tests that ensure that our settings are *never*
unicode strings. If the default system encoding is set to utf-8 these
tests just work since the bytestring will be implicitly encoded to utf-8
instead of ascii which is the python2 default.

https://github.com/timothycrosley/isort/blob/develop/isort/pie_slice.py#L145
2018-01-08 12:05:14 +01:00
pyup.io bot 85c84cc1ad Update elasticsearch-dsl to 5.4.0 (#7106)
* Update elasticsearch-dsl from 5.3.0 to 5.4.0

* Remove legacy 'Result' usage.

* There is no such thing as -_score, see elastic/elasticsearch-dsl-py/#458 for more details.
2017-12-14 16:02:29 -06:00
Christopher Grebs b675677a7a
Expose page_count in pagination api. (#6982)
* Expose page_count in pagination api.

Fixes #6919

* Add docs
2017-11-22 15:03:09 +01:00
Andrew Williamson e24e9c680d
Fix static theme deletining Categories from the DB on change (#6934) 2017-11-16 12:31:54 +00:00
Mathieu Pillard 0af406cbdc
Rename `reviews` to `ratings` internally (#6776)
* Move 'reviews' to 'ratings' to avoid confusion with 'reviewers'
* Change ratings URL names
* Rename Review* models/forms/etc to Rating*
* Rename total_reviews/text_reviews_count/ratings
* Rename activity constants
2017-11-13 18:31:18 +01:00
Christopher Grebs 708a66cad6
Configure max_result_window during reindex, don't return 'next' if max-window is exceeded, raise better error message. (#6893)
* Configure max_result_window during reindex.
* don't return 'next' if max-window is exceeded, raise better error message.

Fixes #6703
Fixes #6703
2017-11-13 18:00:47 +01:00
Christopher Grebs 2573ea4a9c
No bare exception catching anymore. 2017-10-30 10:54:02 +01:00
Mathieu Pillard d2411fd0b6 Rename editors to reviewers everywhere except in the URLs
URLs to follow in a later commit, it will need redirects etc.
2017-10-23 15:55:32 +02:00
Mathieu Pillard 2c4f80df0e Add test proving we gzip API endpoints 2017-10-19 12:50:11 +02:00
Mathieu Pillard 04e14dafee Enable Gzip for API responses 2017-10-18 18:13:47 +02:00
Andrew Williamson 29fe2a1c9f remove the unused /internal/ api (#6666) 2017-10-12 18:20:16 +01:00
Andrew Williamson 36908068fd add contributor support to API (#6420) 2017-09-15 14:36:05 +01:00
Mathieu Pillard ddbec5c369 Don't convert Persona.theme_data to string if it's None (#6292)
Don't convert Persona.theme_data to string if it's None

Avoids returning description: "None" in json representation of
theme_data later.
2017-09-04 12:25:48 +02:00
pyup.io bot e2536ffcc2 Update djangorestframework to 3.6.4 (#6223)
* Update djangorestframework from 3.6.3 to 3.6.4

* fix test fails in drf 3.6.4

* we can't set Field.context any more as @cached_property to @property
2017-08-29 23:01:44 +08:00
Christopher Grebs 5156d7f418 Unify ESPaginator implementations. (#6152)
* Unify ESPaginator implementations.

This adds a `legacy_compat_mode` for our old search API but perfectly
applies max-window-result limitation fixes from the new search api.

Fixes #6083
Fixes #6053

* Fix flake8

* Fix flake8

* Add documentation, reverse compat argument

* Split up pagination into api.pagination and amo.pagination utils

* Fix another import
2017-08-11 16:54:28 +02:00
Christopher Grebs 2ee6be8e4b Merge pull request #5234 from mozilla/try-elasticsearch-latest
Update to ElasticSearch 5.x
2017-07-25 19:31:35 +02:00
Andrew Williamson 04e09fe6f4 Add Abuse reporting (#5975) 2017-07-25 15:29:44 +01:00
Christopher Grebs 42f06f2a73
Merge branch 'master' of github.com:mozilla/addons-server into try-elasticsearch-latest 2017-07-24 12:30:52 +02:00
Mathieu Pillard fcf94198dc Add search autocomplete API
It's based on the regular search API, but fetches less data and
pagination is not supported, the number of results will always be
10 max.
2017-07-18 18:31:39 +02:00
Mathieu Pillard 218c0c75df Fix some django deprecation warnings (#5811)
* Replace SortedDict with OrderedDict

* Replace get_field_by_name() by get_field()

* Consider warnings as errors to catch DeprecationWarnings

* Upgrade pytest django, since it generates a lot of deprecation warnings

* Ignore DeprecationWarning from django-csp

* Replace old option parsing syntax in management commands

* Replace request.REQUEST with request.POST

* Replace custom sql to create indexes by model options

* Replace get_all_field_names() with get_fields()

* don't keep this

* Try removing the create-db, we're having errors at teardown

* Fix commands args parsing

* Re-consider DeprecationWarnings as errors

* Remove usage of Context()

* Fix DeprecationWarning caused by paypal PaypalError self.message

* Fix linter test using exception.message

* Fix mock to prevent passing a callable to a queryset filter

* Remove reference to non-existent fixture

* django.forms.util module has been renamed. Use django.forms.utils instead

* (WIP) Support zh-hant & zh-hans instead of zh-TW and zh-CN, respectively.

* Don't pass callable to queryset

* ignore jwt deprecation warnings

* Don't use TestCase.urls anymore

* test against exception message directly

* Simplify nested context managers

* Restore this usage of Context(), it's still valid

* Restore setup.cfg

* Revert "(WIP) Support zh-hant & zh-hans instead of zh-TW and zh-CN, respectively."

This reverts commit 7d82b59850.

* fix flake8
2017-07-03 19:45:24 +02:00
Christopher Grebs b90bf13922 Merge pull request #5791 from mozilla/1573-implement-django-jinja
Loads of clean-ups along the way.

Fixes #1573

* Moves all helpers modules to templatetags.jinja_helpers - there are a few things in there that aren't jinja related so there'll be a follow-up to split that later
* Update Jinja2 to 2.9.6
* Add django-jinja 2.3.1
* move some jingo-minify helpers to olympia.lib to avoid any jingo imports
* unified |f and |fe helpers into one |format_html helper that always escapes everything unless the input is already |safe

* Move helpers, add requirements, fix imports.
* Give backend a proper name
* Port f and fe filters from jingo
* Make start porting reviews jinja helpers module, make first test pass
* Get a handful more tests working, get rid of get_env, more and more jingo calls.
* Disable extension matching, render .txt templates too, fixes more stats tests
* Fix csv_header template to produce some reasonable and csv parsable
* Set trim_blocks to be compatible with jingo
* Unify |f and |fe into one |format that simplifies escaping rules. Update tests.

I think having one unified |format filter is beneficial, especially
given that our current escaping rules were kinda complicated and allowed
for seriously dangerous combinations even with autoescape activated.

Now everything passed as an argument to |format is explicitly escaped
unless marked as |safe, there's no way around that anymore.

* Naive first version using |format instead of |f and |fe, might need more review.
* Fix format for unicode strings
* Rename |format to |format_html
* Move nl2br_xhtml to amo.jinja_helpers, use it in all our templates.
* Move datetime filter to our code temporarily, fix mocks, fix recursive error
* Move csrf call to django_jinja csrf_token tag, fix addons templatetags
* Fix |class_selected usage, fix render_with to get registered
* Remove hack from zadmin, fix zadmin templatetags
* Fix user delete photo test, don't rely on proper context updates that happen in order.
* Fix more nl2br tests
* Fix detail page escape, django escapes differently than jinja
* Remove context from edit_review_reply_form
* Fix date created format filter usage
* Remove templates setting user, fix can_review
* Fix collect_add_widget to not inherit the global context
* Remove happy unicode client
* Cleanup can_review, add tests
* Fix tests, django use different html character for double quote escaping
* Switch to firefox latest to check ui-tests
* Cleanup and fix do_truncate
* Remove jingo, copy jingo-minify helpers that depend on jingo to our lib for now
* Rename nl2br_xhtml -> nl2br
* Jinja 2.9 compat for reviews truncate filter
* Don't use TEMPLATE_DEBUG
* Set default value for q, happens on index page.
* Fix jinja2 formatting with newstyle gettext
2017-06-30 17:57:31 -07:00
Christopher Grebs aae2f69cca Update tests, fix elasticsearch-py/dsl usage.
* Replace BaseTestCase usage with our TestCase in tests that need the db
* BaseTestCase does not mock ES, but those tests can trigger ES requests
 by doing saves.
* Use Q instead of F
* Start getting the first few tests working
* Upgrade elasticsearch libs to latest versions
* Attempt to fix mapping deprecation warnings, stored fields, and how filters work
* Fix get_es_filter
* Temporary fixes and debugs to get more tests to pass
* Enable custom index settings again
* Add comment, questioning custom index settings
* Fix addons.test_indexers
* Fix stats mapping
* Fix result hit passing around the system
* Fix search filter tests
* Make sure all changes are properly flushed before emptying the index
* Explicitly refresh after creating a new add-on in filter_by_category
* Try and fix tags boosting, this is untested though...
* Start fixing filtered referencing tests...
* Fix fields vs source, es5 only allows returning fields via _source unless they're explicitly stored in the mapping which is not recommended.
* More type: phrase -> match_phrase
* Fix ListSearchResults hit flattening
* Fix 'and' filters
* Fix source filtering for .values_dict()
* Improve debugging, fix source filtering, fix multiple filter handling
* Fix tag boosting in legacy search views.
* Implement explicit query extension to implement tag matching.
* Fix test_and
* Correctly retrieve stored fields in zadmin compat_results
* Make stats views compatible with new es API.
* Fix view themes with new ES API
* Fix elasticsearch commands, reindex and tests
* Fix reindex cron
* Fix test for fuzzy matching.
* We had prefix_length=4 since ages but apparently it didn't work as expected?
* Fix extra_filter_or
* Lots of test fixes to amo.test_search
* Fix compatibility report tests by calling setUp() properly
* Don't nest tags boost in another list
* Fix legacy api test. There is only one add-on matching 'Firefox' but two matching 'Fox'... don't ask me why this ever worked... probably magic?
* Fix deprecated usage of in, use terms instead.
2017-06-16 12:03:56 +08:00