From eef3a0b65429acdf39dc581ab53b9cea9850f5ec Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 23 Mar 2006 00:01:35 +0000 Subject: [PATCH] getting closer to having approvals work --- docs/upgrades/upgrade_6.8.7-6.99.0.pl | 1 + lib/WebGUI/Operation.pm | 1 + lib/WebGUI/Operation/VersionTag.pm | 23 ++++++++++ lib/WebGUI/VersionTag.pm | 15 +++++++ .../Activity/RequestApprovalForVersionTag.pm | 40 +++++++++++++++++- lib/WebGUI/Workflow/Instance.pm | 42 +++++++++++++++---- 6 files changed, 114 insertions(+), 8 deletions(-) diff --git a/docs/upgrades/upgrade_6.8.7-6.99.0.pl b/docs/upgrades/upgrade_6.8.7-6.99.0.pl index 7b9f93539..d18aa73f7 100644 --- a/docs/upgrades/upgrade_6.8.7-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.7-6.99.0.pl @@ -121,6 +121,7 @@ sub addWorkflow { $session->db->write("alter table assetVersionTag add column lockedBy varchar(22) binary not null"); $session->db->write("alter table assetVersionTag add column groupToUse varchar(22) binary not null"); $session->db->write("alter table assetVersionTag add column workflowId varchar(22) binary not null"); + $session->db->write("alter table assetVersionTag add column workflowInstanceId varchar(22) binary"); $session->db->write("alter table assetVersionTag add column comments text"); $session->db->write("create table WorkflowSchedule ( taskId varchar(22) binary not null primary key, diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index 0d2a54227..ad4ff7cd2 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -82,6 +82,7 @@ sub getOperations { 'commitVersionTag' => 'WebGUI::Operation::VersionTag', 'commitVersionTagConfirm' => 'WebGUI::Operation::VersionTag', 'manageCommittedVersions' => 'WebGUI::Operation::VersionTag', + 'approveVersionTag' => 'WebGUI::Operation::VersionTag', 'manageVersions' => 'WebGUI::Operation::VersionTag', 'manageRevisionsInTag' => 'WebGUI::Operation::VersionTag', 'rollbackVersionTag' => 'WebGUI::Operation::VersionTag', diff --git a/lib/WebGUI/Operation/VersionTag.pm b/lib/WebGUI/Operation/VersionTag.pm index c1fa9eca2..0ecc8d69d 100644 --- a/lib/WebGUI/Operation/VersionTag.pm +++ b/lib/WebGUI/Operation/VersionTag.pm @@ -40,6 +40,29 @@ These methods are available from this class: =cut +#------------------------------------------------------------------- + +=head2 www_editVersionTag ( session ) + +Sets an approval for a version tag. + +=cut + +sub www_approveVersionTag { + my $session = shift; + my $tag = WebGUI::VersionTag->new($session, $session->form->param("tagId")); + my $instance = $tag->getWorkflowInstance; + my $activity = $instance->getNextActivity; + return $session->privilege->insufficient() unless ($session->user->isInGroup($activity->get("groupToApprove"))); + if ($session->form->process("status", "selectBox") eq "approved") { + $activity->setApproved($instance); + } else { + $activity->setDenied($instance); + } + $tag->set({comments=>$session->form->process("comments", "textarea")}); + return www_manageVersions($session); +} + #------------------------------------------------------------------- =head2 www_editVersionTag ( session, [ tagId ] ) diff --git a/lib/WebGUI/VersionTag.pm b/lib/WebGUI/VersionTag.pm index 9722302d6..aed662226 100644 --- a/lib/WebGUI/VersionTag.pm +++ b/lib/WebGUI/VersionTag.pm @@ -150,6 +150,19 @@ sub getId { #------------------------------------------------------------------- +=head2 getWorkflowInstance ( ) + +Returns a reference to the workflow instance attached to this version tag if any. + +=cut + +sub getWorkflowInstance { + my $self = shift; + return WebGUI::Workflow::Instance->new($self->session, $self->get("workflowInstanceId")); +} + +#------------------------------------------------------------------- + =head2 getWorking ( session, noCreate ) This is a class method. Returns the current working version tag for this user as set by setWorking(). If there is no current working tag an autotag will be created and assigned as the working tag for this user. @@ -245,6 +258,8 @@ sub requestCommit { methodName=>"new", parameters=>$self->getId }); + $self->{_data}{workflowInstanceId} = $instance->getId; + $self->session->db->setRow("assetVersionTag","tagId",$self->{_data}); } diff --git a/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm b/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm index 87e526021..b7e9c5f73 100644 --- a/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm +++ b/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm @@ -103,12 +103,15 @@ sub execute { message=>join("\n\n",$self->get("message"), $self->session->url->page("op=manageRevisionsInTag;workflowInstanceId=".$instance->getId.";tagId=".$versionTag->getId), $versionTag->get('name'), $versionTag->get("comments")), - groupId=>$self->get("groupToApprove") + groupId=>$self->get("groupToApprove"), + status=>'pending' }); $instance->setScratch("messageId",$message->getId); $instance->setScratch("status","notified"); return $self->WAITING; } elsif ($instance->getScratch("status") eq "denied") { + my $message = $inbox->getMessage($instance->getScratch("messageId")); + $message->setCompleted; my $newInstance = WebGUI::Workflow::Instance->create($self->session, { workflowId=>$self->get("doOnDeny"), methodName=>$instance->get("methodName"), @@ -129,6 +132,41 @@ sub execute { } +#------------------------------------------------------------------- + +=head2 setApproved ( insstance ) + +Marks this approved so that the workflow engine knows it can continue on as approved. + +=head3 instance + +A reference to the instance that you wish to set this approved. + +=cut + +sub setApproved { + my $self = shift; + my $instance = shift; + $instance->setScratch("status","approved"); +} + +#------------------------------------------------------------------- + +=head2 setDenied ( insstance ) + +Marks this approved so that the workflow engine knows it can continue on as denied. + +=head3 instance + +A reference to the instance that you wish to set this denied. + +=cut + +sub setDenied { + my $self = shift; + my $instance = shift; + $instance->setScratch("status","denied"); +} 1; diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index 1b5d5741e..e9fb0267e 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -105,7 +105,7 @@ sub deleteScratch { my $self = shift; my $name = shift; delete $self->{_scratch}{$name}; - $self->session->db->write("delete from WorkflowInstanceScratch where instanceId=?", [$self->getId]); + $self->session->db->write("delete from WorkflowInstanceScratch where instanceId=? and name=?", [$self->getId, $name]); } #------------------------------------------------------------------- @@ -142,6 +142,34 @@ sub get { #------------------------------------------------------------------- +=head2 getId ( ) + +Returns the ID of this instance. + +=cut + +sub getId { + my $self = shift; + return $self->{_id}; +} + +#------------------------------------------------------------------- + +=head2 getNextActivity ( ) + +Returns a reference to the next activity in this workflow from the current position of this instance. + +=cut + +sub getNextActivity { + my $self = shift; + my $workflow = $self->getWorkflow; + return undef unless defined $workflow; + return $workflow->getNextActivity($self->get("currentActivityId")); +} + +#------------------------------------------------------------------- + =head2 getScratch ( name ) Returns the value for a given scratch variable. @@ -159,15 +187,15 @@ sub getScratch { #------------------------------------------------------------------- -=head2 getId ( ) +=head2 getWorkflow ( ) -Returns the ID of this instance. +Returns a reference to the workflow object this instance is associated with. =cut -sub getId { +sub getWorkflow { my $self = shift; - return $self->{_id}; + return WebGUI::Workflow->new($self->session, $self->get("workflowId")); } #------------------------------------------------------------------- @@ -212,7 +240,7 @@ Executes the next iteration in this workflow. Returns a status code based upon w sub run { my $self = shift; - my $workflow = WebGUI::Workflow->new($self->session, $self->get("workflowId")); + my $workflow = $self->getWorkflow; return "undefined" unless (defined $workflow); return "disabled" unless ($workflow->get("enabled")); my $activity = $workflow->getNextActivity($self->get("currentActivityId")); @@ -339,7 +367,7 @@ sub setScratch { my $name = shift; my $value = shift; delete $self->{_scratch}; - $self->session->write("replace into WorkflowInstanceScratch (instanceId, name, value) values (?,?,?)", [$self->getId, $name, $value]); + $self->session->db->write("replace into WorkflowInstanceScratch (instanceId, name, value) values (?,?,?)", [$self->getId, $name, $value]); }