Cleaned up some stuff from reviewing plan access.

This commit is contained in:
ghendricks%novell.com 2007-02-21 23:38:00 +00:00
parent 7c840e8620
commit 0bc6f7e4cb
7 changed files with 124 additions and 140 deletions

View File

@ -34,13 +34,10 @@ RUNNING
PAUSED
BLOCKED
UNIT
INTEGRATION
FUNCTION
SYSTEM
ACCEPTANCE
INSTALLATION
PERFORMANCE
TR_READ
TR_WRITE
TR_DELETE
TR_ADMIN
REL_AUTHOR
REL_EDITOR
@ -97,11 +94,11 @@ use constant RUNNING => 4;
use constant PAUSED => 5;
use constant BLOCKED => 6;
# Test Plan Types
use constant UNIT => 1;
use constant INTEGRATION => 2;
use constant SYSTEM => 3;
use constant PERFORMANCE => 4;
# Test Plan Permissions (bit flags)
use constant READ => 1;
use constant WRITE => 2;
use constant DELETE => 4;
use constant ADMIN => 8;
use constant REL_AUTHOR => 0;
use constant REL_EDITOR => 1;

View File

@ -56,6 +56,7 @@ use Bugzilla::User;
use Bugzilla::Config;
use Bugzilla::Error;
use Bugzilla::Constants;
use Bugzilla::Testopia::Constants;
use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::TestPlan;
use Bugzilla::Testopia::TestRun;
@ -1188,24 +1189,6 @@ sub _generate_dep_tree {
}
}
=head2 can_unlink_plan
Returns true if this test case can be unlinked from the given plan
=cut
sub can_unlink_plan {
my $self = shift;
my ($plan_id) = @_;
my $plan = Bugzilla::Testopia::TestPlan->new($plan_id);
return 1 if Bugzilla->user->in_group('admin');
return 1 if Bugzilla->user->in_group('Testers') && Param("testopia-allow-group-member-deletes");
return 1 if $plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 4;
return 1 if $plan->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 4;
return 0;
}
=head2 obliterate
Removes this case and all things that reference it.
@ -1235,20 +1218,6 @@ sub obliterate {
return 1;
}
=head2 canedit
Returns true if the logged in user has rights to edit this test case.
=cut
sub canedit {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 2;
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 2;
return 0;
}
=head2 canview
Returns true if the logged in user has rights to view this test case.
@ -1258,8 +1227,20 @@ Returns true if the logged in user has rights to view this test case.
sub canview {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) > 0;
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) > 0;
return 1 if $self->get_user_rights(Bugzilla->user->id) & TR_READ;
return 0;
}
=head2 canedit
Returns true if the logged in user has rights to edit this test case.
=cut
sub canedit {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->get_user_rights(Bugzilla->user->id) & TR_WRITE;
return 0;
}
@ -1277,8 +1258,7 @@ sub candelete {
# Otherwise, check for delete rights on all the plans this is linked to
my $own_all = 1;
foreach my $plan (@{$self->plans}){
if (!($plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 4)
|| !($plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 4)) {
if (!($plan->get_user_rights(Bugzilla->user->id) & TR_DELETE)) {
$own_all = 0;
last;
}
@ -1287,17 +1267,34 @@ sub candelete {
return 0;
}
=head2 can_unlink_plan
Returns true if this test case can be unlinked from the given plan
=cut
sub can_unlink_plan {
my $self = shift;
my ($plan_id) = @_;
my $plan = Bugzilla::Testopia::TestPlan->new($plan_id);
return 1 if Bugzilla->user->in_group('admin');
return 1 if Bugzilla->user->in_group('Testers') && Param("testopia-allow-group-member-deletes");
return 1 if $plan->get_user_rights(Bugzilla->user->id) & DELETE;
return 0;
}
sub get_user_rights {
my $self = shift;
my ($userid, $type) = @_;
my ($userid) = @_;
my $dbh = Bugzilla->dbh;
my ($perms) = $dbh->selectrow_array(
"SELECT MAX(permissions) FROM test_plan_permissions
LEFT JOIN test_case_plans ON test_plan_permissions.plan_id = test_case_plans.plan_id
INNER JOIN test_cases ON test_case_plans.case_id = test_cases.case_id
WHERE userid = ? AND test_plan_permissions.plan_id = ? AND grant_type = ?",
undef, ($userid, $self->id, $type));
WHERE userid = ? AND test_plan_permissions.plan_id = ?",
undef, ($userid, $self->id));
return $perms;
}

View File

@ -1021,8 +1021,7 @@ Returns true if the logged in user has rights to view this case-run.
sub canview {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) > 0;
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) > 0;
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id) & TR_READ;
return 0;
}
@ -1035,8 +1034,7 @@ Returns true if the logged in user has rights to edit this case-run.
sub canedit {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 2;
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 2;
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id) & TR_WRITE;
return 0;
}
@ -1051,8 +1049,7 @@ sub candelete {
return 1 if Bugzilla->user->in_group('admin');
return 0 unless Param("allow-test-deletion");
return 1 if Bugzilla->user->in_group('Testers') && Param("testopia-allow-group-member-deletes");
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 4;
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 4;
return 1 if $self->run->plan->get_user_rights(Bugzilla->user->id) & TR_DELETE;
return 0;
}

