Added new API method commitAsUser allowing developers to commit version tags as other users
This commit is contained in:
parent
5a904a85db
commit
053292a75b
3 changed files with 84 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
7.9.7
|
7.9.7
|
||||||
- fixed #11596: Calendar: all day events leaking
|
- fixed #11596: Calendar: all day events leaking
|
||||||
- fixed #11604: scheduled workflows getting deleted
|
- fixed #11604: scheduled workflows getting deleted
|
||||||
|
- added API method commitAsUser allowing developers to commit version tags as other users
|
||||||
|
|
||||||
7.9.6
|
7.9.6
|
||||||
- new checkbox in the asset manager for clearing the package flag on import
|
- new checkbox in the asset manager for clearing the package flag on import
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,64 @@ sub commit {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 commitAsUser ( userId , options )
|
||||||
|
|
||||||
|
Commits the working tab. If userId is passed in, commit will be done as that user
|
||||||
|
|
||||||
|
=head3 userId
|
||||||
|
|
||||||
|
User to commit tag as
|
||||||
|
|
||||||
|
=head3 options
|
||||||
|
|
||||||
|
hash ref of options to pass in
|
||||||
|
|
||||||
|
=head4 comments
|
||||||
|
|
||||||
|
optional comments to set in the version tag
|
||||||
|
|
||||||
|
=head4 commitNow
|
||||||
|
|
||||||
|
optional boolean which, if set, will perform an immediate.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub commitAsUser {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $config = $session->config;
|
||||||
|
my $userId = shift;
|
||||||
|
my $options = shift;
|
||||||
|
my $commitNow = $options->{commitNow};
|
||||||
|
my $comments = $options->{comments};
|
||||||
|
|
||||||
|
return 0 unless (defined $userId);
|
||||||
|
|
||||||
|
#Open a new session
|
||||||
|
my $new_session = WebGUI::Session->open( $config->getWebguiRoot, $config->getFilename );
|
||||||
|
#Set the userId in the new session
|
||||||
|
$new_session->user( { userId => $userId } );
|
||||||
|
|
||||||
|
#Clone the tag into a new version tag in the new session
|
||||||
|
my $new_tag = __PACKAGE__->new( $new_session, $self->getId );
|
||||||
|
|
||||||
|
if ( defined $new_tag ) {
|
||||||
|
$new_tag->set( { comments => $comments } );
|
||||||
|
if ($commitNow) {
|
||||||
|
$new_tag->commit;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$new_tag->requestCommit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#End the new session
|
||||||
|
$new_session->var->end;
|
||||||
|
$new_session->close;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use lib "$FindBin::Bin/lib";
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::VersionTag;
|
use WebGUI::VersionTag;
|
||||||
use Test::More tests => 81; # increment this value for each test you create
|
use Test::More tests => 85; # increment this value for each test you create
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
|
@ -184,8 +184,31 @@ is($tag3->getRevisionCount, 5, 'original tag still with five revisions');
|
||||||
$tag4->clearWorking;
|
$tag4->clearWorking;
|
||||||
$tag3->rollback;
|
$tag3->rollback;
|
||||||
$tag4->rollback;
|
$tag4->rollback;
|
||||||
($asset1, $asset2, $asset3, $tag3, $tag4) = ();
|
|
||||||
|
|
||||||
|
#Test commitAsUser
|
||||||
|
my $tag5 = WebGUI::VersionTag->create($session, {});
|
||||||
|
$tag5->setWorking;
|
||||||
|
my $asset5 = WebGUI::Asset->getRoot($session)->addChild({ className => 'WebGUI::Asset::Snippet' });
|
||||||
|
is($tag5->get("createdBy"),1,'tag created by visitor');
|
||||||
|
$tag5->commitAsUser(3);
|
||||||
|
$tag5 = WebGUI::VersionTag->new($session, $tag5->getId); #Get the tag again - properties have changed
|
||||||
|
is($tag5->get("committedBy"),3,'tag committed by admin');
|
||||||
|
$tag5->clearWorking;
|
||||||
|
$tag5->rollback;
|
||||||
|
|
||||||
|
#Test commitAsUser with options
|
||||||
|
my $tag6 = WebGUI::VersionTag->create($session, {});
|
||||||
|
$tag6->setWorking;
|
||||||
|
my $asset6 = WebGUI::Asset->getRoot($session)->addChild({ className => 'WebGUI::Asset::Snippet' });
|
||||||
|
$tag6->commitAsUser(3, { commitNow => "yes" });
|
||||||
|
$tag6 = WebGUI::VersionTag->new($session, $tag6->getId); #Get the tag again - properties have changed
|
||||||
|
is($tag6->get("committedBy"),3,'tag committed by admin again');
|
||||||
|
$asset6 = WebGUI::Asset->newByDynamicClass($session,$asset6->getId); #Get the asset again - properties have changed
|
||||||
|
is($asset6->get("status"),"approved","asset status approved");
|
||||||
|
$tag6->clearWorking;
|
||||||
|
$tag6->rollback;
|
||||||
|
|
||||||
|
($asset1, $asset2, $asset3, $asset5, $asset6, $tag3, $tag4, $tag5, $tag6) = ();
|
||||||
#additional tests for versionTagMode
|
#additional tests for versionTagMode
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue