roles.proto 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. syntax = "proto3";
  2. package chatto.admin.v1;
  3. import "buf/validate/validate.proto";
  4. import "chatto/api/v1/roles.proto";
  5. import "chatto/api/v1/users.proto";
  6. // Role metadata plus administrative permission state.
  7. message AdminRole {
  8. // Public role metadata shared with ordinary role catalog reads.
  9. chatto.api.v1.Role role = 1;
  10. // Permissions granted by this role.
  11. repeated string permissions = 2;
  12. // Permissions denied by this role.
  13. repeated string permission_denials = 3;
  14. }
  15. // Request the role catalog.
  16. message ListRolesRequest {}
  17. // Finite role catalog snapshot plus viewer role-management capabilities.
  18. message ListRolesResponse {
  19. // Roles sorted by position.
  20. repeated AdminRole roles = 1;
  21. // Whether the caller may create/update/delete role definitions.
  22. bool viewer_can_manage_roles = 2;
  23. // Whether the caller may assign/revoke roles and view role rosters.
  24. bool viewer_can_assign_roles = 3;
  25. }
  26. // Request one role.
  27. message GetRoleRequest {
  28. // Stable role name.
  29. string name = 1 [(buf.validate.field).string.min_len = 1];
  30. }
  31. // One role plus role-management metadata.
  32. message GetRoleResponse {
  33. // Requested role.
  34. AdminRole role = 1;
  35. // Explicit users with this role. Empty unless the caller may assign roles.
  36. repeated chatto.api.v1.User users = 2;
  37. // Whether the caller may create/update/delete role definitions.
  38. bool viewer_can_manage_roles = 3;
  39. // Whether the caller may assign/revoke roles and view role rosters.
  40. bool viewer_can_assign_roles = 4;
  41. }
  42. // Request to create a role.
  43. message CreateRoleRequest {
  44. // Stable role name.
  45. string name = 1 [(buf.validate.field).string.min_len = 1];
  46. // Display name shown in admin and mention UIs.
  47. string display_name = 2 [(buf.validate.field).string.max_len = 80];
  48. // Optional role description.
  49. string description = 3 [(buf.validate.field).string.max_len = 500];
  50. // Whether messages may notify users assigned to this role.
  51. bool pingable = 4;
  52. }
  53. // Result of creating a role.
  54. message CreateRoleResponse {
  55. // Created role.
  56. AdminRole role = 1;
  57. }
  58. // Request to update role metadata.
  59. message UpdateRoleRequest {
  60. // Stable role name.
  61. string name = 1 [(buf.validate.field).string.min_len = 1];
  62. // Display name shown in admin and mention UIs, when changing it.
  63. optional string display_name = 2 [(buf.validate.field).string.max_len = 80];
  64. // Role description, when changing it. Empty clears the description.
  65. optional string description = 3 [(buf.validate.field).string.max_len = 500];
  66. // Whether messages may notify users assigned to this role, when changing it.
  67. optional bool pingable = 4;
  68. }
  69. // Result of updating a role.
  70. message UpdateRoleResponse {
  71. // Updated role.
  72. AdminRole role = 1;
  73. }
  74. // Request to delete a role.
  75. message DeleteRoleRequest {
  76. // Stable role name.
  77. string name = 1 [(buf.validate.field).string.min_len = 1];
  78. }
  79. // Result of deleting a role.
  80. message DeleteRoleResponse {
  81. // True when the request completed.
  82. bool deleted = 1;
  83. }
  84. // Request to replace custom role order.
  85. message ReorderRolesRequest {
  86. // Ordered custom role names. The list must include every custom role exactly
  87. // once; system roles keep fixed positions and must not be included.
  88. repeated string role_names = 1 [(buf.validate.field).repeated = {
  89. max_items: 1000
  90. items: {
  91. string: {min_len: 1}
  92. }
  93. }];
  94. }
  95. // Result of replacing custom role order.
  96. message ReorderRolesResponse {
  97. // Full role catalog after reordering.
  98. repeated AdminRole roles = 1;
  99. }
  100. // Provides authenticated role reads and administrative role definition changes.
  101. service AdminRoleService {
  102. // Lists the role catalog including permission arrays as a finite snapshot.
  103. // Requires an authenticated user. This intentionally includes permission
  104. // arrays for clients that need to show a user's assigned roles and their
  105. // effects; use chatto.api.v1.RoleService for lightweight catalog rendering.
  106. rpc ListRoles(ListRolesRequest) returns (ListRolesResponse);
  107. // Gets one role plus admin detail metadata. Returns NOT_FOUND when the
  108. // role does not exist. Requires an authenticated user; the assigned-user
  109. // roster is empty unless the caller may assign roles.
  110. rpc GetRole(GetRoleRequest) returns (GetRoleResponse);
  111. // Creates a custom role. Requires role.manage.
  112. rpc CreateRole(CreateRoleRequest) returns (CreateRoleResponse);
  113. // Updates role metadata. Requires role.manage.
  114. rpc UpdateRole(UpdateRoleRequest) returns (UpdateRoleResponse);
  115. // Deletes a custom role. Requires role.manage.
  116. rpc DeleteRole(DeleteRoleRequest) returns (DeleteRoleResponse);
  117. // Replaces the custom role order. Requires role.manage.
  118. rpc ReorderRoles(ReorderRolesRequest) returns (ReorderRolesResponse);
  119. }