View File

@ -46,6 +46,7 @@ use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::Config;
use Bugzilla::Constants;
use Bugzilla::Testopia::Constants;
use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::TestRun;
use Bugzilla::Testopia::TestCase;
@ -430,12 +431,13 @@ sub check_tester {
my ($exists) = $dbh->selectrow_array(
"SELECT 1
FROM test_plan_permissions
WHERE userid = ? AND plan_id = ?",
undef, ($userid, $self->id));
WHERE userid = ? AND plan_id = ? AND grant_type = ?",
undef, ($userid, $self->id, GRANT_DIRECT));
return $exists;
}
=head2 update_plan_type
Update the given type
@ -727,7 +729,8 @@ sub set_tester_regexp {
WHERE plan_id = ?", undef, ($regexp, $permissions, $self->id));
}
else {
$dbh->do("INSERT INTO test_plan_permissions_regexp(plan_id, user_regexp, permissions)
$dbh->do("INSERT INTO test_plan_permissions_regexp
(plan_id, user_regexp, permissions)
VALUES(?,?,?)",
undef, ($self->id, $regexp, $permissions));
}
@ -785,7 +788,8 @@ sub add_tester {
my ($userid, $perms) = @_;
my $dbh = Bugzilla->dbh;
$dbh->do("INSERT INTO test_plan_permissions(userid, plan_id, permissions, grant_type)
$dbh->do("INSERT INTO test_plan_permissions
(userid, plan_id, permissions, grant_type)
VALUES(?,?,?,?)",
undef, ($userid, $self->id, $perms, GRANT_DIRECT));
}
@ -846,21 +850,6 @@ sub obliterate {
return 1;
}
=head2 canedit
Returns true if the logged in user has rights to edit this plan
=cut
sub canedit {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 2;
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 2;
return 0;
}
=head2 canview
Returns true if the logged in user has rights to view this plan
@ -870,11 +859,24 @@ Returns true if the logged in user has rights to view this plan
sub canview {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) > 0;
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) > 0;
return 1 if $self->get_user_rights(Bugzilla->user->id) & TR_READ;
return 0;
}
=head2 canedit
Returns true if the logged in user has rights to edit this plan
=cut
sub canedit {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->get_user_rights(Bugzilla->user->id) & TR_WRITE;
return 0;
}
=head2 candelete
Returns true if the logged in user has rights to delete this plan
@ -886,28 +888,26 @@ sub candelete {
return 1 if Bugzilla->user->in_group('admin');
return 0 unless Param("allow-test-deletion");
return 1 if Bugzilla->user->in_group('Testers') && Param("testopia-allow-group-member-deletes");
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 4;
return 1 if $self->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 4;
return 1 if $self->get_user_rights(Bugzilla->user->id) & TR_DELETE;
return 0;
}
sub canadmin {
my $self = shift;
return 1 if Bugzilla->user->in_group("admin");
return 1 if ($self->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 8);
return 1 if ($self->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 8);
return 1 if ($self->get_user_rights(Bugzilla->user->id) & TR_ADMIN);
return 0;
}
sub get_user_rights {
my $self = shift;
my ($userid, $type) = @_;
my ($userid) = @_;
my $dbh = Bugzilla->dbh;
my ($perms) = $dbh->selectrow_array(
"SELECT permissions FROM test_plan_permissions
WHERE userid = ? AND plan_id = ? AND grant_type = ?",
undef, ($userid, $self->id, $type));
WHERE userid = ? AND plan_id = ?",
undef, ($userid, $self->id));
return $perms;
}
@ -1007,9 +1007,9 @@ sub access_list {
my $dbh = Bugzilla->dbh;
my $ref = $dbh->selectall_arrayref(
"SELECT tpt.userid, permissions
FROM test_plan_permissions AS tpt
JOIN profiles ON profiles.userid = tpt.userid
"SELECT tpp.userid, permissions
FROM test_plan_permissions AS tpp
JOIN profiles ON profiles.userid = tpp.userid
WHERE plan_id = ? AND grant_type = ?
ORDER BY profiles.realname", {'Slice' =>{}}, ($self->id, GRANT_DIRECT));
my @rows;

View File

@ -46,6 +46,7 @@ use strict;
use Bugzilla::Util;
use Bugzilla::User;
use Bugzilla::Constants;
use Bugzilla::Testopia::Constants
use Bugzilla::Config;
use Bugzilla::Testopia::Environment;
use Bugzilla::Bug;
@ -74,17 +75,17 @@ use base qw(Exporter);
=cut
use constant DB_COLUMNS => qw(
test_runs.run_id
test_runs.plan_id
test_runs.environment_id
test_runs.product_version
test_runs.build_id
test_runs.plan_text_version
test_runs.manager_id
test_runs.start_date
test_runs.stop_date
test_runs.summary
test_runs.notes
run_id
plan_id
environment_id
product_version
build_id
plan_text_version
manager_id
start_date
stop_date
summary
notes
);
our $columns = join(", ", DB_COLUMNS);
@ -731,20 +732,6 @@ sub get_environments {
return $ref;
}
=head2 canedit
Returns true if the logged in user has rights to edit this test run.
=cut
sub canedit {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 2;
return 1 if $self->plan->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 2;
return 0;
}
=head2 canview
Returns true if the logged in user has rights to view this test run.
@ -754,12 +741,24 @@ Returns true if the logged in user has rights to view this test run.
sub canview {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) > 0;
return 1 if $self->plan->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) > 0;
return 1 if $self->plan->get_user_rights(Bugzilla->user->id) & TR_READ;
return 0;
}
=head2 canedit
Returns true if the logged in user has rights to edit this test run.
=cut
sub canedit {
my $self = shift;
return 1 if Bugzilla->user->in_group('Testers');
return 1 if $self->plan->get_user_rights(Bugzilla->user->id) & TR_WRITE;
return 0;
}
=head2 candelete
Returns true if the logged in user has rights to delete this test run.
@ -771,8 +770,7 @@ sub candelete {
return 1 if Bugzilla->user->in_group('admin');
return 0 unless Param("allow-test-deletion");
return 1 if Bugzilla->user->in_group('Testers') && Param("testopia-allow-group-member-deletes");
return 1 if $self->plan->get_user_rights(Bugzilla->user->id, GRANT_REGEXP) & 4;
return 1 if $self->plan->get_user_rights(Bugzilla->user->id, GRANT_DIRECT) & 4;
return 1 if $self->plan->get_user_rights(Bugzilla->user->id) & TR_DELETE;
return 0;
}

