-
Notifications
You must be signed in to change notification settings - Fork 0
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
story/VOGRE-14 #11
story/VOGRE-14 #11
Conversation
…oject import in view, need to remove redundancy and circular imports, make context consistent
…or directly from projects with add text
…aborator view and url, updated template
…ncorporate messages
annotations/views/project_views.py
Outdated
@@ -36,6 +36,7 @@ def view_project(request, project_id): | |||
order_by = request.GET.get('order_by', 'title') | |||
texts = project.texts.all().order_by(order_by)\ | |||
.values('id', 'title', 'added', 'repository_source_id') | |||
print(texts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
href="{% url "view_project" project.id %}"> | ||
{% if next_url %} | ||
<a class="list-group-item" | ||
href="{{ next_url }}?project_id={{ project.id }}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does the project.id
need to be passed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will redirect the user to the text with ?project_id=
which is later used by other views to retrieve the project id
repository = get_object_or_404(Repository, pk=repository_id) | ||
user = None if isinstance(request.user, AnonymousUser) else request.user | ||
project_id = request.GET.get('project_id') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge with line 234
# Filter texts within each collection that belong to the repository | ||
collection_texts = collection.texts.filter(repository=repository).order_by('-added') | ||
if collection_texts.exists(): | ||
texts_by_project[collection] = list(collection_texts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that all texts in a collection will be loaded here? Those should be paginated, since they might be a lot.
…o see if text is already associated with project, merged project id in context in repository_details view
annotations/exceptions.py
Outdated
|
||
# Get custom error message from the PermissionDenied exception | ||
# raise PermissionDenied("Custom message") | ||
error_message = str(exception) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if None
is passed as exception, this will make error_message
"None"
, won't it?
order_field = default_field | ||
order_direction = '' | ||
order_by = default_field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are two fields here that seem to hold the same value (order_field
, order_by
), why are they both required?
annotations/utils.py
Outdated
|
||
# Get order_by from request, default to default_field | ||
order_by = request.GET.get('order_by', default_field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you probably want to make 'order_by'
also a parameter (with a default value), so it could be used for requests with a different parameter name.
""" | ||
project = get_object_or_404( | ||
_annotate_project_counts(TextCollection.objects), | ||
pk=project_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm so confused by this, doesn't get_object_or_404
expect a class, not a queryset? A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_object_or_404
can also accept a queryset. The utility function _annotate_project_counts(TextCollection.objects)
returns an annotated queryset, where I have added fields like num_texts, num_relations, and num_collaborators. By passing this annotated queryset to get_object_or_404 ensures that these additional fields are included in the retrieved project object (mainly used fore rendering the project stats)
https://docs.djangoproject.com/en/5.1/topics/http/shortcuts/#get-object-or-404
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I think there needs to be a comment here, especially since it would be more obvious why you do that it here are many projects and you want to annotate them all, but this is only requesting one single one. It also doesn't help that it's the "TextCollection" class but the id is "project_id". So there should be an explanatory comment why this is used over just getting the counts directly from the requested project (the way it's written makes it a lot harder to understand what's going on).
user = None if isinstance(request.user, AnonymousUser) else request.user | ||
|
||
# Fetch text collections (projects) owned by the current user | ||
user_owned_collections = TextCollection.objects.filter(ownedBy=user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used anywhere?
if not project_id: | ||
return redirect(f"{reverse('list_projects')}?redirect_to_text_import=True&repository_id={repository_id}&group_id={group_id}&text_key={text_key}") | ||
|
||
print("project_id", project_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
|
||
# Allow GET requests for authenticated users | ||
if request.method in ['GET', 'HEAD', 'OPTIONS']: | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, why would it matter if this is a GET or POST request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, ok, I think I slowly understand, I think it's a naming issue. The class name suggests this will just check if the user is collaborator and owner, not that it checks specific texts for edit permissions (which I think this is doing?). Either it should check in general if the user can see/edit the text or the class name needs to be way more specific. In either case, the class name needs to be changed though.
annotations/views/rest_views.py
Outdated
# Check if user is owner or collaborator of the text's collection | ||
text = None | ||
if hasattr(obj, 'occursIn'): | ||
text = obj.occursIn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is obj
?
…r has obj permission
annotations/models.py
Outdated
return reverse('annotate', args=[self.id]) | ||
"""Get the absolute URL for viewing/annotating this text.""" | ||
# Get the first project this text belongs to | ||
project = self.partOf.first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem right. Wouldn't that mean that if a text is in multiple projects of multiple users, a user might see a text in a project that is not their own?
""" | ||
project = get_object_or_404( | ||
_annotate_project_counts(TextCollection.objects), | ||
pk=project_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I think there needs to be a comment here, especially since it would be more obvious why you do that it here are many projects and you want to annotate them all, but this is only requesting one single one. It also doesn't help that it's the "TextCollection" class but the id is "project_id". So there should be an explanatory comment why this is used over just getting the counts directly from the requested project (the way it's written makes it a lot harder to understand what's going on).
Can one of the admins verify this patch? |
Guidelines for Pull Requests
If you haven't yet read our code review guidelines, please do so, You can find them here.
Please confirm the following by adding an x for each item (turn
[ ]
into[x]
).Please provide a brief description of your ticket
Projects and texts
Description
The text import button should be for projects, not in the menu right now. Or if it stays in the main menu, the user should have to select a project to put the text in.
Actually, I think the way it currently is something is off. Texts should be part of projects, so the user goes to a project and sees all texts in that project. Not under “Texts”.
VOGRE-14
Projects should be sharable with other people.
Description
I want to be able to another user to my project and then they have access to all the texts and annotations in the project. And they should be able to add new texts and annotate them.
VOGRE-15
users should only see their own projects and projects that have been shared with them
VOGRE-24
Are there any other pull requests that this one depends on?
Anything else the reviewer needs to know?