Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add taxonomies for org api #32871

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Jul 27, 2023

Description

This PR adds support for creating, viewing, updating and deleting Taxonomies for Organizations via REST APIs, with the permissions applied accordingly.

Supporting information

Testing instructions

  • Check the unit tests in test_views.py and test_rules.py are correct.
  • Run the unit tests

Manual check can be done in the CMS App:


Private-ref: FAL-3450

@rpenido
Copy link
Contributor Author

rpenido commented Jul 30, 2023

ToDo: Handle {"ENABLE_CREATOR_GROUP": False} when everything else is ok.
Done

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @rpenido , especially the tests!
Let me know if you have any questions or objections to the changes I've suggested?

cms/urls.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/models.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/models.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rest_api/v1/views.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rest_api/v1/views.py Outdated Show resolved Hide resolved
@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch from 750daaa to 0071e91 Compare August 1, 2023 19:29
requirements/edx/kernel.in Outdated Show resolved Hide resolved
openedx/features/content_tagging/models.py Outdated Show resolved Hide resolved
page_size = 100
max_page_size = 1000

pagination_class = TaxonomyPagination
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, didn't notice that the pagination was only added here instead of on the openedx-learning side..
Do you mind to create a small PR against openedx-learning that moves this over there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@rpenido rpenido Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToDo: remove pagination when the PR is merged:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR is merged and now available with openedx-learning==0.1.2.

