shortcut now takes ?visitor=1 to edit visitor prefs from dashboard
This commit is contained in:
parent
848570712e
commit
475a885146
2 changed files with 21 additions and 9 deletions
|
|
@ -216,7 +216,6 @@ sub canManage {
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 discernUserId
|
=head2 discernUserId
|
||||||
|
|
||||||
This utility method is used to determine if the user should be shown the view of the
|
This utility method is used to determine if the user should be shown the view of the
|
||||||
|
|
@ -225,8 +224,8 @@ Shortcut that the Visitor would see, or their own.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub discernUserId {
|
sub discernUserId {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return ($self->canManage && $self->session->isAdminOn) ? '1' : $self->session->user->userId;
|
return ($self->canManage && $self->session->form->get('visitor')) ? '1' : $self->session->user->userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -481,7 +480,7 @@ admin mode is on.
|
||||||
sub _overridesCacheTag {
|
sub _overridesCacheTag {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
#cache by userId, assetId of this shortcut, and whether adminMode is on or not.
|
#cache by userId, assetId of this shortcut, and whether adminMode is on or not.
|
||||||
return join "", "shortcutOverrides", $self->getId, $self->session->user->userId, $self->session->isAdminOn;
|
return join "", "shortcutOverrides", $self->getId, $self->session->user->userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -995,13 +994,18 @@ sub www_getUserPrefsForm {
|
||||||
action => $self->getUrl,
|
action => $self->getUrl,
|
||||||
extras => 'onsubmit="submitForm(this,\''.$self->getId.'\',\''.$self->getUrl.'\');return false;"',
|
extras => 'onsubmit="submitForm(this,\''.$self->getId.'\',\''.$self->getUrl.'\');return false;"',
|
||||||
);
|
);
|
||||||
my $allowedToSave = ( ! $session->isAdminOn && $self->getParent->canPersonalize )
|
# Admins are allowed to edit visitor's preferences
|
||||||
|| ( $session->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
|
my $editingVisitor = $session->form->get('visitor') eq 1;
|
||||||
|
my $allowedToSave = ( ! $editingVisitor && $self->getParent->canPersonalize )
|
||||||
|
|| ( $editingVisitor && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
|
||||||
if ($allowedToSave) {
|
if ($allowedToSave) {
|
||||||
$f->addField( "hidden",
|
$f->addField( "hidden",
|
||||||
name => 'func',
|
name => 'func',
|
||||||
value => 'saveUserPrefs'
|
value => 'saveUserPrefs'
|
||||||
);
|
);
|
||||||
|
if ( $editingVisitor ) {
|
||||||
|
$f->addField( "hidden", name => 'visitor', value => 1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
my $u = WebGUI::User->new($session, $self->discernUserId);
|
my $u = WebGUI::User->new($session, $self->discernUserId);
|
||||||
FIELD: foreach my $fieldId (@fielden) {
|
FIELD: foreach my $fieldId (@fielden) {
|
||||||
|
|
@ -1093,13 +1097,14 @@ the form would allow someone who is not a User Admin to alter Visitor's profile.
|
||||||
sub www_saveUserPrefs {
|
sub www_saveUserPrefs {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
|
my $editingVisitor = $session->form->get('visitor') eq 1;
|
||||||
return '' unless $self->getParent->canPersonalize
|
return '' unless $self->getParent->canPersonalize
|
||||||
|| ( $session->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
|
|| ( $editingVisitor && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
|
||||||
my @fellowFields = $self->getPrefFieldsToShow;
|
my @fellowFields = $self->getPrefFieldsToShow;
|
||||||
my %data = ();
|
my %data = ();
|
||||||
$self->uncacheOverrides;
|
$self->uncacheOverrides;
|
||||||
my $i18n = WebGUI::International->new($session);
|
my $i18n = WebGUI::International->new($session);
|
||||||
my $u = WebGUI::User->new($session, $self->discernUserId);
|
my $u = $editingVisitor ? WebGUI::User->new( $session, '1' ) : $session->user;
|
||||||
foreach my $fieldId ($session->form->param) {
|
foreach my $fieldId ($session->form->param) {
|
||||||
my $field = WebGUI::ProfileField->new($session,$fieldId);
|
my $field = WebGUI::ProfileField->new($session,$fieldId);
|
||||||
next unless $field;
|
next unless $field;
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,14 @@ $mech->submit_form_ok( {
|
||||||
} );
|
} );
|
||||||
is( $mech->session->user->get('alias'), "myself", "alias gets set" );
|
is( $mech->session->user->get('alias'), "myself", "alias gets set" );
|
||||||
|
|
||||||
|
# Admin is allowed to edit visitor's prefs
|
||||||
|
$mech->get_ok( $shortcut->getUrl( 'func=getUserPrefsForm;visitor=1' ) );
|
||||||
|
$mech->submit_form_ok( {
|
||||||
|
fields => { alias => "visitor" },
|
||||||
|
} );
|
||||||
|
isnt( $mech->session->user->get('alias'), "visitor", "admin alias doesn't get set" );
|
||||||
|
is( WebGUI::User->new( $mech->session, '1' )->get('alias'), 'visitor', 'visitors alias set' );
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# editOverrides
|
# editOverrides
|
||||||
|
|
||||||
|
|
@ -62,7 +70,6 @@ $mech->session->user({ userId => 3 });
|
||||||
|
|
||||||
# Make sure edit form has a link to edit the override
|
# Make sure edit form has a link to edit the override
|
||||||
$mech->get_ok( $shortcut->getUrl( 'func=edit' ) );
|
$mech->get_ok( $shortcut->getUrl( 'func=edit' ) );
|
||||||
diag( $mech->content );
|
|
||||||
$mech->follow_link_ok(
|
$mech->follow_link_ok(
|
||||||
{ url_regex => qr/func=editOverride;fieldName=title/ },
|
{ url_regex => qr/func=editOverride;fieldName=title/ },
|
||||||
"Follow the link to edit the override",
|
"Follow the link to edit the override",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue