summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2013-03-28 13:59:48 +0100
committerChristophe Matthieu <chm@openerp.com>2013-03-28 13:59:48 +0100
commit96bb094faae863f6275a0d72e9ccd76df3684a4e (patch)
tree91c1ba9f9af17f942423c673a61495fce95556fa
parenta10da6f0ed5137dab7acd6da6921afa8a8d71ce8 (diff)
[FIX] survey token
bzr revid: chm@openerp.com-20130328125948-q8b243m5g3l7w06b
-rw-r--r--addons/survey/survey.py7
-rw-r--r--addons/survey/survey_demo.xml2
-rw-r--r--addons/survey/wizard/survey_answer.py12
-rw-r--r--addons/survey/wizard/survey_email_compose_message.py36
-rw-r--r--addons/survey/wizard/survey_email_compose_message.xml4
5 files changed, 35 insertions, 26 deletions
diff --git a/addons/survey/survey.py b/addons/survey/survey.py
index 646e03d4990..158e160a17f 100644
--- a/addons/survey/survey.py
+++ b/addons/survey/survey.py
@@ -44,7 +44,12 @@ class survey(osv.osv):
_inherit = ['mail.thread', 'ir.needaction_mixin']
def _needaction_domain_get(self, cr, uid, context=None):
- return ['&', ('response_ids.state', 'in', ['new', 'skip']), ('response_ids.partner_id.user_id', '=', uid)]
+ user_browse = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
+ model, group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_survey_manager')
+ if group_id in [x.id for x in user_browse.groups_id]:
+ return ['&', ('response_ids.state', 'in', ['new', 'skip']), ('response_ids.partner_id.user_id', '=', uid)]
+ else:
+ return []
def default_get(self, cr, uid, fields, context=None):
data = super(survey, self).default_get(cr, uid, fields, context)
diff --git a/addons/survey/survey_demo.xml b/addons/survey/survey_demo.xml
index 8a93a47143b..fae9aa487ad 100644
--- a/addons/survey/survey_demo.xml
+++ b/addons/survey/survey_demo.xml
@@ -155,7 +155,7 @@
<!-- Partner Feedback Demo data -->
<record model="survey" id="survey_partner_feedback">
- <field name="title">OpenERP Partner Feedback</field>
+ <field name="title">Partner Feedback</field>
<field name="max_response_limit">20</field>
<field name="type" ref="survey_type1"/>
<field name="state">open</field>
diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py
index 197686e9522..3b6dfa35830 100644
--- a/addons/survey/wizard/survey_answer.py
+++ b/addons/survey/wizard/survey_answer.py
@@ -250,7 +250,7 @@ class survey_question_wiz(osv.osv_memory):
sur_response_obj = self.pool.get('survey.response')
dom = [('survey_id', '=', survey_id),
"|", ('state', '=', 'test'),
- "&", ('state', 'in', ['new', 'skip']), "|", ('date_deadline', '=', None), ('date_deadline', '>', datetime.now())]
+ "&", ('state', 'in', ['new', 'skip', 'done']), "|", ('date_deadline', '=', None), ('date_deadline', '>', datetime.now())]
# check for private token
if survey_token:
@@ -265,18 +265,20 @@ class survey_question_wiz(osv.osv_memory):
response_ids = None
# check sign in user
if not response_ids and not anonymous:
- response_ids = sur_response_obj.search(cr, SUPERUSER_ID, dom + [('partner_id', '=', pid)], context=context, limit=1, order="date_deadline DESC")
+ response_ids = sur_response_obj.search(cr, SUPERUSER_ID, dom + [('state', '!=', 'done'), ('partner_id', '=', pid)], context=context, limit=1, order="date_deadline DESC")
# user have a specific token or a specific partner access (for state open or restricted)
if response_ids:
response = sur_response_obj.browse(cr, SUPERUSER_ID, response_ids[0], context=context)
res['response_id'] = response_ids[0]
res['state'] = response.state
+ if response.state == 'done':
+ res['readonly'] = True
# errors
if not res['response_id'] and not context.get('edit') and not context.get('survey_test') and (survey_browse.state != 'open' or str(survey_browse.token) != str(survey_token)):
- response_ids = sur_response_obj.search(cr, SUPERUSER_ID, [('survey_id', '=', survey_id), ("token", "=", context.get("survey_token", None))], context=context, limit=1)
+ response_ids = sur_response_obj.search(cr, SUPERUSER_ID, [('survey_id', '=', survey_id), ("token", "=", survey_token)], context=context, limit=1)
if not response_ids:
response_ids = sur_response_obj.search(cr, SUPERUSER_ID, [('survey_id', '=', survey_id), ('partner_id', '=', pid)], context=context, limit=1)
@@ -490,7 +492,7 @@ class survey_question_wiz(osv.osv_memory):
})
response_ans = False
- if not context.get('edit') and response_info.get('response_id'):
+ if not context.get('edit') and response_info['response_id']:
response_ans = sur_response_obj.browse(cr, SUPERUSER_ID, response_info['response_id'], context=context)
if response_ans:
@@ -540,7 +542,7 @@ class survey_question_wiz(osv.osv_memory):
return value
if context.get('edit', False):
return value
-
+ print value
return value
def create(self, cr, uid, vals, context=None):
diff --git a/addons/survey/wizard/survey_email_compose_message.py b/addons/survey/wizard/survey_email_compose_message.py
index e61ef0b3c40..0459e6bdfb7 100644
--- a/addons/survey/wizard/survey_email_compose_message.py
+++ b/addons/survey/wizard/survey_email_compose_message.py
@@ -53,7 +53,7 @@ class survey_mail_compose_message(osv.TransientModel):
_columns = {
'public': fields.selection([('public_link', 'Share the public web link to your audience.'), \
('email_public_link', 'Send by email the public web link to your audience.'),\
- ('email', 'Send private invitation to your audience (only one response per recipient and per invitation).')],
+ ('email_private', 'Send private invitation to your audience (only one response per recipient and per invitation).')],
string='Share options', required=True),
'public_url': fields.function(_get_public_url, string="Public url", type="char"),
'public_url_html': fields.function(_get_public_url_html, string="Public HTML web link", type="char"),
@@ -67,7 +67,7 @@ class survey_mail_compose_message(osv.TransientModel):
'date_deadline': fields.date(string="Deadline to which the invitation to respond is valid", help="Deadline to which the invitation to respond for this survey is valid. If the field is empty, the invitation is still valid."),
}
_defaults = {
- 'public': 'email',
+ 'public': 'email_private',
}
def onchange_multi_email(self, cr, uid, ids, multi_email, context=None):
@@ -106,21 +106,8 @@ class survey_mail_compose_message(osv.TransientModel):
def create_response_and_send_mail(wizard, token, partner_id, email):
""" Create one mail by recipients and replace __URL__ by link with identification token
"""
- # create response with token
- survey_response_obj.create(cr, uid, {
- 'date_deadline': wizard.date_deadline,
- 'survey_id': wizard.res_id,
- 'date_create': datetime.now(),
- 'response_type': 'link',
- 'state': 'new',
- 'token': token,
- 'partner_id': partner_id,
- 'email': email,
- })
-
#set url
- url = wizard.public == 'email' and re.sub(r'params=[^&]+', 'params=%s' % token, wizard.public_url) or wizard.public_url
-
+ url = token and re.sub(r'params=[^&]+', 'params=%s' % token, wizard.public_url) or wizard.public_url
# post the message
values = {
'model': None,
@@ -144,7 +131,22 @@ class survey_mail_compose_message(osv.TransientModel):
response_ids = survey_response_obj.search(cr, uid, [('survey_id', '=', wizard.res_id), ('state', 'in', ['new', 'skip']), '|', ('partner_id', '=', partner_id), ('email', '=', email)], context=context)
if response_ids:
return survey_response_obj.read(cr, uid, response_ids, ['token'], context=context)[0]['token']
- return not wizard.public and uuid.uuid4() or False
+ if wizard.public != 'email_private':
+ return None
+ else:
+ token = uuid.uuid4()
+ # create response with token
+ survey_response_obj.create(cr, uid, {
+ 'date_deadline': wizard.date_deadline,
+ 'survey_id': wizard.res_id,
+ 'date_create': datetime.now(),
+ 'response_type': 'link',
+ 'state': 'new',
+ 'token': token,
+ 'partner_id': partner_id,
+ 'email': email,
+ })
+ return token
for wizard in self.browse(cr, uid, ids, context=context):
if wizard.model == 'survey':
diff --git a/addons/survey/wizard/survey_email_compose_message.xml b/addons/survey/wizard/survey_email_compose_message.xml
index 45132801cd7..ff88b79157f 100644
--- a/addons/survey/wizard/survey_email_compose_message.xml
+++ b/addons/survey/wizard/survey_email_compose_message.xml
@@ -34,7 +34,7 @@
<group col="2" invisible="context.get('survey_resent_token')">
<field name="public" widget="radio"/>
</group>
- <group col="1" invisible="context.get('survey_resent_token')" attrs="{'invisible':[('public','in',['email', 'email_public_link'])]}" class="oe_survey_email_public">
+ <group col="1" invisible="context.get('survey_resent_token')" attrs="{'invisible':[('public','in',['email_private', 'email_public_link'])]}" class="oe_survey_email_public">
<div>
You can share your survey web public link and/or send private invitations to your audience.<br/>
People can response once per invitation, and whenever they want with the public web link.
@@ -66,7 +66,7 @@
</div>
</group>
</group>
- <footer attrs="{'invisible':[('public','in',['email', 'email_public_link'])]}">
+ <footer attrs="{'invisible':[('public','in',['email_private', 'email_public_link'])]}">
<button string="Close" class="oe_link" special="cancel" />
</footer>
<footer attrs="{'invisible':['|',('public','=',False),('public','in',['public_link'])]}">