If you run make requirements in your LMS shell, that should bump the installed version in the requirements/edx/* files.
And if you run into this issue, see these comments on stackoverflow:

Exception: Can not find valid pkg-config name.
      Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually

openedx/features/content_tagging/models.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/tests/test_rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/tests/test_rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/tests/test_rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
@openedx-webhooks
Copy link

openedx-webhooks commented Aug 3, 2023

Thanks for the pull request, @rpenido! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 3, 2023
@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch from 97fe65b to ef81ea8 Compare August 4, 2023 22:29
@rpenido
Copy link
Contributor Author

rpenido commented Aug 4, 2023

Hi @pomegranited! I reverted the changes that are not related to the Taxonomy model.

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rpenido , I've requested a few changes, and noted some things that I'd like to fix as part of a separate task.

I'm also awaiting word from Product on how they want the org content author permissions to work, something that came up in our last meeting. So this might sit in External Review for a little while before it can be merged.

But if you could address the requested changes, I'll work on the rest and let you know.

Thank you!

openedx/features/content_tagging/models/base.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rest_api/v1/filters.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rest_api/v1/views.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/rules.py Show resolved Hide resolved
openedx/features/content_tagging/rest_api/v1/filters.py Outdated Show resolved Hide resolved
openedx/features/content_tagging/tests/test_rules.py Outdated Show resolved Hide resolved
@rpenido
Copy link
Contributor Author

rpenido commented Aug 8, 2023

Hi @pomegranited!

I made the changes and also reverted some "style only" modifications to get a clear diff. Thank you for your input on that.

I will squash/rebase when we are ready to External Review!

@rpenido rpenido changed the title feat: add taxonomies for org api [wip] feat: add taxonomies for org api Aug 8, 2023
@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch 2 times, most recently from 9f89936 to 36f8dcc Compare August 9, 2023 13:25
@rpenido
Copy link
Contributor Author

rpenido commented Aug 9, 2023

Hi @pomegranited !
The change in permissions requested is here: b10b02a2288145408c9e6614bdf0d719c1f37f3f (including fixing the view tests and cleaning some code)
I cherry-picked the new test_rules.py and fixed it with the new conditions here: 3dccf60435e94d9b4ddf16d2f6b300866a690269

- [ ] ToDo: change the test_views to use helper functions
Is the proposal to make a helper function that checks list, get, edit, update, delete (for taxonomy, tag, objecttag), and then duplicate this function for each "user role"?
We will end up with multiple methods and views in the same test. I'm not sure about this one in the test_view context. Do you think this is the way to go?

@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch from 36f8dcc to 3dccf60 Compare August 9, 2023 13:41
Comment on lines 22 to 45
return queryset.filter(enabled=True).filter(
Q(
Exists(
TaxonomyOrg.objects.filter(
taxonomy=OuterRef("pk"),
rel_type=TaxonomyOrg.RelType.OWNER,
org=None,
)
)
)
| Q(
Exists(
TaxonomyOrg.objects.filter(
taxonomy=OuterRef("pk"),
rel_type=TaxonomyOrg.RelType.OWNER,
org__short_name__in=[
org.short_name
for org in Organization.objects.all()
if is_taxonomy_user_for_org(request.user, org)
],
)
)
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need the enabled filter here -- the rest of this org checking can go.

Suggested change
return queryset.filter(enabled=True).filter(
Q(
Exists(
TaxonomyOrg.objects.filter(
taxonomy=OuterRef("pk"),
rel_type=TaxonomyOrg.RelType.OWNER,
org=None,
)
)
)
| Q(
Exists(
TaxonomyOrg.objects.filter(
taxonomy=OuterRef("pk"),
rel_type=TaxonomyOrg.RelType.OWNER,
org__short_name__in=[
org.short_name
for org in Organization.objects.all()
if is_taxonomy_user_for_org(request.user, org)
],
)
)
)
)
return queryset.filter(enabled=True)

Taxonomy users include global staff and superusers, course creators who can create courses for any org and
content creators for this specific org.
"""
return is_content_creator(user, org.short_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted, we don't need any of this "is_content_creator" logic anymore. Only global staff + superusers can add/edit taxonomies, and anyone can view an enabled taxonomy, no matter its org.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch 2 times, most recently from 67ca1d8 to c81c7bd Compare August 10, 2023 16:24
@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch from 55696a8 to 210aed9 Compare August 15, 2023 22:27
@rpenido rpenido marked this pull request as ready for review August 18, 2023 21:16
@bradenmacdonald
Copy link
Contributor

@rpenido Please fix the failing test and then I can merge this.

@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch 2 times, most recently from 7ee6d0b to 3591589 Compare August 22, 2023 17:23
@rpenido
Copy link
Contributor Author

rpenido commented Aug 22, 2023

Hi @bradenmacdonald! Do you know how to make the tests run again here?

@bradenmacdonald
Copy link
Contributor

@rpenido They seem to be running now.

@rpenido
Copy link
Contributor Author

rpenido commented Aug 22, 2023

I think we are good now @bradenmacdonald! Thank you!

@yusuf-musleh
Copy link
Contributor

@bradenmacdonald I just rebased my PR open-craft#577 on @rpenido's work here. Was wondering if you'd like to take a take a look at it and merge it into this branch before merging this one in to master? Or are we better off doing it separately? The related openedx-learning PR openedx/openedx-learning#68 was already merged.

@bradenmacdonald
Copy link
Contributor

@yusuf-musleh If it's just those two lines of code that were already approved, please go ahead and merge into this branch. Hope that's OK with you @rpenido.

@rpenido
Copy link
Contributor Author

rpenido commented Aug 22, 2023

Of course @bradenmacdonald and @yusuf-musleh! Let's reduce the overhead and earn some time!

@yusuf-musleh
Copy link
Contributor

yusuf-musleh commented Aug 22, 2023

@bradenmacdonald @rpenido Sounds good, I just need to bump up the installed version of the openedx-learning package. I'm currently running make upgrade package=openedx-learning locally to get the updated requirement files, will push it to my PR and merge once I confirm the tests pass (they are failing because of that),

@yusuf-musleh
Copy link
Contributor

@bradenmacdonald Had to make a small change to the on the python API side and update the relevant tests. This is after the openedx-learning version upgrade. Tests should be fixed now, waiting for them to complete, then will merge, unless you have any issues with the additional changes I added.

@rpenido rpenido force-pushed the rpenido/fal-3449-taxonomy-view-management-apis branch from 07b8e9a to a19b2ea Compare August 23, 2023 12:07
# openedx-learning new version has some changes which are breaking quality tests
# See https://github.com/openedx/openedx-learning/pull/68 for the changes.
# It needs to be updated in a separate issue.
openedx-learning==0.1.2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradenmacdonald I removed this to make the tests pass. I'm not sure what "breaking quality tests" means here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpenido I believe that was because when my changes were merged to the openedx-learning repo, it contained changes that remove some kwargs from some functions that were being called in this repo, and that would cause the quality tests to fail (hence the version was pinned to not use the latest). Now that everything is being merged, this change should be fine, in fact, it is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yusuf-musleh!

@rpenido
Copy link
Contributor Author

rpenido commented Aug 24, 2023

Hi @bradenmacdonald!
Is there something we can do to help this get merged?

Thank you!

@bradenmacdonald
Copy link
Contributor

@rpenido Thanks for the ping; I actually didn't realize this was waiting for me. I'll merge it in 30 min.

@bradenmacdonald bradenmacdonald merged commit ecc4a0d into openedx:master Aug 24, 2023
43 checks passed
@bradenmacdonald bradenmacdonald deleted the rpenido/fal-3449-taxonomy-view-management-apis branch August 24, 2023 17:32
@openedx-webhooks
Copy link

@rpenido 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Tagging] Taxonomies for Org API
6 participants