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

story/VOGRE-14 #11

Merged
merged 49 commits into from
Dec 12, 2024
Merged

story/VOGRE-14 #11

merged 49 commits into from
Dec 12, 2024

Conversation

Girik1105
Copy link
Contributor

@Girik1105 Girik1105 commented Oct 17, 2024

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]).

  • I have removed all code style changes that are not necessary (e.g. changing blanks across the whole file that don’t need to be changed, adding empty lines in parts other than your own code)
  • I am not making any changes to files that don’t have any effect (e.g. imports added that don’t need to be added)
  • I do not have any sysout statements in my code or commented out code that isn’t needed anymore
  • I am not reformatting any files in the wrong format or without cause.
  • I am not changing file encoding or line endings to something else than UTF-8, LF
  • My pull request does not show an insane amount of files being changed although my ticket only requires a few files being changed
  • I have added Javadoc/documentation where appropriate
  • I have added test cases where appropriate
  • I have explained any part of my code/implementation decisions that is not be self-explanatory

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?

  • Text URLS now contain the project instead of being passed as parameters.
  • Since there shouldn't be an instance where a text exists without a project, a user will be prompted to select a project when he is importing a text directly from a repository. A user can also directly add texts from a project.
  • Collaborators will be able to view existing texts and the annotations on them when added to a project as a collaborator, and if a collaborator is removed they will no longer has access to the text but their annotations won't be deleted

@@ -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)
Copy link
Member

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 }}">
Copy link
Member

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?

Copy link
Contributor Author

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')
Copy link
Member

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)
Copy link
Member

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.

@jdamerow jdamerow closed this Nov 14, 2024
…o see if text is already associated with project, merged project id in context in repository_details view
@Girik1105 Girik1105 reopened this Nov 14, 2024
@Girik1105 Girik1105 closed this Nov 15, 2024
@Girik1105 Girik1105 reopened this Nov 19, 2024
This was referenced Nov 20, 2024

# Get custom error message from the PermissionDenied exception
# raise PermissionDenied("Custom message")
error_message = str(exception)
Copy link
Member

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
Copy link
Member

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?


# Get order_by from request, default to default_field
order_by = request.GET.get('order_by', default_field)
Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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?

Copy link
Member

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.

# Check if user is owner or collaborator of the text's collection
text = None
if hasattr(obj, 'occursIn'):
text = obj.occursIn
Copy link
Member

Choose a reason for hiding this comment

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

what is obj?

@jdamerow jdamerow closed this Nov 21, 2024
@Girik1105 Girik1105 reopened this Nov 21, 2024
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()
Copy link
Member

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
Copy link
Member

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).

@jdamerow jdamerow closed this Nov 27, 2024
@Girik1105 Girik1105 reopened this Dec 5, 2024
@diging-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@jdamerow jdamerow merged commit 9442b51 into develop Dec 12, 2024
@jdamerow jdamerow deleted the story/VOGRE-14 branch December 12, 2024 20:28
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