View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
17479Bug reportsPluginspublic2021-07-29 09:15
Reporterdschirge Assigned Togalads  
PrioritynoneSeveritypartial_block 
Status acknowledgedResolutionopen 
Product Version3.25.20 
Summary17479: How to change template and survey format temporary from outside
Description

Hi guys,

for a project we need to change the format and/or template for a specific survey just for some users.
You have for example a survey with the template "vanilla" which is used for most of the participants.
Which would be the best way to change the template or the format for some participants via plugin?

We are doing it with modifying the session.

For example we change the template via

    $sessionKey = 'template_' . $surveyId;
    Yii::app()->user->setState($sessionKey, $this->templateName);
    $this->event->set('template', $this->templateName);

It is working as expected but with a problem.
We are modifiying the selected template for a survey in the current admin session as well which leads to different problems. It occures when you are developing the survey in one tab and testing it in another tab.

Using different browsers or private tabs is no possible solution.

How can you solve this mixture of admin and user sessions?

TagsNo tags attached.
Bug heat8
Complete LimeSurvey version number (& build)Version 3.25.14+210218
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMySQL 5.x
Server OS (if known)
Webserver software & version (if known)
PHP Version5.6

Relationships

related to 17107 acknowledgedc_schmitz Survey seems without any question when testing (admin user) 

Users monitoring this issue

There are no users monitoring this issue.

Activities

DenisChenu

DenisChenu

2021-07-27 13:09

developer   ~65647

How can you solve this mixture of admin and user sessions?

Always launch with newtest=Y or Private browser.

It's a question : not an issue here …

dschirge

dschirge

2021-07-27 13:20

reporter   ~65648

The surveys are startet with newTest=Y, private browsing is unfortunately not possible.

Mazi

Mazi

2021-07-27 14:44

updater   ~65650

The problem is with the session handling, example:

  1. Call the general settings, Format = G there.
  2. Call public survey with format switch at URL: .../index.php/999901?newtest=Y&lang=en&format=A&template=etc_dataentry
  3. Then call the general settings again, Format = A is shown (which is wrong), though at the DB it is still G

If you log out and log in to the admin interface again, the format is shown as G again because of the new session.

So the problem - to me - seems to be the mix of admin and public survey session.

Any idea how to differentiate these settings???

ollehar

ollehar

2021-07-27 15:14

administrator   ~65651

Using different browsers or private tabs is no possible solution.

Why?

Mazi

Mazi

2021-07-27 21:34

updater   ~65657

RE "Why?" -> The customer's answer: "Because people at the company are stupid. We just need a working solution for which we do not have to train every new employee."

ollehar

ollehar

2021-07-27 21:57

administrator   ~65658

Last edited: 2021-07-27 21:57

OK, to repeat what I wrote in the chat, what you need is probably a patch that overrides the PHP session if a certain URL parameter is set.

Mazi

Mazi

2021-07-27 23:47

updater   ~65659

Well, I think a better session handling at Limesurvey would be the core thing. Why can public survey sessions and admin sessions get messed up at all? Can we somehow differentiate between a survey taking session and the admin session?

We are already adjusting the session if the URL parameter is set, see code snippet above:
$sessionKey = 'template_' . $surveyId;
Yii::app()->user->setState($sessionKey, $this->templateName);
$this->event->set('template', $this->templateName);

Thing is that this adjustment also affects the admin session, see step 3 above.

DenisChenu

DenisChenu

2021-07-28 08:30

developer   ~65662

https://gitlab.com/SondagesPro/coreAndTools/sessionNameBySurvey

This must be tested more and more.

Else : i really think we muts have different session name too. For each survey and for admin.

Something you can try :

  1. 2 tabs
  2. Preview group
  3. At same time reload other admin page
  4. You are loggued out …
dschirge

dschirge

2021-07-28 09:06

reporter   ~65664

I agree with DenisChenu.
The sessionNameBySurvey plugin looks very good to me. It will unfortunately not fix our problem because the survey developers works in the same survey.
But regardless of this topic it of course would fix problems if somebody works in multiple tabs with different surveys which should be a problem at the moment too.

DenisChenu

DenisChenu

2021-07-28 09:09

