Skip to content

Conversation

@XanderVertegaal
Copy link
Contributor

Addresses part of #12

Adds a role field to the User model. I opted to add a field canEditOrAddProblem to the serializer so we don't have to implement a method that checks whether a user with role X can do Y in two places.

@XanderVertegaal XanderVertegaal changed the base branch from develop to feature/user-problems November 4, 2025 15:53
Copy link
Contributor

@jgonggrijp jgonggrijp left a comment

Choose a reason for hiding this comment

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

#12 has a table of permissions that each role should or should not have. Why not just define those as custom permissions (where needed) and then implement the roles as regular user groups? That way you don't have to hardcode the roles and Django will assist more in enforcing the permissions.

Base automatically changed from feature/user-problems to develop December 10, 2025 09:47
@XanderVertegaal
Copy link
Contributor Author

Update! At your suggestion, the role field has been replaced by Django user groups and permissions. I have added a data migration that creates them and assigns the required permissions to them. For now there are only two groups: 'annotators' and 'master annotators'. Technically there is a third group (now called 'visitors' in the frontend) for users who are logged in but have not been assigned to either user group. However, these do not (yet?) have any special permissions that non-authenticated users lack, so I did not create a separate group for them now.

@jgonggrijp
Copy link
Contributor

Would you like me to take another look?

@XanderVertegaal
Copy link
Contributor Author

If you have time, yes please!

Copy link
Contributor

@jgonggrijp jgonggrijp left a comment

Choose a reason for hiding this comment

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

I like the comprehensive tests!

I have some comments, but it's mostly questions or nitpicks.

assert response.status_code == status.HTTP_200_OK


class TestUserRoleProperties:
Copy link
Contributor

Choose a reason for hiding this comment

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

Terrible nitpick, I know, but Python calls them "attributes".

Copy link
Contributor Author

@XanderVertegaal XanderVertegaal Dec 12, 2025

Choose a reason for hiding this comment

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

On the Python level they may be attributes, but in Django they are marked as 'properties' (cf. the @property decorator used in the definition of these fields) so if you do not mind I will be sticking to TestUserRoleProperties in this case.

In general, by the way, I appreciate nitpicks like this one; please keep them coming!

Comment on lines 81 to 118
private newProblem$(baseParam: number | null): Observable<ProblemResponse> {
const sharedProblemResponse: Omit<ProblemResponse, "problem"> = {
index: null,
first: null,
last: null,
next: null,
previous: null,
total: 0,
error: null,
};

if (baseParam !== null) {
return this.existingProblem$(baseParam.toString()).pipe(map(response => {
const problem = response?.problem;
return {
...sharedProblemResponse,
problem: {
id: null,
base: baseParam,
hypothesis: problem?.hypothesis ?? "",
dataset: Dataset.USER,
premises: problem?.premises ?? [],
entailmentLabel: EntailmentLabel.UNKNOWN,
extraData: null,
// KB items are not shared across problems.
kbItems: problem?.kbItems.map(kbItem => ({
...kbItem,
id: null,
})) ?? []
}
};
}));
}
return of<ProblemResponse>({
...sharedProblemResponse,
problem: {
id: null,
base: baseParam,
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to comment that you should refactor this, but I vaguely recall commenting on very similar code before. Did you already change this on another branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I recall correctly, it was in a comment that said something along the lines of: "I don't recommend you change this, but if we used 'underscore', you could do this: ...". Did you change your mind about refactoring?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm maybe refactor without underscore? Just to get rid of the deep nesting?

@XanderVertegaal XanderVertegaal merged commit 13a0612 into develop Dec 17, 2025
1 check passed
@XanderVertegaal XanderVertegaal deleted the feature/user-models branch December 17, 2025 15:31
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that every time I write that you can outfactor something "at module scope", you implement this in a new utility module. As far as I'm concerned, you could also just keep it in the module where the logic originated. Maybe you're already aware of this and you just prefer a separate module, but I thought I'd mention it.

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