summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Zalewa <zaloon@gmail.com>2018-02-28 23:13:43 +0100
committerdklawren <dklawren@users.noreply.github.com>2018-02-28 23:13:43 +0100
commitc7fd0908bd85bc5761aa28fe9c893f93394bfd4b (patch)
tree2aa2a35a97c7c38018baad35a0d92504ca59570d
parent26f4bcb1ce2dad98c457c3b6b755cca134485b14 (diff)
downloadbugzilla-c7fd0908bd85bc5761aa28fe9c893f93394bfd4b.tar.gz
bugzilla-c7fd0908bd85bc5761aa28fe9c893f93394bfd4b.tar.xz
Bug 1440239 - PhabBugz - Assign a secure-revision
-rw-r--r--extensions/PhabBugz/lib/Feed.pm7
-rw-r--r--extensions/PhabBugz/lib/Project.pm14
-rw-r--r--extensions/PhabBugz/lib/Revision.pm33
-rw-r--r--extensions/PhabBugz/lib/Util.pm27
-rw-r--r--extensions/Push/lib/Connector/Phabricator.pm28
5 files changed, 92 insertions, 17 deletions
diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm
index c7d6d0a29..3b158d2d6 100644
--- a/extensions/PhabBugz/lib/Feed.pm
+++ b/extensions/PhabBugz/lib/Feed.pm
@@ -23,11 +23,11 @@ use Bugzilla::Extension::PhabBugz::Revision;
use Bugzilla::Extension::PhabBugz::User;
use Bugzilla::Extension::PhabBugz::Util qw(
add_security_sync_comments
- create_private_revision_policy
create_revision_attachment
edit_revision_policy
get_bug_role_phids
get_phab_bmo_ids
+ get_project_phid
get_security_sync_groups
is_attachment_phab_revision
make_revision_public
@@ -183,6 +183,8 @@ sub process_revision_change {
$self->logger->debug('Bug is public so setting view/edit public');
$revision->set_policy('view', 'public');
$revision->set_policy('edit', 'users');
+ my $secure_project_phid = get_project_phid('secure-revision');
+ $revision->remove_project($secure_project_phid);
}
# else bug is private.
else {
@@ -225,6 +227,9 @@ sub process_revision_change {
$revision->set_policy('edit', $new_policy->phid);
}
+ my $secure_project_phid = get_project_phid('secure-revision');
+ $revision->add_project($secure_project_phid);
+
my $subscribers = get_bug_role_phids($bug);
$revision->set_subscribers($subscribers);
}
diff --git a/extensions/PhabBugz/lib/Project.pm b/extensions/PhabBugz/lib/Project.pm
index 91dc2133d..fd09cbecf 100644
--- a/extensions/PhabBugz/lib/Project.pm
+++ b/extensions/PhabBugz/lib/Project.pm
@@ -232,6 +232,20 @@ sub update {
}
}
+ if ($self->{add_projects}) {
+ push(@{ $data->{transactions} }, {
+ type => 'projects.add',
+ value => $self->{add_projects}
+ });
+ }
+
+ if ($self->{remove_projects}) {
+ push(@{ $data->{transactions} }, {
+ type => 'projects.remove',
+ value => $self->{remove_projects}
+ });
+ }
+
my $result = request( 'project.edit', $data );
return $result;
diff --git a/extensions/PhabBugz/lib/Revision.pm b/extensions/PhabBugz/lib/Revision.pm
index a897acf31..c114de78c 100644
--- a/extensions/PhabBugz/lib/Revision.pm
+++ b/extensions/PhabBugz/lib/Revision.pm
@@ -9,6 +9,7 @@ package Bugzilla::Extension::PhabBugz::Revision;
use 5.10.1;
use Moo;
+
use Scalar::Util qw(blessed);
use Types::Standard -all;
use Type::Utils;
@@ -249,6 +250,20 @@ sub update {
}
}
+ if ($self->{add_projects}) {
+ push(@{ $data->{transactions} }, {
+ type => 'projects.add',
+ value => $self->{add_projects}
+ });
+ }
+
+ if ($self->{remove_projects}) {
+ push(@{ $data->{transactions} }, {
+ type => 'projects.remove',
+ value => $self->{remove_projects}
+ });
+ }
+
my $result = request( 'differential.revision.edit', $data );
return $result;
@@ -390,4 +405,20 @@ sub set_policy {
$self->{set_policy}->{$name} = $policy;
}
-1; \ No newline at end of file
+sub add_project {
+ my ( $self, $project ) = @_;
+ $self->{add_projects} ||= [];
+ my $project_phid = blessed $project ? $project->phid : $project;
+ return undef unless $project_phid;
+ push @{ $self->{add_projects} }, $project_phid;
+}
+
+sub remove_project {
+ my ( $self, $project ) = @_;
+ $self->{remove_projects} ||= [];
+ my $project_phid = blessed $project ? $project->phid : $project;
+ return undef unless $project_phid;
+ push @{ $self->{remove_projects} }, $project_phid;
+}
+
+1;
diff --git a/extensions/PhabBugz/lib/Util.pm b/extensions/PhabBugz/lib/Util.pm
index 838283f97..5658ac9d8 100644
--- a/extensions/PhabBugz/lib/Util.pm
+++ b/extensions/PhabBugz/lib/Util.pm
@@ -273,19 +273,26 @@ sub add_comment_to_revision {
sub get_project_phid {
my $project = shift;
+ my $memcache = Bugzilla->memcached;
- my $data = {
- queryKey => 'all',
- constraints => {
- name => $project
- }
- };
+ # Check memcache
+ my $project_phid = $memcache->get_config({ key => "phab_project_phid_" . $project });
+ if (!$project_phid) {
+ my $data = {
+ queryKey => 'all',
+ constraints => {
+ name => $project
+ }
+ };
- my $result = request('project.search', $data);
- return undef
- unless (exists $result->{result}{data} && @{ $result->{result}{data} });
+ my $result = request('project.search', $data);
+ return undef
+ unless (exists $result->{result}{data} && @{ $result->{result}{data} });
- return $result->{result}{data}[0]{phid};
+ $project_phid = $result->{result}{data}[0]{phid};
+ $memcache->set_config({ key => "phab_project_phid_" . $project, data => $project_phid });
+ }
+ return $project_phid;
}
sub create_project {
diff --git a/extensions/Push/lib/Connector/Phabricator.pm b/extensions/Push/lib/Connector/Phabricator.pm
index 8c3b56112..5da64901a 100644
--- a/extensions/Push/lib/Connector/Phabricator.pm
+++ b/extensions/Push/lib/Connector/Phabricator.pm
@@ -20,11 +20,19 @@ use Bugzilla::User;
use Bugzilla::Extension::PhabBugz::Constants;
use Bugzilla::Extension::PhabBugz::Util qw(
- add_comment_to_revision create_private_revision_policy
- edit_revision_policy get_attachment_revisions get_bug_role_phids
- intersect make_revision_public
- make_revision_private set_revision_subscribers
- get_security_sync_groups add_security_sync_comments);
+ add_comment_to_revision
+ add_security_sync_comments
+ create_private_revision_policy
+ edit_revision_policy
+ get_attachment_revisions
+ get_bug_role_phids
+ get_project_phid
+ get_security_sync_groups
+ intersect
+ make_revision_public
+ make_revision_private
+ set_revision_subscribers
+);
use Bugzilla::Extension::Push::Constants;
use Bugzilla::Extension::Push::Util qw(is_public);
@@ -96,9 +104,14 @@ sub send {
$subscribers = get_bug_role_phids($bug);
}
+ my $secure_project_phid = get_project_phid('secure-revision');
+
foreach my $revision (@revisions) {
my $revision_phid = $revision->{phid};
+ my $rev_obj = Bugzilla::Extension::PhabBugz::Revision->new_from_query({ phids => [ $revision_phid ] });
+ my $revision_updated;
+
if ( $is_public && $group_change ) {
Bugzilla->audit(sprintf(
'Making revision %s public for bug %s',
@@ -106,6 +119,8 @@ sub send {
$bug->id
));
make_revision_public($revision_phid);
+ $rev_obj->remove_project($secure_project_phid);
+ $revision_updated = 1;
}
elsif ( !$is_public && $group_change ) {
Bugzilla->audit(sprintf(
@@ -115,6 +130,8 @@ sub send {
));
my $policy_phid = create_private_revision_policy( $bug, \@set_groups );
edit_revision_policy( $revision_phid, $policy_phid, $subscribers );
+ $rev_obj->add_project($secure_project_phid);
+ $revision_updated = 1;
}
elsif ( !$is_public && !$group_change ) {
Bugzilla->audit(sprintf(
@@ -124,6 +141,7 @@ sub send {
));
set_revision_subscribers( $revision_phid, $subscribers );
}
+ $rev_obj->update() if $revision_updated;
}
return PUSH_RESULT_OK;