developer   ~65665

The sessionNameBySurvey plugin looks very good to me. It will unfortunately not fix our problem because the survey developers works in the same survey.

the plugin use own session name only for survey controller, never for admin controller : https://gitlab.com/SondagesPro/coreAndTools/sessionNameBySurvey/-/blob/master/sessionNameBySurvey.php#L33

But : to be incuded in LS core : best option seems to extend https://github.com/LimeSurvey/LimeSurvey/blob/master/framework/web/CHttpSession.php

Mazi

Mazi

2021-07-28 10:29

updater   ~65668

@DenisChenu, for which use case did you actually develop this plugin for? Did you test it with a new 3.27 version?

RE " i really think we muts have different session name too. For each survey and for admin." -> I totally agree!

DenisChenu

DenisChenu

2021-07-28 10:57

developer   ~65669

for which use case did you actually develop this plugin for? Did you test it with a new 3.27 version?

https://bugs.limesurvey.org/view.php?id=13761
and only quickly tested on 3.10

DenisChenu

DenisChenu

2021-07-28 14:56

developer   ~65678

Another more easy solution : 2 different link (alias)
Use publicurl to set the public link.

Different website => 2 different session.

Mazi

Mazi

2021-07-28 15:01

updater   ~65680

@DenisChenu, does that work with a load balanced system with db based sessions?

Can we have the same Limesurvey system to use e.g.
mydomin.com as publicurl
admin.mydomain.com as homeurl

DenisChenu

DenisChenu

2021-07-28 15:02

developer   ~65682

And plugin solution :

See : https://gitlab.com/SondagesPro/mailing/adminNotificationHtmlAnswerTable/-/blob/master/adminNotificationHtmlAnswerTable.php#L42

Must be adapted to the situation,

Finally beforeControllerAction must check if you are in admin or public and register the good afterFindSurvey according to this.
You can even use private variable to check if need to update Survey or not.

maybe best

  1. private $ispublic to false
  2. beforeControllerAction : check ispublic : false or true
  3. afterFindSurvey : if ispublic : update Survey accrding to param or SESSION. If not : didn't update.
DenisChenu

DenisChenu

2021-07-28 15:04

developer   ~65684

@DenisChenu, does that work with a load balanced system with db based sessions?

Session cookies are not the same , then i think yes.

DenisChenu

DenisChenu

2021-07-29 09:15

developer   ~65722

Do the trick

    /**
     * Register to afterFindSurvey only if needed
     */
    public function beforeControllerAction()
    {
        $controller = $this->getEvent()->get('controller');
        $neededControllers = array('survey');
        if (!in_array($controller, $neededControllers) ) {
            return;
        }
        $this->subscribe('afterFindSurvey');
    }

Issue History

Date Modified Username Field Change
2021-07-27 12:59 dschirge New Issue
2021-07-27 13:02 Mazi Description Updated
2021-07-27 13:09 DenisChenu Note Added: 65647
2021-07-27 13:20 dschirge Note Added: 65648
2021-07-27 14:44 Mazi Note Added: 65650
2021-07-27 15:14 ollehar Note Added: 65651
2021-07-27 21:34 Mazi Note Added: 65657
2021-07-27 21:57 ollehar Note Added: 65658
2021-07-27 21:57 ollehar Note Edited: 65658
2021-07-27 23:47 Mazi Note Added: 65659
2021-07-28 08:30 DenisChenu Note Added: 65662
2021-07-28 09:06 dschirge Note Added: 65664
2021-07-28 09:09 DenisChenu Note Added: 65665
2021-07-28 10:29 Mazi Note Added: 65668
2021-07-28 10:57 DenisChenu Note Added: 65669
2021-07-28 14:56 DenisChenu Note Added: 65678
2021-07-28 15:01 Mazi Note Added: 65680
2021-07-28 15:02 DenisChenu Note Added: 65682
2021-07-28 15:04 DenisChenu Note Added: 65684
2021-07-28 17:52 DenisChenu Relationship added related to 17107
2021-07-29 08:54 galads Assigned To => galads
2021-07-29 08:54 galads Status new => acknowledged
2021-07-29 09:15 DenisChenu Note Added: 65722