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

refactor: Link landscapes directly to shared files, links and visualizations #904

Merged
merged 11 commits into from
Oct 24, 2023

Conversation

josebui
Copy link
Contributor

@josebui josebui commented Oct 17, 2023

terraso_backend/apps/shared_data/views.py Outdated Show resolved Hide resolved
Comment on lines +37 to +42
def is_user_allowed_to_view_data_entry(data_entry, user):
shared_resources = data_entry.shared_resources.all()
for shared_resource in shared_resources:
if is_target_member(user, shared_resource.target):
return True
return False
Copy link
Member

Choose a reason for hiding this comment

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

question: can there be a case where there are multiple shared resources and the user is only a member of one of them? what happens then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paulschreiber Yes, that can happen, so if the user has access to at least one of the targets where the resource is shared they can view it, that is why the algorithm exists early inside the for loop if the user is a member of any target.

group = Group.objects.get(slug=group_slug)
except Group.DoesNotExist:
target = model_class.objects.get(slug=target_slug)
except Exception:
Copy link
Member

Choose a reason for hiding this comment

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

question: can you specify a more specific exception type?

Copy link
Contributor

@david-code david-code left a comment

Choose a reason for hiding this comment

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

Looks good to me

Comment on lines +47 to +51
def resolve_source(self, info, **kwargs):
return self.source

def resolve_target(self, info, **kwargs):
return self.target
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Curious why these resolve methods are necessary, is this something to do with the ContentType model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@david-code Yes, this has to do with the generic relationship, graphene is not able to do this automatically so it expects this to be defined explicitely

@josebui josebui requested a review from paulschreiber October 23, 2023 16:22
@josebui josebui force-pushed the refactor/landscapes-shared-files branch from 8800c53 to ed3430a Compare October 24, 2023 16:46
@josebui josebui merged commit 3685a2e into main Oct 24, 2023
6 checks passed
@josebui josebui deleted the refactor/landscapes-shared-files branch October 24, 2023 18:58
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.

3 participants