Class CourseAccessService

java.lang.Object
edu.ucsb.cs156.happiercows.services.CourseAccessService

@Service public class CourseAccessService extends Object
Determines whether a user has access to a course-linked Game, based on whether their email appears on the roster (as a Student or Staff member) of the course the Game is linked to. See issue #251.
  • Constructor Details

    • CourseAccessService

      public CourseAccessService()
  • Method Details

    • isEligibleForGame

      public boolean isEligibleForGame(User user, Game game)
      A user is eligible for a course-linked game if they are an admin, or if their email appears on the course's roster of students or staff. A game with no course (courseId == null) is open to everyone.
    • getCourseIdsForUser

      public List<Long> getCourseIdsForUser(User user)
      Returns the distinct list of course ids for which this user's email appears on the roster as a student or as staff.

      Roster emails are compared to the user's email using CanonicalFormConverter.areEquivalentEmails(String, String), not exact string equality, so that a roster row uploaded with a stale/non-canonical email (e.g. an old @umail.ucsb.edu entry that predates this fix, or one that slips in from a school whose export format isn't fully normalized) still matches a student logging in with the canonical form of the same address. See issue #278.

    • findMatchingStudentForCourseLinkedGame

      public Optional<Student> findMatchingStudentForCourseLinkedGame(User user, Game game)
      Returns the Student roster row that corresponds to this user, for the course linked to the given game - but only if the game is actually linked to a course. Used to decide whether a FarmerActivity row should be recorded for a play-page view or a buy/sell action: activity is only tracked for course-linked games, and only for users whose email matches a student on that course's roster (see issue #291), using the same canonical-email-matching rule as getCourseIdsForUser(User).