Skip to content

Commit

Permalink
[TfL] Move role mapping to configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed May 13, 2024
1 parent 517d1a5 commit 6a79c2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
12 changes: 3 additions & 9 deletions perllib/FixMyStreet/Cobrand/TfL.pm
Expand Up @@ -213,14 +213,8 @@ sub roles_from_oidc {
$user->user_roles->delete;
$user->from_body($self->body->id);

my %role_map = (
BasicEditorViewers => 'Streetcare - Basic Editor Viewers',
Contractor => 'Streetcare - Contractor',
AgentInspector => 'Streetcare - Agent Inspector',
Admin => 'Streetcare - Admin',
CustomerServices => 'Streetcare - Customer Services',
CPOS => 'Streetcare - CPOS',
);
my $cfg = $self->feature('oidc_login') || {};
my $role_map = $cfg->{role_map} || {};

my @body_roles;
for ($user->from_body->roles->search(undef, { order_by => 'name' })->all) {
Expand All @@ -231,7 +225,7 @@ sub roles_from_oidc {
}

for my $assign_role (@$roles) {
my ($body_role) = grep { $role_map{$assign_role} && $_->{name} eq $role_map{$assign_role} } @body_roles;
my ($body_role) = grep { $role_map->{$assign_role} && $_->{name} eq $role_map->{$assign_role} } @body_roles;

if ($body_role) {
$user->user_roles->find_or_create({
Expand Down
6 changes: 5 additions & 1 deletion t/app/controller/auth_social.t
Expand Up @@ -635,7 +635,11 @@ for my $setup (
token_uri => 'http://oidc.example.org/oauth2/v2.0/token',
logout_uri => 'http://oidc.example.org/oauth2/v2.0/logout',
password_change_uri => 'http://oidc.example.org/oauth2/v2.0/password_change',
display_name => 'MyAccount'
display_name => 'MyAccount',
role_map => {
BasicEditorViewers => 'Streetcare - Basic Editor Viewers',
Admin => 'Streetcare - Admin',
},
}
}
}
Expand Down

0 comments on commit 6a79c2b

Please sign in to comment.