File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -247,13 +247,19 @@ async fn save_changes(
247
247
let cohort: Option < i64 > = cohort. parse :: < i64 > ( ) . ok ( ) ;
248
248
249
249
// Check that the current user role can switch to the submitted role.
250
- if form. template [ "context" ] [ "roles" ] . get ( role. to_string ( ) ) . and_then ( Value :: as_bool) . unwrap_or ( false ) {
251
- return Err ( TelescopeError :: BadRequest {
250
+ form. template [ "context" ] [ "roles" ]
251
+ // Index the selected role availability.
252
+ . get ( role. to_string ( ) )
253
+ // Convert to bool, default as false.
254
+ . and_then ( Value :: as_bool)
255
+ . unwrap_or ( false )
256
+ // Create and propagate error on false.
257
+ . then ( || ( ) )
258
+ . ok_or ( TelescopeError :: BadRequest {
252
259
header : "Invalid Role Selection" . into ( ) ,
253
260
message : "The selected role is not available at this time" . into ( ) ,
254
261
show_status_code : false
255
- } ) ;
256
- }
262
+ } ) ?;
257
263
258
264
// Fill the form with the submitted info.
259
265
form. template [ "context" ] [ "first_name" ] = json ! ( & first_name) ;
You can’t perform that action at this time.
0 commit comments