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

feat: add shared attribute, add markshared mutation, add templateCour… #914

Merged
merged 31 commits into from
Apr 1, 2024

Conversation

paul-jaworski
Copy link
Contributor

No description provided.

@realmayus realmayus temporarily deployed to backend-feat-974-c5gmwsq0gykbg December 2, 2023 18:01 Inactive
Copy link
Member

@Jonasdoubleyou Jonasdoubleyou left a comment

Choose a reason for hiding this comment

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

Looks pretty good already!
You also need to adapt authorizations.ts and mark the shared attribute as public, it's not something we need to keep private.

graphql/course/fields.ts Outdated Show resolved Hide resolved
graphql/course/mutations.ts Outdated Show resolved Hide resolved
graphql/course/mutations.ts Show resolved Hide resolved
@Jonasdoubleyou
Copy link
Member

And this could use an integration test where one instructor publishes a course, and then another instructor is able to find it (c.f.

void test('Search further instructors', async () => {
)

@Jonasdoubleyou
Copy link
Member

And we should also relax the check in

await hasAccess(context, 'Course', course);
- The access check on the course should be checked if the course is shared.

@realmayus realmayus had a problem deploying to backend-feat-974-0jydgkpvtuy96 December 2, 2023 18:26 Failure
@realmayus realmayus temporarily deployed to backend-feat-974-0jydgkpvtuy96 December 2, 2023 18:29 Inactive
@paul-jaworski
Copy link
Contributor Author

And we should also relax the check in

await hasAccess(context, 'Course', course);

  • The access check on the course should be checked if the course is shared.

If I make the hasAccess method call conditional, the authorization method must not be @AuthorizedDeferred then right?

@Jonasdoubleyou
Copy link
Member

Ah, true, we need two checks then. @Authorized(Role.INSTRUCTOR) and then manually check inside subcourseAdd whether the course is shared or the user is an instructor

@realmayus realmayus temporarily deployed to backend-feat-974-snrfhtlg33tmn December 2, 2023 19:05 Inactive
@realmayus realmayus temporarily deployed to backend-feat-974-snrfhtlg33tmn December 2, 2023 19:21 Inactive
@paul-jaworski paul-jaworski self-assigned this Jan 13, 2024
@paul-jaworski
Copy link
Contributor Author

Hey Jonas, this got a bit confusing to me after a long break. May you please sum up which methods and auth checks should be changed?

Thank you very much :)

@Jonasdoubleyou
Copy link
Member

  • subcourseCreate should be available to all Role.INSTRUCTOR, then it should be checked whether the course is shared or owned by the instructor
  • An integration test is missing

@paul-jaworski
Copy link
Contributor Author

I see that there is a method call "await hasAccess(context, 'Course', course);". Should the check whether the course is shared or owned by the instructor be included there?

Copy link
Member

@Jonasdoubleyou Jonasdoubleyou 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, some minor touchups to be made then this is ready :)


const student = await getSessionStudent(context, studentId);
await prisma.subcourse_instructors_student.create({ data: { subcourseId: result.id, studentId: student.id } });
if (isCourseSharedOrOwned) {
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, you are right since I already throw an error in line 92 when the if condition isnt met :)

},
});
const isCourseSharedOrOwned = !!courseInstructorAssociation || course.shared;
if (!isCourseSharedOrOwned) {
logger.error(`Subcourse(${courseId}) is not shared or Student(${studentId}) is not an instructor of this subcourse`);
Copy link
Member

Choose a reason for hiding this comment

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

Subcourse -> Course

@@ -71,7 +71,7 @@ class PublicLectureInput {
@Resolver((of) => GraphQLModel.Subcourse)
export class MutateSubcourseResolver {
@Mutation((returns) => GraphQLModel.Subcourse)
@AuthorizedDeferred(Role.ADMIN, Role.OWNER)
@AuthorizedDeferred(Role.INSTRUCTOR)
Copy link
Member

Choose a reason for hiding this comment

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

Ah, and this must be @Authorized instead of @AuthorizedDeferred

Copy link
Member

@Jonasdoubleyou Jonasdoubleyou left a comment

Choose a reason for hiding this comment

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

sorry, overlooked this earlier

const courseInstructorAssociation = await prisma.course_instructors_student.findFirst({
where: {
courseId: courseId,
studentId: studentId,
Copy link
Member

Choose a reason for hiding this comment

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

Ah, this for sure is wrong, we cannot trust our users to pass in their id. Please do

const student = await getSessionStudent(context, studentId);

... studentId: student.id

Copy link
Member

@Jonasdoubleyou Jonasdoubleyou left a comment

Choose a reason for hiding this comment

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

apart from fixing the integration tests this should be good now

@@ -21,6 +22,7 @@ const courseOne = test('Create Course One', async () => {
description: "Why should I test if my users can do that for me in production?"
category: club
allowContact: true
shared: 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 think you need a separate mutation markShared afterwards

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please rephrase this comment? Do you mean that we need a separate test for shared and nonshared courses? For the current integration test I manually set the shared value to false. See line 414

Copy link
Member

Choose a reason for hiding this comment

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

No the courseCreate Mutation does not take a shared attribute, thus the test is failing?

@@ -126,7 +129,7 @@ export const subcourseOne = test('Create Subcourse', async () => {
allowChatContactProspects: true
allowChatContactParticipants: true
groupChatType: ${ChatType.NORMAL}
}) { id }
} studentId: ${student.userID}) { id }
Copy link
Member

Choose a reason for hiding this comment

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

and this can be reverted as we now use the session student

@paul-jaworski
Copy link
Contributor Author

@Jonasdoubleyou or @realmayus Can you please have another look here?

@Jonasdoubleyou
Copy link
Member

Um, the tests are still failing, have you seen my comment regarding shared: true?

graphql/course/fields.ts Outdated Show resolved Hide resolved
graphql/subcourse/mutations.ts Outdated Show resolved Hide resolved
graphql/subcourse/mutations.ts Outdated Show resolved Hide resolved
integration-tests/07_course.ts Outdated Show resolved Hide resolved
integration-tests/07_course.ts Outdated Show resolved Hide resolved
integration-tests/07_course.ts Show resolved Hide resolved
integration-tests/07_course.ts Outdated Show resolved Hide resolved
integration-tests/07_course.ts Show resolved Hide resolved
Copy link
Member

@Jonasdoubleyou Jonasdoubleyou left a comment

Choose a reason for hiding this comment

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

nice!

@paul-jaworski paul-jaworski merged commit b654673 into master Apr 1, 2024
2 checks passed
@paul-jaworski paul-jaworski deleted the feat-974 branch April 1, 2024 17:34
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