@@ -13,10 +13,22 @@ use warnings;
1313use parent qw( Bugzilla::Extension) ;
1414
1515use Bugzilla::Attachment;
16- use Bugzilla::Config::Common;
16+ use Bugzilla::Error;
17+ use List::MoreUtils qw( any ) ;
1718
1819our $VERSION = ' 0.01' ;
1920
21+ my @METHOD_WHITELIST = (
22+ ' User.get' ,
23+ ' User.login' ,
24+ ' User.valid_login' ,
25+ ' Bug.add_comment' ,
26+ ' Bug.add_attachment' ,
27+ ' Bug.attachments' ,
28+ ' Bug.get' ,
29+ ' Bug.update_attachment' ,
30+ );
31+
2032sub template_before_process {
2133 my ($self , $args ) = @_ ;
2234 my $file = $args -> {' file' };
@@ -65,25 +77,32 @@ sub auth_delegation_confirm {
6577 }
6678}
6779
68- sub config_modify_panels {
80+ sub config_add_panels {
6981 my ($self , $args ) = @_ ;
70- push @{ $args -> {panels }-> {advanced }-> {params } }, {
71- name => ' mozreview_base_url' ,
72- type => ' t' ,
73- default => ' ' ,
74- checker => \&check_urlbase
75- };
76- push @{ $args -> {panels }-> {advanced }-> {params } }, {
77- name => ' mozreview_auth_callback_url' ,
78- type => ' t' ,
79- default => ' ' ,
80- checker => sub {
81- my ($url ) = (@_ );
82-
83- return ' must be an HTTP/HTTPS absolute URL' unless $url =~ m { ^https?://} ;
84- return ' ' ;
82+ my $modules = $args -> {panel_modules };
83+ $modules -> {MozReview } = " Bugzilla::Extension::MozReview::Config" ;
84+ }
85+
86+ sub webservice_before_call {
87+ my ($self , $args ) = @_ ;
88+ my ($method , $full_method ) = ($args -> {method }, $args -> {full_method });
89+ my $mozreview_app_id = Bugzilla-> params-> {mozreview_app_id };
90+ my $user = Bugzilla-> user;
91+
92+ return unless $mozreview_app_id ;
93+ return unless $user -> authorizer;
94+
95+ my $getter = $user -> authorizer-> successful_info_getter()
96+ or return ;
97+
98+ return unless $getter -> can(" app_id" ) && $getter -> app_id;
99+
100+ my $app_id = $getter -> app_id;
101+ if ($app_id eq $mozreview_app_id ) {
102+ unless (any { $full_method eq $_ } @METHOD_WHITELIST ) {
103+ ThrowCodeError(' unknown_method' , { method => $full_method });
85104 }
86- };
105+ }
87106}
88107
89108__PACKAGE__ -> NAME;
0 commit comments