@@ -13,7 +13,7 @@ use crate::models::auth::{AuthUser, OrganisationAdmin};
1313use crate :: models:: campaign:: { Campaign , NewCampaign } ;
1414use crate :: models:: email_template:: { EmailTemplate , NewEmailTemplate } ;
1515use crate :: models:: error:: ChaosError ;
16- use crate :: models:: organisation:: { AdminToRemove , AdminUpdateList , NewOrganisation , Organisation , SlugCheck } ;
16+ use crate :: models:: organisation:: { MemberToRemove , AdminUpdateList , NewOrganisation , Organisation , SlugCheck , MemberToInvite } ;
1717use crate :: models:: transaction:: DBTransaction ;
1818use crate :: service:: auth:: assert_is_super_user;
1919use axum:: extract:: { Json , Path , State } ;
@@ -202,6 +202,30 @@ impl OrganisationHandler {
202202 Ok ( ( StatusCode :: OK , Json ( members) ) )
203203 }
204204
205+ /// Retrieves all users (role) of an organisation.
206+ ///
207+ /// This handler allows organisation admins to view all members with the role "User".
208+ ///
209+ /// # Arguments
210+ ///
211+ /// * `state` - The application state
212+ /// * `id` - The ID of the organisation
213+ /// * `_admin` - The authenticated user (must be an organisation admin)
214+ ///
215+ /// # Returns
216+ ///
217+ /// * `Result<impl IntoResponse, ChaosError>` - List of members or error
218+ pub async fn get_users (
219+ mut transaction : DBTransaction < ' _ > ,
220+ Path ( id) : Path < i64 > ,
221+ _admin : OrganisationAdmin ,
222+ ) -> Result < impl IntoResponse , ChaosError > {
223+ let members = Organisation :: get_users ( id, & mut transaction. tx ) . await ?;
224+
225+ transaction. tx . commit ( ) . await ?;
226+ Ok ( ( StatusCode :: OK , Json ( members) ) )
227+ }
228+
205229 /// Retrieves all members of an organisation.
206230 ///
207231 /// This handler allows organisation admins to view all members.
@@ -296,20 +320,17 @@ impl OrganisationHandler {
296320 mut transaction : DBTransaction < ' _ > ,
297321 Path ( id) : Path < i64 > ,
298322 _super_user : SuperUser ,
299- Json ( request_body) : Json < AdminToRemove > ,
323+ Json ( request_body) : Json < MemberToRemove > ,
300324 ) -> Result < impl IntoResponse , ChaosError > {
301325 Organisation :: remove_admin ( id, request_body. user_id , & mut transaction. tx ) . await ?;
302326
303327 transaction. tx . commit ( ) . await ?;
304- Ok ( (
305- StatusCode :: OK ,
306- "Successfully removed member from organisation" ,
307- ) )
328+ Ok ( AppMessage :: OkMessage ( "Successfully removed member from organisation" ) )
308329 }
309330
310- /// Removes a member from an organisation.
331+ /// Removes a user from an organisation.
311332 ///
312- /// This handler allows organisation admins to remove members.
333+ /// This handler allows organisation admins to remove members with role "User" .
313334 ///
314335 /// # Arguments
315336 ///
@@ -321,19 +342,29 @@ impl OrganisationHandler {
321342 /// # Returns
322343 ///
323344 /// * `Result<impl IntoResponse, ChaosError>` - Success message or error
324- pub async fn remove_member (
345+ pub async fn remove_user (
346+ mut transaction : DBTransaction < ' _ > ,
347+ Path ( id) : Path < i64 > ,
348+ _admin : OrganisationAdmin ,
349+ Json ( request_body) : Json < MemberToRemove > ,
350+ ) -> Result < impl IntoResponse , ChaosError > {
351+ Organisation :: remove_user ( id, request_body. user_id , & mut transaction. tx ) . await ?;
352+
353+ transaction. tx . commit ( ) . await ?;
354+ Ok ( AppMessage :: OkMessage ( "Successfully removed member from organisation" ) )
355+ }
356+
357+ pub async fn invite_user (
325358 mut transaction : DBTransaction < ' _ > ,
326359 Path ( id) : Path < i64 > ,
327360 _admin : OrganisationAdmin ,
328- Json ( request_body) : Json < AdminToRemove > ,
361+ State ( state) : State < AppState > ,
362+ Json ( request_body) : Json < MemberToInvite > ,
329363 ) -> Result < impl IntoResponse , ChaosError > {
330- Organisation :: remove_member ( id, request_body. user_id , & mut transaction. tx ) . await ?;
364+ Organisation :: invite_user ( id, request_body. email , state . email_credentials , & mut transaction. tx ) . await ?;
331365
332366 transaction. tx . commit ( ) . await ?;
333- Ok ( (
334- StatusCode :: OK ,
335- "Successfully removed member from organisation" ,
336- ) )
367+ Ok ( AppMessage :: OkMessage ( "Successfully invited user to organisation" ) )
337368 }
338369
339370 /// Updates an organisation's logo.
0 commit comments