Skip to content

Instantly share code, notes, and snippets.

@dklawren
Created August 10, 2017 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dklawren/63ce3564720368d474fb301f2a97c60f to your computer and use it in GitHub Desktop.
Save dklawren/63ce3564720368d474fb301f2a97c60f to your computer and use it in GitHub Desktop.
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