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

825 add toggle to add/remove current site to/from element sites #875

Open
wants to merge 22 commits into
base: dev-2.2.0
Choose a base branch
from

Conversation

MyPyDavid
Copy link
Member

@MyPyDavid MyPyDavid commented Dec 8, 2023

Description

The new endpoints that add or remove the current site from the sites of an element are:

Django back-end

questions

  • PUT /api/v1/questions/catalogs/{id}/toggle-site/

tasks

  • PUT /api/v1/tasks/tasks/{id}/toggle-site/

views

  • PUT /api/v1/views/views/{id}/toggle-site/

These are defined in a new ViewSetMixin, ElementToggleCurrentSiteViewSetMixin in
rdmo/management/viewsets.py. This mixin has one action toggle-site and only for put is allowed.
It adds or removes the current site from the object, depending on whether is was there already or not (like a toggle).
For permissions it uses a new (rules-based) CanToggleElementCurrentSite permission class.

The mixin class could be simplified by removing the serializer_class and the get_queryset method.
Could we adapt the ElementSucces reducer to not need the serialized object for these actions?
Permissions could by checked right in the action methods by eg. test_rule().

React front-end:

  • new component: ToggleCurrentSiteLink in rdmo/management/assets/js/components/common/Links.js
  • added elementAction to storeElement and storeElementInit
  • the url routing is done in eg. the MultiSiteApi.js storeElement via the action

Related issue: #825

Motivation and Context

How has this been tested?

Screenshots (if appropriate)

Logged in as example-editor.
image

Types of Changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the contributor guide.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@MyPyDavid MyPyDavid changed the base branch from main to dev-2.2.0 December 8, 2023 17:31
@MyPyDavid
Copy link
Member Author

need to re-do the commits and add the tests but buttons seem to be working like this

@MyPyDavid MyPyDavid self-assigned this Dec 11, 2023
@MyPyDavid MyPyDavid force-pushed the 825-exclude-sites-assignment-from-protection-of-a-catalogue branch from 8b60c37 to 23767c6 Compare December 14, 2023 08:11
@MyPyDavid MyPyDavid changed the title 825 add toggle to add/remove current site to element sites 825 add toggle to add/remove current site to/from element sites Dec 14, 2023
@MyPyDavid MyPyDavid force-pushed the 825-exclude-sites-assignment-from-protection-of-a-catalogue branch from 23767c6 to 395ce52 Compare December 14, 2023 08:45
@MyPyDavid MyPyDavid added this to the 2.2.0 milestone Dec 14, 2023
@MyPyDavid MyPyDavid marked this pull request as ready for review December 14, 2023 10:58
@MyPyDavid MyPyDavid linked an issue Jan 4, 2024 that may be closed by this pull request
@MyPyDavid MyPyDavid force-pushed the 825-exclude-sites-assignment-from-protection-of-a-catalogue branch 3 times, most recently from 2bd6281 to c3abc7a Compare January 10, 2024 12:58
@MyPyDavid MyPyDavid force-pushed the 825-exclude-sites-assignment-from-protection-of-a-catalogue branch from c3abc7a to 64f1fec Compare January 10, 2024 16:25
Copy link
Member

@jochenklar jochenklar left a comment

Choose a reason for hiding this comment

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

Thanks for the work. I have some minor suggestions.

rdmo/management/assets/js/components/element/Catalog.js Outdated Show resolved Hide resolved
rdmo/questions/viewsets.py Outdated Show resolved Hide resolved
rdmo/management/assets/js/api/QuestionsApi.js Show resolved Hide resolved
const ToggleCurrentSiteLink = ({ has_current_site, locked, onClick, disabled }) => {
const className = classNames({
'element-btn-link fa': true,
'fa-plus-square-o': !has_current_site,
Copy link
Member

Choose a reason for hiding this comment

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

The icons are not super, but I don't have a better suggestion. Maybe the transition to material symbols will solve this at one point.

Copy link
Member

Choose a reason for hiding this comment

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

ok maybe like this?
image

I also think it is better when the toogle site link is not the first one.

Copy link
Member

Choose a reason for hiding this comment

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

fa-plus-square and fa-minus-square

rdmo/management/rules.py Outdated Show resolved Hide resolved
rdmo/management/rules.py Outdated Show resolved Hide resolved
rdmo/management/viewsets.py Outdated Show resolved Hide resolved
rdmo/core/permissions.py Outdated Show resolved Hide resolved
rdmo/management/assets/js/components/element/Catalog.js Outdated Show resolved Hide resolved
rdmo/management/assets/js/actions/elementActions.js Outdated Show resolved Hide resolved
rdmo/management/assets/js/api/ViewsApi.js Outdated Show resolved Hide resolved
rdmo/management/assets/js/api/MultiSiteApi.js Outdated Show resolved Hide resolved
rdmo/management/assets/js/api/MultiSiteApi.js Outdated Show resolved Hide resolved
rdmo/management/assets/js/components/common/Links.js Outdated Show resolved Hide resolved
const ToggleCurrentSiteLink = ({ has_current_site, locked, onClick, disabled }) => {
const className = classNames({
'element-btn-link fa': true,
'fa-plus-square-o': !has_current_site,
Copy link
Member

Choose a reason for hiding this comment

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

ok maybe like this?
image

I also think it is better when the toogle site link is not the first one.

const ToggleCurrentSiteLink = ({ has_current_site, locked, onClick, disabled }) => {
const className = classNames({
'element-btn-link fa': true,
'fa-plus-square-o': !has_current_site,
Copy link
Member

Choose a reason for hiding this comment

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

fa-plus-square and fa-minus-square

Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
… rename hasCurrentSite

Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
@MyPyDavid MyPyDavid requested a review from jochenklar May 15, 2024 15:02
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
@MyPyDavid MyPyDavid force-pushed the 825-exclude-sites-assignment-from-protection-of-a-catalogue branch from 65ef10e to 8757d2c Compare May 16, 2024 08:09
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this whole file to rdmo/core/tests/utils.py? I am not a big fan of to much indirection in tests (I got that from 2 scoops of django), but I guess it makes sense here. I a bigger test cleanup we could also move some of the constants to this file as well. Maybe a constants.py and a utils.py.

Another idea would be to use fixtures for this (the utils part).

return function(dispatch, getState) {
dispatch(storeElementInit(element))

dispatch(storeElementInit(element, elementAction))
Copy link
Member

Choose a reason for hiding this comment

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

I think elementAction is not needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude sites assignment from "protection" of a catalogue
2 participants