View File

@ -56,8 +56,8 @@ use Bugzilla::Error;
=cut
use constant DB_COLUMNS => qw(
test_tags.tag_id
test_tags.tag_name
tag_id
tag_name
);

View File

@ -30,13 +30,13 @@ use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::Product;
use vars qw($vars);
use Data::Dumper;
require 'globals.pl';
my $template = Bugzilla->template;
my $cgi = Bugzilla->cgi;
Bugzilla->login();
Bugzilla->login(LOGIN_REQUIRED);
print $cgi->header;
my $plan_id = trim($cgi->param('plan_id') || '');
@ -55,9 +55,6 @@ unless ($plan->canadmin){
ThrowUserError('testopia-plan-acl-denied', {plan_id => $plan->id});
}
#print Dumper($plan->access_list);
if ($action eq 'Apply Changes'){
do_update();
display();
@ -65,7 +62,6 @@ if ($action eq 'Apply Changes'){
elsif ($action eq 'Add User'){
do_update();
my $dbh = Bugzilla->dbh;
my $userid = DBNameToIdAndCheck(trim($cgi->param('adduser')));
ThrowUserError('testopia-tester-already-on-list', {'login' => $cgi->param('adduser')})
if ($plan->check_tester($userid));
@ -74,10 +70,10 @@ elsif ($action eq 'Add User'){
# The order we check these is important since each permission
# implies the prior ones.
$perms = $cgi->param("nr") ? 1 : $perms;
$perms = $cgi->param("nw") ? 3 : $perms;
$perms = $cgi->param("nd") ? 7 : $perms;
$perms = $cgi->param("na") ? 15 : $perms;
$perms |= TR_READ if $cgi->param("nr");
$perms |= TR_WRITE if $cgi->param("nw");
$perms |= TR_DELETE if $cgi->param("nd");
$perms |= TR_ADMIN if $cgi->param("na");
$plan->add_tester($userid, $perms);
@ -97,9 +93,9 @@ else{
}
sub do_update {
# We need at least on admin
# We need at least one admin
my $params = join(" ", $cgi->param());
ThrowUserErorr('testopia-no-admins') unless $params =~ /a\d+/;
ThrowUserError('testopia-no-admins') unless $params =~ /(^|\s)a\d+($|\s)/;
my $tester_regexp = $cgi->param('userregexp');
trick_taint($tester_regexp);
@ -108,23 +104,22 @@ sub do_update {
# The order we check these is important since each permission
# implies the prior ones.
$regexp_perms = $cgi->param('pr') ? 1 : $regexp_perms;
$regexp_perms = $cgi->param('pw') ? 3 : $regexp_perms;
$regexp_perms = $cgi->param('pd') ? 7 : $regexp_perms;
$regexp_perms = $cgi->param('pa') ? 15 : $regexp_perms;
$regexp_perms |= TR_READ if $cgi->param('pr');
$regexp_perms |= TR_WRITE if $cgi->param('pw');
$regexp_perms |= TR_DELETE if $cgi->param('pd');
$regexp_perms |= TR_ADMIN if $cgi->param('pa');
$plan->set_tester_regexp($tester_regexp, $regexp_perms);
my $dbh = Bugzilla->dbh;
foreach my $row (@{$plan->access_list}){
my $perms = 0;
# The order we check these is important since each permission
# implies the prior ones.
$perms = $cgi->param('r'.$row->{'user'}->id) ? 1 : $perms;
$perms = $cgi->param('w'.$row->{'user'}->id) ? 3 : $perms;
$perms = $cgi->param('d'.$row->{'user'}->id) ? 7 : $perms;
$perms = $cgi->param('a'.$row->{'user'}->id) ? 15 : $perms;
$perms |= TR_READ if $cgi->param('r'.$row->{'user'}->id);
$perms |= TR_WRITE if $cgi->param('w'.$row->{'user'}->id);
$perms |= TR_DELETE if $cgi->param('d'.$row->{'user'}->id);
$perms |= TR_ADMIN if $cgi->param('a'.$row->{'user'}->id);
$plan->update_tester($row->{'user'}->id, $perms);
}