File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -321,6 +321,32 @@ pub async fn add_client<'r>(
321321 } )
322322}
323323
324+ #[ delete( "/roles/<role_id>/limited_to_clients/<client_id>" ) ]
325+ pub async fn delete_limited_to_client < ' r > (
326+ // from url
327+ role_id : i32 ,
328+ client_id : i32 ,
329+ // from headers
330+ _session : AdminSession ,
331+ // injected
332+ db : DbConn ,
333+ ) -> Result < impl Responder < ' r , ' static > > {
334+ let role = Role :: find ( role_id, & db) . await ?;
335+ let client = Client :: find ( client_id, & db) . await ?;
336+ role. remove_limited_to_client ( client_id, & db) . await ?;
337+ Ok ( Accepter {
338+ html : Redirect :: to ( uri ! ( show_role_page(
339+ role_id,
340+ None :: <String >,
341+ Some ( format!(
342+ "Successfully removed client “{}” from the “limited to” list" ,
343+ client. name,
344+ ) )
345+ ) ) ) ,
346+ json : Custom ( Status :: Ok , ( ) ) ,
347+ } )
348+ }
349+
324350#[ delete( "/roles/<role_id>/users/<user_id>" ) ]
325351pub async fn delete_user < ' r > (
326352 // from url
Original file line number Diff line number Diff line change @@ -227,6 +227,28 @@ impl Role {
227227 }
228228 }
229229
230+ pub async fn remove_limited_to_client (
231+ self ,
232+ client_id : i32 ,
233+ db : & DbConn ,
234+ ) -> Result < bool > {
235+ let role_id = self . id ;
236+ let count = db
237+ . run ( move |conn| {
238+ diesel:: delete (
239+ roles_limited_to_clients:: table
240+ . filter (
241+ roles_limited_to_clients:: client_id. eq ( client_id) ,
242+ )
243+ . filter ( roles_limited_to_clients:: role_id. eq ( role_id) ) ,
244+ )
245+ . execute ( conn)
246+ } )
247+ . await
248+ . map_err ( ZauthError :: from) ?;
249+ Ok ( count > 0 )
250+ }
251+
230252 pub async fn remove_user ( self , user_id : i32 , db : & DbConn ) -> Result < bool > {
231253 let count = db
232254 . run ( move |conn| {
You can’t perform that action at this time.
0 commit comments