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

Services: Records: Raise CommunityNotSelectedError when community is … #288

Conversation

sakshamarora1
Copy link

@sakshamarora1 sakshamarora1 force-pushed the feature/require_community branch from 9c6b123 to eec0529 Compare September 16, 2024 15:22
Comment on lines +382 to +386
if (
current_app.config["RDM_RECORD_ALWAYS_IN_COMMUNITY"]
and len(draft.parent.communities.ids) == 0
):
if not self.check_permission(identity, "publish", record=draft):
Copy link
Contributor

Choose a reason for hiding this comment

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

to improve the readability:

Suggested change
if (
current_app.config["RDM_RECORD_ALWAYS_IN_COMMUNITY"]
and len(draft.parent.communities.ids) == 0
):
if not self.check_permission(identity, "publish", record=draft):
community_required = current_app.config["RDM_RECORD_ALWAYS_IN_COMMUNITY"]
community_missing = len(draft.parent.communities.ids) == 0
can_publish = self.check_permission(identity, "publish", record=draft)
if (
community_required and community_missing and not can_publish
):

also not ideal, in some cases we check the permissions for publish twice (second time in line 388)

# If config is True and there are no communities selected
# Then, check for permissions to upload without community
if (
current_app.config["RDM_RECORD_ALWAYS_IN_COMMUNITY"]
Copy link
Contributor

Choose a reason for hiding this comment

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

the configuration variable is declared in rdm-records, therefore this module knows nothing about it if they are not installed together.
In addition, drafts resources does not know anything about invenio-communities, therefore this check should be done in a place that is aware of both drafts and communities

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

Successfully merging this pull request may close these issues.

Require a community when uploading
2 participants