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

disconnect between resource-backed model getters and async methods in current-user service #5410

Open
stopfstedt opened this issue Apr 19, 2024 · 1 comment
Assignees
Labels

Comments

@stopfstedt
Copy link
Member

stopfstedt commented Apr 19, 2024

i banged my head against this for a while today.

this is best explained by example:

from the current-user service class, consider this method:

  async isTeachingCourseInSchool(school) {
    const user = await this.getModel();
    const schoolCourseIds = school.hasMany('courses').ids();

    const courses = await user.get('allInstructedCourses');
    const matches = courses.filter((course) => schoolCourseIds.includes(course.get('id')));

    return matches.length > 0;
  }

take note of the async method call on the user model: await user.get('allInstructedCourses');

this invokes the User::allInstructedCourses getter - this is not a method that returns a promise, there is nothing to await on. it appears to always be returning an empty array when invoked in this manner.

there are several other examples of this kind of mismatch.

  • CurrentUser::isTeachingCourse(course) is marred by the same problem
  • CurrentUser::isTeachingSession(session) calls the User::allInstructedSession getter - same problem.
@stopfstedt stopfstedt added the BUG label Apr 19, 2024
@stopfstedt
Copy link
Member Author

stopfstedt commented Apr 19, 2024

another wrinkle - we don't have any test coverage on these methods.

$ egrep -r '(isTeachingCourseInSchool|isTeachingCourse|isTeachingSession)\(' packages/ | egrep -v '(dist|node_modules)'packages/ilios-common/addon/services/current-user.js:  async isTeachingCourseInSchool(school) {
packages/ilios-common/addon/services/current-user.js:  async isTeachingCourse(course) {
packages/ilios-common/addon/services/current-user.js:  async isTeachingSession(session) {
packages/ilios-common/addon/services/current-user.js:      (await this.isTeachingCourseInSchool(school))
packages/ilios-common/addon/services/current-user.js:    if (rolesToCheck.includes('COURSE_INSTRUCTOR') && (await this.isTeachingCourse(course))) {
packages/ilios-common/addon/services/current-user.js:    if (rolesToCheck.includes('SESSION_INSTRUCTOR') && (await this.isTeachingSession(session))) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant