Commit f50dc8f7 authored by Roman Lacko's avatar Roman Lacko
Browse files

get around removed 'is_admin' flag

parent ea8c295e
...@@ -77,7 +77,6 @@ sub new { ...@@ -77,7 +77,6 @@ sub new {
croak "GitLab authentication failed: ", $response->message croak "GitLab authentication failed: ", $response->message
unless $response->is_success; unless $response->is_success;
$self->{user_is_admin} = $user->{is_admin};
my $version = $self->version(-immortal => 1); my $version = $self->version(-immortal => 1);
my $vn = defined $version my $vn = defined $version
...@@ -115,7 +114,20 @@ sub die_on_error { ...@@ -115,7 +114,20 @@ sub die_on_error {
sub is_admin { sub is_admin {
my ($self) = @_; my ($self) = @_;
return $self->{user_is_admin};
return $self->{is_admin} if $self->{is_admin};
my $sudo = $self->{impersonate};
$self->{is_admin} = 1;
$self->sudo(undef);
$self->{session} = $self->whoami
unless defined $self->{session};
$self->sudo($self->{session}->{username});
my ($user, $response) = $self->whoami(-response => 1, -immortal => 1);
$self->sudo($sudo);
return $self->{session}->{is_admin} = $response->is_success;
} }
#=============================================================================== #===============================================================================
...@@ -140,7 +152,9 @@ sub login { ...@@ -140,7 +152,9 @@ sub login {
if ($response->is_success) { if ($response->is_success) {
$log->debug("login successful"); $log->debug("login successful");
$self->{token} = $self->json->decode($response->decoded_content)->{private_token}; $self->{session} = $self->json->decode($response->decoded_content);
$self->{is_admin} = $self->{session}->{is_admin};
$self->{token} = $self->{session}->{private_token};
} else { } else {
$log->fatal("login failed: " . $response->status_line); $log->fatal("login failed: " . $response->status_line);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment