Skip to content

Commit

Permalink
Add reversion to desk view.
Browse files Browse the repository at this point in the history
Added the "and Revert" or "and Delete" option to the "Check In" menu on desk/My Workspace views. This saves the user from having to click "Edit" and then "Cancel Checkout". Suggested by Matt Rolf and Phillip Smith. In order to make this happen, the code that handles cancelling a checkout, which was duplicated nearly verbatim in the callbacks for the story, media, and template profiles has been factored out into a new class `Bric::App::Callback::Util::Asset`. [#62 state:resolved]
  • Loading branch information
theory committed Jan 20, 2010
1 parent 954e1fc commit d13ea3e
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 154 deletions.
7 changes: 5 additions & 2 deletions comp/widgets/desk/desk_item.html
Expand Up @@ -201,8 +201,11 @@ <h4>Publish:</h4>
push @$checkin_opts, @and_publish;
}
}
my @and_shelve = ['shelve', $lang->maketext('and Shelve')];
push @$checkin_opts, @and_shelve;
push @$checkin_opts, (
['shelve', $lang->maketext('and Shelve')],
['cancel', $lang->maketext('and ' . ($obj->get_version == 0 ? 'Delete' : 'Revert'))],
);

}

my ($name, $date, $date_label, $type_label, $uri, $uuid);
Expand Down
27 changes: 24 additions & 3 deletions lib/Bric/App/Callback/Desk.pm
Expand Up @@ -12,6 +12,7 @@ use Bric::App::Session qw(:state :user);
use Bric::App::Event qw(log_event);
use Bric::App::Util qw(:pkg :aref);
use Bric::App::Callback::Publish;
use Bric::App::Callback::Util::Asset;
use Bric::Biz::Asset::Business::Media;
use Bric::Biz::Asset::Business::Story;
use Bric::Biz::Asset::Template;
Expand All @@ -38,9 +39,6 @@ sub checkin : Callback {
my $obj = $pkgs->{$class}->lookup({'id' => $id, checkout => 1});
my $desk = $obj->get_current_desk;

$desk->checkin($obj);
log_event("${class}_checkin", $obj, { Version => $obj->get_version });

# If the same asset is cached in the session, remove it.
if (my $cached = get_state_data("$class\_prof" => $class)) {
if ($cached->get_id == $obj->get_id) {
Expand All @@ -52,6 +50,29 @@ sub checkin : Callback {
my ($next_desk_id, $next_workflow_id) =
split /-/, $self->params->{"desk_asset|next_desk"};

if ($next_desk_id eq 'cancel') {
my $action;
print STDERR "####### ", $obj->get_checked_out, $/;
if ($obj->get_version == 0) {
# If the version number is 0, the asset was never checked in to a
# desk. So just delete it.
Bric::App::Callback::Util::Asset->remove($obj);
$action = 'deleted';
} else {
# Cancel the checkout.
Bric::App::Callback::Util::Asset->cancel_checkout($obj);
$action = 'check out canceled';
}
$self->add_message(
ucfirst $obj->key_name . qq{ "[_1]" $action.},
'<span class="l10n">' . $obj->get_title . '</span>',
);
return;
}

$desk->checkin($obj);
log_event("${class}_checkin", $obj, { Version => $obj->get_version });

if ($next_desk_id eq 'shelve') {
$desk->remove_asset($obj)->save;
$obj->set_workflow_id(undef);
Expand Down
50 changes: 3 additions & 47 deletions lib/Bric/App/Callback/Profile/Media.pm
Expand Up @@ -26,6 +26,7 @@ use Bric::Util::Priv::Parts::Const qw(:all);
use Bric::Util::MediaType;
use Bric::Util::Trans::FS;
use Bric::App::Callback::Search;
use Bric::App::Callback::Util::Asset;

my $SEARCH_URL = '/workflow/manager/media/';
my $ACTIVE_URL = '/workflow/active/media/';
Expand Down Expand Up @@ -403,44 +404,7 @@ sub cancel : Callback(priority => 6) {
return unless $handle_delete->($media, $self);
} else {
# Cancel the checkout.
$media->cancel_checkout;
log_event('media_cancel_checkout', $media);

# If the media was last recalled from the library, then remove it
# from the desk and workflow. We can tell this because there will
# only be one media_moved event and one media_checkout event
# since the last media_add_workflow event.
my @events = Bric::Util::Event->list({
class => 'Bric::Biz::Asset::Business::Media',
obj_id => $media->get_id
});
my ($desks, $cos) = (0, 0);
while (@events && $events[0]->get_key_name ne 'media_add_workflow') {
my $kn = shift(@events)->get_key_name;
if ($kn eq 'media_moved') {
$desks++;
} elsif ($kn eq 'media_checkout') {
$cos++
}
}

# If one move to desk, and one checkout, and this isn't the first
# time the media has been in workflow since it was created...
# XXX Two events upon creation: media_create and media_moved.
if ($desks == 1 && $cos == 1 && @events > 2) {
# It was just recalled from the library. So remove it from the
# desk and from workflow.
my $desk = $media->get_current_desk;
$desk->remove_asset($media);
$media->set_workflow_id(undef);
$desk->save;
$media->save;
log_event("media_rem_workflow", $media);
} else {
# Just save the cancelled checkout. It will be left in workflow for
# others to find.
$media->save;
}
Bric::App::Callback::Util::Asset->cancel_checkout($media);
$self->add_message('Media "[_1]" check out canceled.', $media->get_title);
}
$self->clear_my_state;
Expand Down Expand Up @@ -901,15 +865,7 @@ sub _handle_contributors {

$handle_delete = sub {
my ($media, $self) = @_;
my $desk = $media->get_current_desk;
$desk->checkin($media);
$desk->remove_asset($media);
$media->set_workflow_id(undef);
$media->deactivate;
$desk->save;
$media->save;
log_event("media_rem_workflow", $media);
log_event("media_deact", $media);
Bric::App::Callback::Util::Asset->remove($media);
$self->add_message('Media "[_1]" deleted.', $media->get_title);
};

Expand Down
51 changes: 3 additions & 48 deletions lib/Bric/App/Callback/Profile/Story.pm
Expand Up @@ -23,6 +23,7 @@ use Bric::Util::Fault qw(:all);
use Bric::Util::Grp::Parts::Member::Contrib;
use Bric::Util::Priv::Parts::Const qw(:all);
use Bric::App::Callback::Search;
use Bric::App::Callback::Util::Asset;

my $SEARCH_URL = '/workflow/manager/story/';
my $ACTIVE_URL = '/workflow/active/story/';
Expand Down Expand Up @@ -293,45 +294,7 @@ sub cancel : Callback(priority => 6) {
return unless $self->_handle_delete($story);
} else {
# Cancel the checkout.
$story->cancel_checkout;
log_event('story_cancel_checkout', $story);

# If the story was last recalled from the library, then remove it
# from the desk and workflow. We can tell this because there will
# only be one story_moved event and one story_checkout event
# since the last story_add_workflow event.
my @events = Bric::Util::Event->list({
class => ref $story,
obj_id => $story->get_id
});
my ($desks, $cos) = (0, 0);
while (@events && $events[0]->get_key_name ne 'story_add_workflow') {
my $kn = shift(@events)->get_key_name;
if ($kn eq 'story_moved') {
$desks++;
} elsif ($kn eq 'story_checkout') {
$cos++
}
}

# If one move to desk, and one checkout, and this isn't the first
# time the story has been in workflow since it was created...
# XXX Three events upon creation: story_create, story_add_category,
# and story_moved.
if ($desks == 1 && $cos == 1 && @events > 3) {
# It was just recalled from the library. So remove it from the
# desk and from workflow.
my $desk = $story->get_current_desk;
$desk->remove_asset($story);
$story->set_workflow_id(undef);
$desk->save;
$story->save;
log_event("story_rem_workflow", $story);
} else {
# Just save the cancelled checkout. It will be left in workflow for
# others to find.
$story->save;
}
Bric::App::Callback::Util::Asset->cancel_checkout($story);
$self->add_message(
'Story "[_1]" check out canceled.',
'<span class="l10n">' . $story->get_title . '</span>',
Expand Down Expand Up @@ -987,15 +950,7 @@ sub _handle_contributors {

sub _handle_delete {
my ($self, $story) = @_;
my $desk = $story->get_current_desk();
$desk->checkin($story) if $story->get_checked_out;
$desk->remove_asset($story);
$story->set_workflow_id(undef);
$story->deactivate;
$desk->save;
$story->save;
log_event("story_rem_workflow", $story);
log_event("story_deact", $story);
Bric::App::Callback::Util::Asset->remove($story);
$self->add_message(
'Story "[_1]" deleted.',
'<span class="l10n">' . $story->get_title . '</span>',
Expand Down
58 changes: 4 additions & 54 deletions lib/Bric/App/Callback/Profile/Template.pm
Expand Up @@ -9,6 +9,7 @@ use Bric::App::Authz qw(:all);
use Bric::App::Event qw(log_event);
use Bric::App::Session qw(:state :user);
use Bric::App::Util qw(:history);
use Bric::App::Callback::Util::Asset;
use Bric::Biz::Asset::Template;
use Bric::Biz::ElementType;
use Bric::Biz::Workflow;
Expand Down Expand Up @@ -176,47 +177,8 @@ sub cancel : Callback(priority => 6) {
# desk. So just delete it.
$delete_fa->($self, $fa);
} else {
# Cancel the checkout and undeploy the template from the user's
# sand box.
$fa->cancel_checkout;
log_event('template_cancel_checkout', $fa);
my $sb = Bric::Util::Burner->new({user_id => get_user_id()});
$sb->undeploy($fa);

# If the template was last recalled from the library, then remove it
# from the desk and workflow. We can tell this because there will
# only be one template_moved event and one template_checkout event
# since the last template_add_workflow event.
my @events = Bric::Util::Event->list({
class => ref $fa,
obj_id => $fa->get_id
});
my ($desks, $cos) = (0, 0);
while (@events && $events[0]->get_key_name ne 'template_add_workflow') {
my $kn = shift(@events)->get_key_name;
if ($kn eq 'template_moved') {
$desks++;
} elsif ($kn eq 'template_checkout') {
$cos++
}
}

# If one move to desk, and one checkout, and this isn't the first
# time the template has been in workflow since it was created...
if ($desks == 1 && $cos == 1 && @events > 2) {
# It was just recalled from the library. So remove it from the
# desk and from workflow.
my $desk = $fa->get_current_desk;
$desk->remove_asset($fa);
$fa->set_workflow_id(undef);
$desk->save;
$fa->save;
log_event("template_rem_workflow", $fa);
} else {
# Just save the cancelled checkout. It will be left in workflow for
# others to find.
$fa->save;
}
# Cancel the checkout.
Bric::App::Callback::Util::Asset->cancel_checkout($fa);
$self->add_message('Template "[_1]" check out canceled.', $fa->get_file_name);
}
clear_state($self->class_key);
Expand Down Expand Up @@ -630,19 +592,7 @@ $check_syntax = sub {

$delete_fa = sub {
my ($self, $fa) = @_;
my $desk = $fa->get_current_desk;
$desk->checkin($fa);
$desk->remove_asset($fa);
$desk->save;
log_event("template_rem_workflow", $fa);
my $burn = Bric::Util::Burner->new;
$burn->undeploy($fa);
my $sb = Bric::Util::Burner->new({user_id => get_user_id() });
$sb->undeploy($fa);
$fa->set_workflow_id(undef);
$fa->deactivate;
$fa->save;
log_event("template_deact", $fa);
Bric::App::Callback::Util::Asset->remove($fa);
$self->add_message('Template "[_1]" deleted.', $fa->get_file_name);
};

Expand Down

0 comments on commit d13ea3e

Please sign in to comment.