Skip to content

Commit

Permalink
feat(#33): clean up function names for rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumpy-Squirrel committed Nov 5, 2024
1 parent 432c9bf commit 15e4d52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion api/openapi-spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -883,13 +883,16 @@ paths:
- rooms
summary: find my room
description: |-
Obtain the room you are in. Must have a valid registration.
Obtain the room you are in. Must have a valid registration in attending status.
Visibility of this information depends on the "final" flag that is set on the room, so admins can start planning
room assignments without them becoming immediately visible to users.
This endpoint works even for admins, giving them the room they are in, as long as they have a valid registration.
Admins are treated no different from regular users for this endpoint. This is so even an admin gets the
same user experience as a non-admin regarding their own room assignment.
Because the user identity is taken from the logged in user, this does not work for Api Key authorization.
Use the /rooms endpoint with member_id parameter instead.
operationId: findMyRoom
Expand Down
16 changes: 10 additions & 6 deletions internal/service/rooms/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ func (r *roomService) FindRooms(ctx context.Context, params *FindRoomParams) ([]
}

if validator.IsAdmin() || validator.IsAPITokenCall() {
return r.findRoomsLowlevel(ctx, params)
return r.findRoomsFullAccess(ctx, params)
} else {
return nil, errNotAdminOrApiToken(ctx, "(not loaded)", "(not loaded)")
}
}

func (r *roomService) findRoomsLowlevel(ctx context.Context, params *FindRoomParams) ([]*modelsv1.Room, error) {
// findRoomsFullAccess obtains rooms by search criteria. No permission checks are performed in this internal method.
func (r *roomService) findRoomsFullAccess(ctx context.Context, params *FindRoomParams) ([]*modelsv1.Room, error) {
result := make([]*modelsv1.Room, 0)

roomIDs, err := r.DB.FindRooms(ctx, "", params.MinOccupants, params.MaxOccupants, params.MinSize, params.MaxSize, params.MemberIDs)
Expand All @@ -46,7 +47,7 @@ func (r *roomService) findRoomsLowlevel(ctx context.Context, params *FindRoomPar
}

for _, id := range roomIDs {
room, err := r.getRoomByIDLowlevel(ctx, id)
room, err := r.getRoomByIDFullAccess(ctx, id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
aulogging.WarnErrf(ctx, err, "find rooms failed to read room %s - maybe intermittent change: %s", id, err.Error())
Expand All @@ -73,7 +74,7 @@ func (r *roomService) FindMyRoom(ctx context.Context) (*modelsv1.Room, error) {
MinOccupants: 0,
MaxOccupants: -1,
}
rooms, err := r.findRoomsLowlevel(ctx, params)
rooms, err := r.findRoomsFullAccess(ctx, params)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -104,13 +105,16 @@ func (r *roomService) GetRoomByID(ctx context.Context, roomID string) (*modelsv1
}

if validator.IsAdmin() || validator.IsAPITokenCall() {
return r.getRoomByIDLowlevel(ctx, roomID)
return r.getRoomByIDFullAccess(ctx, roomID)
} else {
return nil, errNotAdminOrApiToken(ctx, roomID, "(not loaded)")
}
}

func (r *roomService) getRoomByIDLowlevel(ctx context.Context, roomID string) (*modelsv1.Room, error) {
// getRoomByIDFullAccess obtains a single room mapped to API model given its uuid.
//
// No permission checking in this internal method.
func (r *roomService) getRoomByIDFullAccess(ctx context.Context, roomID string) (*modelsv1.Room, error) {
room, err := r.DB.GetRoomByID(ctx, roomID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
Expand Down

0 comments on commit 15e4d52

Please sign in to comment.