Commit Graph

636 Commits

Author SHA1 Message Date
Sagirov Eugeniy
8f88422c4a test: prepare tests for removing support for children in Old Mongo 2022-10-28 11:43:20 -04:00
Tim McCormack
4ecd9fe683 feat!: Delete all non-legacy IP code (#31000)
The IP chain code has moved to edx-django-utils—except for the legacy-IP code,
which is now in a new module. This will allow other IDAs to use the IP code.

Commit includes some adjustments to the toggle annotation.

Part of <https://github.com/openedx/edx-django-utils/issues/241>.
2022-09-21 14:11:34 +00:00
Raymond Zhou
aafac8f69b Revert "feat: TNL-10051 blockstore API perf instrumentation" (#30885) 2022-08-22 16:51:53 -04:00
Bernard Szabo
d58607ea2d feat: TNL-10051 reorder import statements
import logging must come near top
2022-08-22 13:19:53 -04:00
Bernard Szabo
e4d5de09da feat: TNL-10051 fix whitespace violation
Need two blank lines, not one
2022-08-22 12:55:50 -04:00
Bernard Szabo
2a9ce209f1 feat: TNL-10051 blockstore API perf instrumentation
Log before & after making blockstore (Django) API calls to get performance from timestamps
2022-08-22 12:22:20 -04:00
Robert Raposa
2af65d1b77 feat: add monitoring for users across requests (#30795)
We already add the user id (imperfectly) to many requests.
However, when a user starts off unauthenticated, it is not
possible to correlate to those requests. Adding the raw
IP chain provides that possibility. See new custom attribute
ip_chain.raw.
2022-07-28 13:45:34 -04:00
Mohammad Ahtasham ul Hassan
44fa09eba5 refactor: refactor discussions_xblock (#30636)
JIRA: https://openedx.atlassian.net/browse/BOM-2580
This PR aims at refactoring the discussion xblock sub project and moving it within the xmodule directory effectively removing its position as a sub project within edx-platform
2022-06-27 17:11:56 +05:00
Eugene Dyudyunov
b4fecd620b refactor: rename toggle_warnings to toggle_warning (#30458)
Rename toggle_warnings to toggle_warning for consistency with setting_warning.
2022-05-24 11:47:31 -04:00
Kyle McCormick
25df9ca420 refactor: make safe_lxml an ordinary folder in openedx/core/lib (#25689) 2022-05-24 15:35:23 +05:00
Demid
a4ec4c1b8e refactor: Delete XModule classes (#30262)
Removes XModule, XModuleDescriptor, ProxyAttribute classes and their usages.
2022-05-10 19:09:11 +02:00
Eugene Dyudyunov
289e682b8f FC-0001: Remove old EdxRestAPIClient usage across the platform (#30301)
* refactor: remove EdxRestAPIClient

* test: update tests according to EdxRestAPIClient removal

* fix: remove unused import
2022-05-09 12:48:26 -04:00
Eugene Dyudyunov
f262d64ad4 FC-0001: enterprise dependencies for EdxRestAPIClient replacement (#30240)
* refactor: enterprise dependencies for EdxRestAPIClient replacement

This is a part of https://github.com/openedx/public-engineering/issues/42

- add settings for enterprise-backend-service DOT application
- update utils used by enterprise to get rid of EdxRestAPIClient
- original utils stays in the code (to keep edx-platform api
clients working) till the
https://github.com/openedx/public-engineering/issues/39 deprecation
work will be done

* fix: fix typo in the docstring
2022-04-21 15:28:22 -04:00
Kaustav Banerjee
702866b225 feat: delete XModuleDescriptorToXBlockMixin (#29927)
This:
1. Deletes XModuleDescriptorToXBlockMixin
2. Deletes `metadata_traslations` and `_translate()` from `XmlParserMixin`,
    and all related implementations.
3. Removes translations of deprecated OLX attributes during import/export:
    <old_attr> : <new_attr>
    - 'slug' : 'url_name'
    - 'name' : 'display_name'
    - 'id' : 'discussion_id' (Discussion XBlock)
    - 'for' : 'discussion_target' (Discussion XBlock)
    - 'attempts' : 'max_attempts' (CAPA)
2022-04-21 16:15:00 +01:00
Jillian Vogel
8b77638bf0 test: refactors blockstore integration tests to run as unit tests.
Tests which @requires_blockstore (i.e. the Blockstore service) have
been made to run as a unit test using the installed Blockstore app, and
will be run by the platform CI.

The Blockstore service tests can still be run manually by setting
EDXAPP_RUN_BLOCKSTORE_TESTS=1

Related fixes:

* adds blockstore bundle storage settings
* let the studio devstack and test servers serve static files from
  the /media URL This allows the blockstore/content libraries API to
  serve blockstore assets in dev.
* Wrap ContentLibrary creation in an atomic transaction, so that if it
 fails, the related bundle can be deleted directly from the database
  during the exception handler. (Previously, we called a REST API which
  deleted it as part of a separate service.)
2022-04-21 09:39:59 +01:00
Jillian Vogel
7d81c3e671 test: minor fixes to requires_blockstore tests
These tests aren't run as part of the CI, and so have been failing for
an unknown time.
2022-04-21 09:39:59 +01:00
Jillian Vogel
cfd53aff70 refactor: installs blockstore into edx-platform
* adds blockstore as a requirement and an installed app, with
  configurable bundle storage settings.
* adds waffle switch and setting to allow use of blockstore's python API
  instead of REST API in live testservers and in production.
* adds database router which, when a `blockstore` DATABASE connection is
  configured, allows the platform to use the blockstore service's
  database instead of the default edxapp database.
* replaces blockstore_api exceptions and models with blockstore.app.api classes
* minor fixes to the blockstore_api to make the Blockstore REST API
  return data packaged the same as the Blockstore Python API.
2022-04-21 09:39:54 +01:00
Tim McCormack
a251d18281 feat!: Use more-trusted IP in rate-limiting (#241)
Previously, our rate-limiting code trusted the entire `X-Forwarded-For`
header, allowing a malicious client to spoof that header and evade
rate-limiting. This commit introduces a new module and setting
allowing us to make a more conservative choice of IPs.

- Create new `openedx.core.djangoapps.util.ip` module for producing
  the IP "external chain" for requests based on the XFF header and the
  REMOTE_ADDR.
- Include a function that gives the safest choice of IPs.
- Add new setting `CLOSEST_CLIENT_IP_FROM_HEADERS` for configuring how
  the external chain is derived (i.e. setting the trust
  boundary). Currently has a default, but we may want to make it
  mandatory in the future.
- Change `django-ratelimit` code to use the proximate IP in the external
  chain -- the one just outside the trust boundary.

Also:

- Change `XForwardedForMiddleware` to use more conservative choice for
  its `REMOTE_ADDR` override
- Other adjustments to `XForwardedForMiddleware` as needed in order to
  initialize new module and support code that needs the real
  `REMOTE_ADDR` value
- Metrics for observability into the change (and XFF composition)
- Feature switch to restore legacy mode if needed

This also gives us a path forward to removing use of the django-ipware
package, which is no longer maintained and has a handful of bugs that make it
difficult to use safely.

Internal ticket: ARCHBOM-2056
2022-04-20 13:46:58 +00:00
Demid
16fa97dde4 feat: deprecate filestore
This:

1. Removes the `filestore` property from the `ModuleSystem` in favor of
   the `runtime.resources_fs` property.
   In the original code, `filestore` is equal to
   `DescriptorSystem.runtime.resources_fs`. It's safe to replace it with
   `ModuleSystem.runtime.resources_fs` because both runtimes are combined
   using the `CachingDescriptorSystem`. It provides the `resources_fs` property
   that uses the same file storage.

2. Renames `filestore` argument to `resources_fs` in the `LoncapaSystem`
   constructor.

3. Adds the deprecated `filestore` property to the `ModuleSystemShim`
   and `RuntimeShim`.
2022-04-14 14:45:05 +02:00
Saad Yousaf
fd60d8c8cf fix: revert discussion xblock from MFE view to legacy view. (#30141)
Co-authored-by: SaadYousaf <saadyousaf@A006-00314.local>
2022-03-30 11:31:45 +05:00
Tim McCormack
813b403575 fix: Use more accurate attr name for IP chain size (#30106)
XFF is just part of the chain; record the length of the whole chain instead
(which is always one larger).

Also include junk in one of the test values for realism.
2022-03-22 15:33:35 +00:00
Tim McCormack
c3bc68abc1 feat: Add monitoring for X-Forwarded-For header length (#30090) 2022-03-18 15:31:27 +00:00
Robert Raposa
9fa79809d8 refactor: CookieMonitoringMiddleware moved to edx-django-utils
The CookieMonitoringMiddleware and its related script
moved to edx-django-utils.

ARCHBOM-2054
2022-03-17 16:59:00 -04:00
Robert Raposa
23a5f9500e fix: process cookie headers at request time (#30068)
Processing cookies at response time included cookies
that were temporary, like the JWT cookie that is
created by the server by combining the JWT header-payload
and JWT signature cookies. Since we are trying to monitor
the cookie header, we do not want to process this cookie.

However, since we want to include the user id in the logging
message, we delay the logging until response time.

Also, fixed docstring which mislabeled a custom attribute.

ARCHBOM-2055
2022-03-15 15:45:21 -04:00
Kaustav Banerjee
c48c655998 refactor: deprecates replace url related properties from ModuleSystem
Deprecates the following attributes from ModuleSystem:
 * replace_urls
 * replace_course_urls
 * replace_jump_to_id_urls

A new ReplaceURLService is created as replacement with a unified replace_urls method
2022-03-14 09:35:41 -04:00
Arslan
2bc6a8ac0a fix: Use PipelineManifestStorage instead of PipelineCachedStorage 2022-03-14 12:57:23 +05:00
Robert Raposa
78ba9f09a1 feat: add corrupt cookie header monitoring (#30039)
In case of unusual cookie headers containing "Cookie ",
add custom attributes for monitoring:
- cookies.header.corrupt_count
- cookies.header.corrupt_key_count

See annotation documentation for more details.

Separately, updated to skip cookie log sampling for
0 size cookie header.

ARCHBOM-2055
2022-03-11 14:36:26 -05:00
Robert Raposa
29e50710dc feat: enhance cookie monitoring and logging
Contains a number of cookie monitoring changes.

Enhancements:
- Add sampling capability for cookie logging on headers
 smaller than the threshold. For details, see
 COOKIE_SAMPLING_REQUEST_COUNT.
- Add cookie header size to log message.
- Sort logged cookies starting with largest cookie.
- Move logging from Middleware request processing
 to response processing to ensure the user id is
 available for logging for authenticated calls.
- Added cookies.header.size.computed to check
 if there are any large hidden duplicate cookies.
 Can be compared against the cookies.header.size
 custom attribute.
- Add delimiters into logs to make it simpler to parse
 when the logging tools accidentally exports multiple
 log lines together.

Removed:
- Legacy cookie capture code. This code was dangerous to
  to enable and provided more limited insight than the
  newer logging, so this was removed to simplify the code.

Other refactors:
- Switched Middleware to use new Django format, rather
 than the Mixin.
- Moved tests to its own test class. Note: this
 middleware is likely to move to a separate
 library.

ARCHBOM-2055
2022-03-09 20:39:27 -05:00
Mohammad Ahtasham ul Hassan
68e0885ca8 fix: fixed django4 warnings (#29644) 2022-03-07 15:50:17 +05:00
Mohammad Ahtasham ul Hassan
dd488a76d1 fix: fixed django40 warnings (#29641)
* fix: fixed django4 warnings
Co-authored-by: UsamaSadiq <usama.sadiq@arbisoft.com>
2022-02-25 16:24:51 +05:00
Tim McCormack
e218b71601 feat: Just log cookie sizes when over threshold (no encrypted contents) (#29938)
This should really be all we need for most cases, and we don't want to
emit sensitive data more than necessary, even encrypted. If we need to
inspect one cookie in particular, we can add special logging for that.

Also, change to greater-than-or-equal for threshold to match setting docs.

ref: ARCHBOM-2042
2022-02-18 19:01:37 +00:00
Michael Terry
cb1bb7fa64 test: switch default test store to the split store
It's long past time that the default test modulestore was Split,
instead of Old Mongo. This commit switches the default store and
fixes some tests that now fail:
- Tests that didn't expect MFE to be enabled (because we don't
  enable MFE for Old Mongo) - opt out of MFE for those
- Tests that hardcoded old key string formats
- Lots of other random little differences

In many places, I didn't spend much time trying to figure out how to
properly fix the test, and instead just set the modulestore to Old
Mongo.

For those tests that I didn't spend time investigating, I've set
the modulestore to TEST_DATA_MONGO_AMNESTY_MODULESTORE - search for
that string to find further work.
2022-02-04 14:32:50 -05:00
Jillian Vogel
2173a98ef8 refactor: deprecates ModuleSystem properties for code sandboxing and cache
* Deprecates ModuleSystem can_execute_unsafe_code, get_python_lib_zip and cache properties
* Adds a new CacheService and SandboxService to provide the deprecated property
* Adds tests for the added CacheService and SandboxService
* Updates the ModuleSystemShim tests in Lms and Studio
2022-01-25 14:42:39 +10:30
Kshitij Sobti
2bbf447ab5 feat: banner for staff users that displays a message for testing the new MFE experience (#29698)
Adds a new banner allowing staff users to preview and switch between the new and legacy forum experience.
2022-01-18 11:18:59 +05:00
Rebecca Graber
0e9499de7d feat: log an encrypted string of the full cookie header when over threshold (#29735)
* feat: log an encrypted string of the full cookie header when over threshold
2022-01-10 13:02:47 -05:00
Aarif
6c5b1ef551 fix: updated the imports order to fix quality failure (#29722) 2022-01-06 11:39:33 -05:00
Kshitij Sobti
b5f045dc5f fix: update discussions MFE path [BD-38] [TNL-9347] (#29691)
* fix: update discussiosn MFE path

* squash!: fix tests
2022-01-06 18:34:53 +05:00
Ned Batchelder
e39f9c503a build: suppress Django deprecation warnings (#29528)
Suppress them both in tests (via setup.py and pytest.ini)
and in management command & application runs
(via logsettings.py).

Developers aren't looking at these warnings; they'll be dealt with in a
formal process for upgrading Django.  Suppress them for now so that
important information isn't lost in the noise.
2021-12-15 10:45:12 -05:00
Jawayria
dba7d78c74 chore: Applied lint-amnesty on openedx/core/lib 2021-12-02 15:11:13 +05:00
Jillian Vogel
ad5ad72273 [BD-13] Deprecate ModuleSystem.render_template (fixed) (#29354)
* refactor: deprecates ModuleSystem.render_template

in favor of the added MakoSystem render_template method.

Related changes:
* Adds the MakoService to the StudioEditModuleRuntime,
  PreviewModuleSystem, LmsModuleSystem, and XBlockRuntime
* MakoService constructor takes a `namespace_prefix` string, so that the
  CMS PreviewModuleSystem can render to LMS templates, without needing
  the special render_from_lms helper method.
* ModuleSystem.render_template becomes a read-only property, so the
  constructor calls and test module systems are updated accordingly.
* Adds tests for the MakoService and module system shims.

(cherry picked from commit 457f959356)

* refactor: use MakoService.render_template to remove deprecation warnings

from block code.

(cherry picked from commit 8d62d337f5)

* refactor: use MakoService.render_template to remove deprecation warnings

from test code.

(cherry picked from commit 26b43465a4)

* test: Adds a test to verify the bug introduced by the previous changes

The AuthoringMixin is automatically added to all XBlocks (see
settings.XBLOCK_MIXINS), and AuthoringMixin.visibility_view expects the
"mako" service.

This test verifies the bug by testing the PureXBlock, which does not
require the "mako" service, and so fails when the visibility_view is
rendered.

* fix: AuthoringMixin needs mako service

which fixes the visibility_view for XBlocks which don't explicitly
require the mako service.

Also removes the unneeded class property _services_requested from
AuthoringMixin and StudioEditableBlock. This property is better provided
by the XBlockMixin class.
2021-11-29 14:42:52 -05:00
Kshitij Sobti
c8bd924e23 feat: Add support for using the discussions MFE UI instead of existing UI [BD-38] [TNL-9228] (#29285)
* feat: Add support for using the discussions MFE UI instead of existing UI

Adds a new course waffle flag that when set along with the discussions MFE URL shows the discussions MFE UI instead of the regular UI.

* test: add tests

* squash!: more consistent url name
2021-11-23 14:56:25 +05:00
Justin Lapierre
f6f3a79a15 Revert "[BD-13] Deprecate ModuleSystem.render_template" 2021-11-16 15:16:08 -05:00
Ned Batchelder
d9dd10dc97 style: code cleanups from Steven Burch (#29292)
* chore: update deprecated import from collections

* chore: remove outdated imports from markdown library

as it hasn't been supported since 2.0.3 and we're on 3.x.
This was deprecated at least as early as 2012!

* docs: add docstring and remove lint-amnesty to markdown plugin

* chore: remove deprecated etree import

* style: remove unnecessary-comprehension for sets

* style: resolve a number of amnestied pylint complaints

Co-authored-by: stvn <stvn@mit.edu>
2021-11-10 07:11:57 -08:00
Jillian Vogel
8d62d337f5 refactor: use MakoService.render_template to remove deprecation warnings
from block code.
2021-11-09 14:03:54 +10:30
Kshitij Sobti
ff61434893 feat: Add a new way to enable/disable teams [BD-38] [TNL-9175] [BB-5066] (#29099)
* feat: Add a new way to enable/disable teams

Adds a new mechanism for enabling/disabling the team feature in a course using an 'enabled' field to the teams config.
If this field is set to true, teams is enabled (team sets/groups) still need to be defined. If this is set to false then teams is disabled whether or not team sets are defined.

* fix: review feedback
2021-11-01 17:12:06 +05:00
Agrendalath
e633cc9c24 feat: support adding custom editors to Studio
This:
1. Introduces a variable for the Course Outline view in Studio.
   A custom theme can override it to add new editors.
2. Exports a function for creating new editor modals.
   A custom theme can use it to create editors without adding boilerplate code.
3. Adds a pluggable override for XBlock fields that are passed to the Studio.
   Without this, custom editors in Studio cannot retrieve values of XBlock fields.
2021-10-27 13:35:19 -04:00
M. Zulqarnain
43008723be feat: New codemods on OpenedX 3 (#28778) 2021-10-22 13:55:51 +05:00
Kshitij Sobti
2ecb4daece fix: update course URL match pattern to also match learning MFE (#29050)
The learning MFE paths include /course/{course_id} which doesn't match /courses/{course_id} which is what the regex expects. This causes issues with the Wiki when when accessed from the learning MFE doesn't detect that course it's related to in the middleware.
2021-10-21 20:24:40 +05:00
Usama Sadiq
9ee8df0980 fix: Remove pylint constraint and fix warnings (#28646) 2021-10-20 23:00:13 +05:00
Robert Raposa
f3e5838b89 docs: update unexpected_multiple_exceptions comment (#28939)
Update the unexpected_multiple_exceptions comment based on findings
from monitoring since this was originally released.
2021-10-05 14:08:22 -04:00