1use rustauth_core::plugin::PluginErrorCode;
2
3pub const ORGANIZATION_ERROR_CODES: &[(&str, &str)] = &[
4 (
5 "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION",
6 "You are not allowed to create a new organization",
7 ),
8 (
9 "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS",
10 "You have reached the maximum number of organizations",
11 ),
12 ("ORGANIZATION_ALREADY_EXISTS", "Organization already exists"),
13 (
14 "ORGANIZATION_SLUG_ALREADY_TAKEN",
15 "Organization slug already taken",
16 ),
17 ("ORGANIZATION_NOT_FOUND", "Organization not found"),
18 (
19 "USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION",
20 "User is not a member of the organization",
21 ),
22 (
23 "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_ORGANIZATION",
24 "You are not allowed to update this organization",
25 ),
26 (
27 "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_ORGANIZATION",
28 "You are not allowed to delete this organization",
29 ),
30 ("NO_ACTIVE_ORGANIZATION", "No active organization"),
31 (
32 "USER_IS_ALREADY_A_MEMBER_OF_THIS_ORGANIZATION",
33 "User is already a member of this organization",
34 ),
35 ("MEMBER_NOT_FOUND", "Member not found"),
36 ("ROLE_NOT_FOUND", "Role not found"),
37 (
38 "YOU_CANNOT_LEAVE_THE_ORGANIZATION_AS_THE_ONLY_OWNER",
39 "You cannot leave the organization as the only owner",
40 ),
41 (
42 "YOU_CANNOT_LEAVE_THE_ORGANIZATION_WITHOUT_AN_OWNER",
43 "You cannot leave the organization without an owner",
44 ),
45 (
46 "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_MEMBER",
47 "You are not allowed to delete this member",
48 ),
49 (
50 "YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION",
51 "You are not allowed to invite users to this organization",
52 ),
53 (
54 "USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION",
55 "User is already invited to this organization",
56 ),
57 ("INVITATION_NOT_FOUND", "Invitation not found"),
58 (
59 "YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION",
60 "You are not the recipient of the invitation",
61 ),
62 (
63 "EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION",
64 "Email verification required before accepting or rejecting invitation",
65 ),
66 (
67 "YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION",
68 "You are not allowed to cancel this invitation",
69 ),
70 (
71 "YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE",
72 "You are not allowed to invite a user with this role",
73 ),
74 ("INVITATION_LIMIT_REACHED", "Invitation limit reached"),
75 (
76 "ORGANIZATION_MEMBERSHIP_LIMIT_REACHED",
77 "Organization membership limit reached",
78 ),
79 (
80 "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_MEMBER",
81 "You are not allowed to update this member",
82 ),
83 (
84 "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM",
85 "You are not allowed to create a new team",
86 ),
87 ("TEAM_ALREADY_EXISTS", "Team already exists"),
88 ("TEAM_NOT_FOUND", "Team not found"),
89 (
90 "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS",
91 "You have reached the maximum number of teams",
92 ),
93 ("UNABLE_TO_REMOVE_LAST_TEAM", "Unable to remove last team"),
94 (
95 "YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION",
96 "You are not allowed to create teams in this organization",
97 ),
98 (
99 "YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION",
100 "You are not allowed to delete teams in this organization",
101 ),
102 (
103 "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM",
104 "You are not allowed to update this team",
105 ),
106 (
107 "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM",
108 "You are not allowed to delete this team",
109 ),
110 ("TEAM_MEMBER_LIMIT_REACHED", "Team member limit reached"),
111 ("USER_IS_NOT_A_MEMBER_OF_THE_TEAM", "User is not a member of the team"),
112 (
113 "YOU_CAN_NOT_ACCESS_THE_MEMBERS_OF_THIS_TEAM",
114 "You are not allowed to list the members of this team",
115 ),
116 ("YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM", "You do not have an active team"),
117 (
118 "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER",
119 "You are not allowed to create a new member",
120 ),
121 (
122 "YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER",
123 "You are not allowed to remove a team member",
124 ),
125 (
126 "YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION",
127 "You are not allowed to access this organization as an owner",
128 ),
129 (
130 "YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION",
131 "You are not a member of this organization",
132 ),
133 (
134 "MISSING_AC_INSTANCE",
135 "Dynamic Access Control requires a pre-defined ac instance on the server auth plugin. Read server logs for more information",
136 ),
137 (
138 "YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE",
139 "You must be in an organization to create a role",
140 ),
141 (
142 "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE",
143 "You are not allowed to create a role",
144 ),
145 (
146 "YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE",
147 "You are not allowed to update a role",
148 ),
149 (
150 "YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE",
151 "You are not allowed to delete a role",
152 ),
153 (
154 "YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE",
155 "You are not allowed to read a role",
156 ),
157 (
158 "YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE",
159 "You are not allowed to list a role",
160 ),
161 (
162 "YOU_ARE_NOT_ALLOWED_TO_GET_A_ROLE",
163 "You are not allowed to get a role",
164 ),
165 ("TOO_MANY_ROLES", "This organization has too many roles"),
166 (
167 "INVALID_RESOURCE",
168 "The provided permission includes an invalid resource",
169 ),
170 (
171 "ROLE_NAME_IS_ALREADY_TAKEN",
172 "That role name is already taken",
173 ),
174 (
175 "CANNOT_DELETE_A_PRE_DEFINED_ROLE",
176 "Cannot delete a pre-defined role",
177 ),
178 (
179 "ROLE_IS_ASSIGNED_TO_MEMBERS",
180 "Cannot delete a role that is assigned to members. Please reassign the members to a different role first",
181 ),
182 (
183 "INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION",
184 "Inviter is no longer a member of the organization",
185 ),
186 (
187 "FAILED_TO_RETRIEVE_INVITATION",
188 "Failed to retrieve invitation",
189 ),
190];
191
192pub fn message(code: &str) -> &'static str {
193 ORGANIZATION_ERROR_CODES
194 .iter()
195 .find_map(|(candidate, message)| (*candidate == code).then_some(*message))
196 .unwrap_or("Organization plugin error")
197}
198
199pub fn error_codes() -> Vec<PluginErrorCode> {
200 ORGANIZATION_ERROR_CODES
201 .iter()
202 .map(|(code, message)| PluginErrorCode::new(*code, *message))
203 .collect()
204}