Created
August 10, 2017 20:23
-
-
Save dklawren/63ce3564720368d474fb301f2a97c60f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub check_user_permission_for_bug { | |
my ($self, $params) = @_; | |
my $user = Bugzilla->login(LOGIN_REQUIRED); | |
# Ensure PhabBugz is on | |
ThrowUserError('invalid_phabricator_request') unless Bugzilla->params->{phabricator_enabled}; | |
# Validate that the requesting user's email matches phab-bot | |
ThrowUserError('unauthorized_user') unless $user->login eq PHAB_BMO_USER_EMAIL; | |
# Validate that a bug id and user id are provided | |
ThrowUserError('invalid_phabricator_request_params') | |
unless ($params->{bug_id} && $params->{user_id}); | |
# Validate that the user and bug exist | |
my $user = Bugzilla::User->new($params->{user_id}); | |
ThrowUserError('user_doesnt_exist') unless $user; | |
# Check that user can view the bug | |
my $can_see_bug = $user->can_see_bug($bug_id); | |
# Send back an object which says { "valid_bug": true|false } | |
return { | |
valid_bug => $can_see_bug | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment