diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 45529df21..e93a93d47 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.7.0 - fixed: Template parser cannot be set + - fixed #9836: Matrix: Group to Add Listings is missing 7.6.14 - fixed: IE6 shows Admin Bar over Asset Manager diff --git a/docs/upgrades/upgrade_7.5.40-7.6.10.pl b/docs/upgrades/upgrade_7.5.40-7.6.10.pl index c96d7223c..3d368a284 100644 --- a/docs/upgrades/upgrade_7.5.40-7.6.10.pl +++ b/docs/upgrades/upgrade_7.5.40-7.6.10.pl @@ -254,7 +254,7 @@ sub upgradeMatrix { my $session = shift; print "\tUpgrading matrix assets... \n" unless $quiet; my $db = $session->db; - $db->write("alter table Matrix drop column groupToRate, drop column groupToAdd, drop column privilegedGroup, + $db->write("alter table Matrix drop column groupToRate, drop column privilegedGroup, drop column ratingTimeout, drop column ratingTimeoutPrivileged, drop column ratingDetailTemplateId, drop column visitorCacheTimeout"); $db->write("alter table Matrix add column defaultSort char(22) not null default 'score', @@ -337,6 +337,7 @@ sub upgradeMatrix { $listing->{title} = $listing->{productName}; $listing->{version} = $listing->{versionNumber}; $listing->{screenshots} = $listing->{storageId}; + $listing->{ownerUserId} = $listing->{maintainerId}; $listing->{productURL} = $listing->{productUrl}; $listing->{manufacturerURL} = $listing->{manufacturerUrl}; my $newMatrixListing = $matrix->addChild($listing,undef,undef,{skipAutoCommitWorkflows=>1}); diff --git a/docs/upgrades/upgrade_7.6.14-7.7.0.pl b/docs/upgrades/upgrade_7.6.14-7.7.0.pl index a4d4d4a41..1f480ada3 100644 --- a/docs/upgrades/upgrade_7.6.14-7.7.0.pl +++ b/docs/upgrades/upgrade_7.6.14-7.7.0.pl @@ -32,8 +32,20 @@ my $session = start(); # this line required # upgrade functions go here +addGroupToAddToMatrix( $session ); + finish($session); # this line required +#---------------------------------------------------------------------------- +sub addGroupToAddToMatrix { + my $session = shift; + print "\tAdding groupToAdd to Matrix table, if needed... \n" unless $quiet; + my $sth = $session->db->read('describe Matrix groupToAdd'); + if (! defined $sth->hashRef) { + $session->db->write("alter table Matrix add column groupToAdd char(22) default 2"); + } + print "Done.\n" unless $quiet; +} #---------------------------------------------------------------------------- # Describe what our function does diff --git a/docs/upgrades/upgrade_7.6.3-7.6.4.pl b/docs/upgrades/upgrade_7.6.3-7.6.4.pl index b47fb0534..7a850c9eb 100644 --- a/docs/upgrades/upgrade_7.6.3-7.6.4.pl +++ b/docs/upgrades/upgrade_7.6.3-7.6.4.pl @@ -61,7 +61,7 @@ sub upgradeMatrix { my $session = shift; print "\tUpgrading matrix assets... \n" unless $quiet; my $db = $session->db; - $db->write("alter table Matrix drop column groupToRate, drop column groupToAdd, drop column privilegedGroup, + $db->write("alter table Matrix drop column groupToRate, drop column privilegedGroup, drop column ratingTimeout, drop column ratingTimeoutPrivileged, drop column ratingDetailTemplateId, drop column visitorCacheTimeout"); $db->write("alter table Matrix add column defaultSort char(22) not null default 'score', @@ -144,6 +144,7 @@ sub upgradeMatrix { $listing->{title} = $listing->{productName}; $listing->{version} = $listing->{versionNumber}; $listing->{screenshots} = $listing->{storageId}; + $listing->{ownerUserId} = $listing->{maintainerId}; $listing->{productURL} = $listing->{productUrl}; $listing->{manufacturerURL} = $listing->{manufacturerUrl}; my $newMatrixListing = $matrix->addChild($listing,undef,undef,{skipAutoCommitWorkflows=>1}); diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 5e88bedc8..511f5dbc6 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -58,6 +58,43 @@ sub addRevision { return $newSelf; } +#---------------------------------------------------------------------------- + +=head2 canAdd ( ) + +Override canAdd to ignore its permissions check. Permissions are handled +by the parent Matrix. + +=cut + +sub canAdd { + return 1; +} + +#---------------------------------------------------------------------------- + +=head2 canEdit ( ) + +Returns true if the user can edit this asset. C is a WebGUI user ID. + +Users can edit this Matrix listing if they are the owner, or if they can edit +the parent Matrix. + +=cut + +sub canEdit { + my $self = shift; + + if ( $self->session->form->process("assetId") eq "new" ) { + return $self->getParent->canAddMatrixListing(); + } + else { + return 1 if $self->session->user->userId eq $self->get("ownerUserId"); + + return $self->getParent->canEdit(); + } +} + #------------------------------------------------------------------- =head2 definition ( session, definition ) @@ -327,7 +364,7 @@ sub getEditForm { $form->raw( ''. - WebGUI::Form::Button($session, {}). + WebGUI::Form::Submit($session, {}). WebGUI::Form::Button($session, { -value => $i18n->get('cancel', 'WebGUI'), -extras => q|onclick="history.go(-1);" class="backwardButton"| @@ -580,6 +617,14 @@ sub view { if ($emailSent){ $var->{emailSent} = 1; } + + unless($self->hasBeenCommitted){ + my $workflowInstanceId = $db->quickScalar("select workflowInstanceId from assetVersionTag where tagId =?" + ,[$self->get('tagId')]); + $var->{canApprove} = $self->getParent->canEdit; + $var->{approveOrDenyUrl} = $self->getUrl("op=manageRevisionsInTag;workflowInstanceId=".$workflowInstanceId + .";tagId=".$self->get('tagId')); + } $var->{canEdit} = $self->canEdit; $var->{editUrl} = $self->getUrl("func=edit"); $var->{controls} = $self->getToolbar; @@ -835,12 +880,14 @@ Web facing method which is the default edit page sub www_edit { my $self = shift; - - return $self->session->privilege->noAccess() unless $self->getParent->canAddMatrixListing(); - my $i18n = WebGUI::International->new($self->session, "Asset_MatrixListing"); - return $self->session->privilege->insufficient() unless $self->canEdit; - return $self->session->privilege->locked() unless $self->canEditIfLocked; + + if($self->session->form->process('func') eq 'add'){ + return $self->session->privilege->noAccess() unless $self->getParent->canAddMatrixListing(); + }else{ + return $self->session->privilege->insufficient() unless $self->canEdit; + return $self->session->privilege->locked() unless $self->canEditIfLocked; + } my $var = $self->get; my $matrix = $self->getParent; diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 68ba4ee2f..355e65698 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -30,10 +30,46 @@ Returns true if able to add MatrixListings. sub canAddMatrixListing { my $self = shift; + my $user = $self->session->user; - return 0 if $self->session->user->isVisitor; + # Users in the groupToAdd group can add listings + if ( $user->isInGroup( $self->get("groupToAdd") ) ) { + return 1; + } + # Users who can edit matrix can add listings + else { + return $self->canEdit; + } - return 1; +} + +#---------------------------------------------------------------------------- + +=head2 canEdit ( [userId] ) + +Returns true if the user can edit this Matrix. + +Also checks if a user is adding a Matrix Listing and allows them to if they are +part of the C group. + +=cut + +sub canEdit { + my $self = shift; + my $userId = shift || $self->session->user->userId; + + my $form = $self->session->form; + if ( $form->get('func') eq "editSave" && $form->get('assetId') eq "new" && $form->get( 'class' )->isa( +'WebGUI::Asset::MatrixListing' ) ) { + return $self->canAddMatrixListing(); + } + else { + if ($userId eq $self->get("ownerUserId")) { + return 1; + } + my $user = WebGUI::User->new($self->session, $userId); + return $user->isInGroup($self->get("groupIdEdit")); + } } #------------------------------------------------------------------- @@ -164,6 +200,13 @@ sub definition { hoverHelp =>$i18n->get('max comparisons privileged description'), label =>$i18n->get('max comparisons privileged label'), }, + groupToAdd=>{ + fieldType =>"group", + tab =>"security", + defaultValue =>2, + hoverHelp =>$i18n->get('group to add description'), + label =>$i18n->get('group to add label'), + }, submissionApprovalWorkflowId=>{ fieldType =>"workflow", tab =>"security", @@ -543,7 +586,8 @@ sub view { }) }; foreach my $pendingListing (@pendingListings){ push (@{ $var->{pending_loop} }, { - url => $pendingListing->getUrl, + url => $pendingListing->getUrl + ."?func=view;revision=".$pendingListing->get('revisionDate'), name => $pendingListing->get('title'), }); } diff --git a/lib/WebGUI/i18n/English/Asset_Matrix.pm b/lib/WebGUI/i18n/English/Asset_Matrix.pm index 90f7af55c..3a02c1826 100644 --- a/lib/WebGUI/i18n/English/Asset_Matrix.pm +++ b/lib/WebGUI/i18n/English/Asset_Matrix.pm @@ -372,6 +372,11 @@ listing,|, lastUpdated => 0, }, + 'group to add description' => { + message => q|Select the group that is allowed to add listings to this matrix.|, + lastUpdated => 0, + }, + 'ratings duration description' => { message => q|Select the interval after which old ratings are cleaned out.|, lastUpdated => 0, @@ -487,6 +492,11 @@ listing,|, lastUpdated => 0, }, + 'group to add label' => { + message => q|Group To Add|, + lastUpdated => 0, + }, + 'ratings duration label' => { message => q|Ratings Duration|, lastUpdated => 0, @@ -750,6 +760,12 @@ selectBox.

| message => q|Hide/show stickied|, }, + 'approve or deny label' => { + lastUpdated => 0, + message => q|Approve/Deny|, + context => q|Label for the approve or deny link on the matrix listing detail screen.|, + }, + 'matrix asset template variables title' => { lastUpdated => 0, message => q|Matrix Asset Template Variables|,