Skip to content

As a developer I want gym-wide shared templates and exercise library so instructors can collaborate on programs and muscle mappings #171

@ChristopherRotnes

Description

@ChristopherRotnes

Summary

Templates (session_templates) and the exercise library (exercise_library) are currently user-private. Co-instructors at the same gym cannot see or edit each other's templates or exercises, forcing duplicate work and inconsistent muscle mappings. Making both gym-wide lets the team build a shared program library and correct muscle data together.

Priority

High

UI spec (Carbon g100)

  • Bibliotek "Mine maler" tab renamed to "Maler" (templates are no longer personal)
  • Template cards: show "Av [display_name]" in var(--cds-font-mono) 11px below exercise/muscle count — only when the creator differs from the current user
  • Exercise rows: same attribution below muscle chips
  • No permission gating on Edit/Delete buttons — all co-instructors can act on any item

Data model

RLS changes (migration gym_wide_templates_and_exercises):

-- session_templates: INSERT own, SELECT/UPDATE/DELETE same-gym
-- session_template_exercises: ALL via parent template gym check
-- exercise_library: INSERT own, SELECT/UPDATE/DELETE same-gym

-- Same-gym check pattern (mirrors sessions policy):
EXISTS (
  SELECT 1 FROM user_gyms ug1
  JOIN user_gyms ug2 ON ug2.sporty_business_unit_id = ug1.sporty_business_unit_id
  WHERE ug1.user_id = auth.uid()
    AND ug2.user_id = <table>.user_id
)

user_id retained on both tables as "created by" for attribution display.

fetchTemplates() and fetchLibraryExercises() updated to join profiles!user_id(display_name).

Acceptance criteria

  • Co-instructor at same gym can see all templates in Bibliotek
  • Co-instructor can edit template name and exercises
  • Co-instructor can delete any template or exercise
  • Creator attribution shown on items not created by current user
  • touchTemplate succeeds when using a colleague's template in Planlegger
  • INSERT always uses own user_id (cannot create on behalf of another)
  • Existing tests pass (npm test — 82 tests)
  • Users without user_gyms entry cannot see templates (covered by ensureGymMembership on sign-in)

Out of scope

  • Retroactive muscle remapping when an exercise is edited (tracked separately)
  • Private/opt-out templates — all templates are gym-wide with no exceptions
  • Cross-gym template sharing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions