diff --git a/addons/hr_recruitment_survey/data/survey_demo.xml b/addons/hr_recruitment_survey/data/survey_demo.xml index 089b5df481b..2f98596d8db 100644 --- a/addons/hr_recruitment_survey/data/survey_demo.xml +++ b/addons/hr_recruitment_survey/data/survey_demo.xml @@ -3,7 +3,7 @@ Recruitment Form - + token

diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 9a6b8b57337..bf569e733e4 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -59,8 +59,11 @@ class Survey(http.Controller): if not answer_sudo and ensure_token: return 'token_required' + if not answer_sudo and survey_sudo.access_mode == 'token': + return 'token_required' - if survey_sudo.auth_required and request.env.user._is_public(): + # Public -> no auth required; Token -> token check hereabove + if survey_sudo.access_mode not in ['public', 'token'] and request.env.user._is_public(): return 'survey_auth' if survey_sudo.is_closed or not survey_sudo.active: @@ -99,7 +102,7 @@ class Survey(http.Controller): has_survey_access = True can_answer = bool(answer_sudo) if not can_answer: - can_answer = survey_sudo.auth_required is False + can_answer = survey_sudo.access_mode == 'public' return { 'survey_sudo': survey_sudo, diff --git a/addons/survey/data/survey_demo_feedback.xml b/addons/survey/data/survey_demo_feedback.xml index 24aa3890ac4..8d24117ab47 100644 --- a/addons/survey/data/survey_demo_feedback.xml +++ b/addons/survey/data/survey_demo_feedback.xml @@ -4,7 +4,7 @@ User Feedback Form - + public

This survey allows you to give a feedback about your experience with our eCommerce solution. @@ -229,4 +229,4 @@ skip - + \ No newline at end of file diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index 38da4f40277..0f0f788f029 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -35,14 +35,26 @@ class Survey(models.Model): page_ids = fields.One2many('survey.page', 'survey_id', string='Pages', copy=True) user_input_ids = fields.One2many('survey.user_input', 'survey_id', string='User responses', readonly=True, groups='survey.group_survey_user') # security / access - auth_required = fields.Boolean('Login required', help="Users with a public link will be requested to login before taking part to the survey") + access_mode = fields.Selection([ + ('public', 'Everyone'), + ('authentication', 'Login Required'), + ('internal', 'Employees Only'), + ('token', 'Invitation only')], string='Access Mode', + default='authentication', required=True) users_can_go_back = fields.Boolean('Users can go back', help="If checked, users can go back to previous pages.") + users_can_signup = fields.Boolean('Users can signup', compute='_compute_users_can_signup') public_url = fields.Char("Public link", compute="_compute_survey_url") # statistics tot_sent_survey = fields.Integer("Number of sent surveys", compute="_compute_survey_statistic") tot_start_survey = fields.Integer("Number of started surveys", compute="_compute_survey_statistic") tot_comp_survey = fields.Integer("Number of completed surveys", compute="_compute_survey_statistic") + @api.multi + def _compute_users_can_signup(self): + signup_allowed = self.env['res.users'].sudo()._get_signup_invitation_scope() == 'b2c' + for survey in self: + survey.users_can_signup = signup_allowed + @api.multi def _compute_survey_statistic(self): UserInput = self.env['survey.user_input'] @@ -125,8 +137,15 @@ class Survey(models.Model): raise UserError(_('Creating token for archived surveys is not allowed.')) elif self.is_closed: raise UserError(_('Creating token for closed surveys is not allowed.')) - if self.auth_required and (not user or user._is_public()): - raise UserError(_('Creating token for external users is not allowed for surveys requesting authentication.')) + if self.access_mode == 'authentication': + # signup possible -> should have at least a partner to create an account + if self.users_can_signup and not user and not partner: + raise UserError(_('Creating token for external people is not allowed for surveys requesting authentication.')) + # no signup possible -> should be a not public user (employee or portal users) + if not self.users_can_signup and (not user or user._is_public()): + raise UserError(_('Creating token for external people is not allowed for surveys requesting authentication.')) + if self.access_mode == 'internal' and (not user or not user.has_group('base.group_user')): + raise UserError(_('Creating token for anybody else than employees is not allowed for internal surveys.')) @api.model def next_page(self, user_input, page_id, go_back=False): diff --git a/addons/survey/tests/common.py b/addons/survey/tests/common.py index fbe03f3f24b..4235739ba14 100644 --- a/addons/survey/tests/common.py +++ b/addons/survey/tests/common.py @@ -64,7 +64,7 @@ class SurveyCase(common.SavepointCase): self.survey = self.env['survey.survey'].sudo(self.survey_manager).create({ 'title': 'Test Survey', - 'auth_required': True, + 'access_mode': 'authentication', 'users_can_go_back': False, }) self.page_0 = self.env['survey.page'].sudo(self.survey_manager).create({ diff --git a/addons/survey/tests/test_survey_flow.py b/addons/survey/tests/test_survey_flow.py index 537ab1d46d4..11d9ed2a57c 100644 --- a/addons/survey/tests/test_survey_flow.py +++ b/addons/survey/tests/test_survey_flow.py @@ -47,7 +47,7 @@ class TestSurveyFlow(common.SurveyCase, HttpCase): with self.sudo(self.survey_manager): survey = self.env['survey.survey'].create({ 'title': 'Public Survey for Tarte Al Djotte', - 'auth_required': False, + 'access_mode': 'public', }) # First page is about customer data diff --git a/addons/survey/views/survey_survey_views.xml b/addons/survey/views/survey_survey_views.xml index 7c0d391b4af..c6292b549a9 100644 --- a/addons/survey/views/survey_survey_views.xml +++ b/addons/survey/views/survey_survey_views.xml @@ -9,12 +9,11 @@ -

-
@@ -25,7 +24,7 @@ icon="fa-pencil-square-o"> - @@ -33,24 +32,20 @@
@@ -85,7 +80,7 @@ - + @@ -108,7 +103,7 @@
    -
  • +
  • Test
  • @@ -165,12 +160,10 @@

    You can create surveys for different purposes: customer opinion, services feedback, recruitment interviews, employee's periodical evaluations, marketing campaigns, etc.

    - Design easily your survey, send invitations to answer by email and analyse answers. + Design easily your survey, send invitations to answer by email and analyze answers.

    - - diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 8e8ccf61385..530bcdeffc3 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -55,7 +55,7 @@

    Login required

    This survey is open only to registered people. Please - log in. + log in.

diff --git a/addons/survey/views/survey_user_views.xml b/addons/survey/views/survey_user_views.xml index 919daed1deb..5344823ed42 100644 --- a/addons/survey/views/survey_user_views.xml +++ b/addons/survey/views/survey_user_views.xml @@ -30,7 +30,7 @@