{"success":true,"name":"model-roles-and-permissions-as-data-not-scattered-if-admin-c","description":"Adding the second or third role check hardcoded into feature code","category":"ai-brimind","path":"ai-brimind/model-roles-and-permissions-as-data-not-scattered-if-admin-c/SKILL.md","file":"SKILL.md","content":"---\nname: model-roles-and-permissions-as-data-not-scattered-if-admin-c\ndescription: \"Adding the second or third role check hardcoded into feature code\"\n---\n\n# Model Roles and Permissions as Data, Not Scattered if-admin Checks\n\n## When to use\nAccess rules live as if-statements comparing role strings across the codebase, or a new role/permission requires editing many files.\n\n## Example request\nif (user.role === 'admin') copied into 30 places → adding 'coach' means 30 edits; scattered law. one screen forgot the check → that role sees everything; unenforced gap. 'can managers export?' → the answer lives in grep results, not in one table; unreadable policy. — each wrote the law into the walls instead of a book.\n\n## Instructions\nAct as a legislator who writes the law in one book, so judges consult it instead of each remembering their own version. Before the access rules multiply, design the model once: name the roles, name the permissions as actions on things ('edit member', 'export reports'), and map which role holds which permission — in one data structure or table, not in conditions sprinkled through features. Code then asks one question everywhere: 'can this user do X?' — a single check function reading the map — so adding a role or changing a rule edits data, not thirty files. Check permissions, not roles, in feature code: 'can export' survives reorganizations of who can, while 'is admin' hardens the org chart into the code. Keep the map server-side and authoritative; the UI may hide buttons, but the check function is the law, per the project's authorization rules. Write the map somewhere a human can read the whole policy at a glance. Only proceed once 'who can do what' is answerable by opening one file — because a policy you must grep for is a policy nobody actually knows.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #802\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}