[IMP] survey: survey.action_filling is a server action for web link access
bzr revid: chm@openerp.com-20130227103121-3o3uige52e5fcmq5
This commit is contained in:
@@ -70,7 +70,6 @@ class survey(osv.osv):
|
||||
""" Compute if the message is unread by the current user. """
|
||||
res = dict((id, 0) for id in ids)
|
||||
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
|
||||
model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'survey', 'action_fill_survey')
|
||||
survey_obj = self.pool.get('survey')
|
||||
for survey_browse in survey_obj.browse(cr, uid, ids, context=context):
|
||||
query = {
|
||||
@@ -78,7 +77,7 @@ class survey(osv.osv):
|
||||
}
|
||||
fragment = {
|
||||
'active_id': survey_browse.id,
|
||||
'action': model_id[1],
|
||||
'action': 'survey.action_filling',
|
||||
'params': survey_browse.token,
|
||||
}
|
||||
res[survey_browse.id] = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment)))
|
||||
@@ -92,7 +91,7 @@ class survey(osv.osv):
|
||||
'max_response_limit': fields.integer('Maximum Answer Limit',
|
||||
help="Set to one if survey is answerable only once"),
|
||||
'state': fields.selection([('draft', 'Draft'), ('open', 'Open'), ('close', 'Close'), ('cancel', 'Cancelled')], 'Status', required=1),
|
||||
'sign_in': fields.boolean('User must be sign up'),
|
||||
'authenticate': fields.boolean('User must be authenticate'),
|
||||
'tot_start_survey': fields.function(_get_tot_start_survey, string="Total Started Survey", type="integer"),
|
||||
'tot_comp_survey': fields.function(_get_tot_comp_survey, string="Total Completed Survey", type="integer"),
|
||||
'note': fields.text('Description', size=128, translate=True),
|
||||
@@ -104,7 +103,7 @@ class survey(osv.osv):
|
||||
}
|
||||
_defaults = {
|
||||
'state': "draft",
|
||||
'sign_in': False,
|
||||
'authenticate': False,
|
||||
'date_open': fields.datetime.now,
|
||||
'token': lambda s, cr, uid, c: uuid.uuid4(),
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<group>
|
||||
<group colspan="4">
|
||||
<field name="type" attrs="{'readonly':[('state','in',['close','cancel'])]}" class="oe_inline"/>
|
||||
<field name="sign_in"/>
|
||||
<field name="authenticate"/>
|
||||
<field name="max_response_limit" attrs="{'readonly':[('state','=','close')]}"/>
|
||||
<field name="public_url" widget="url"/>
|
||||
</group>
|
||||
|
||||
@@ -188,7 +188,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
}
|
||||
self.pool.get('survey').message_post(cr, SUPERUSER_ID, survey_id, context=context, **val)
|
||||
|
||||
def get_response_info_from_token(self, cr, uid, survey_id, context):
|
||||
def get_response_info_from_token(self, cr, uid, survey_id, survey_token, context=None):
|
||||
"""
|
||||
Get the response informations and return a dictionnary
|
||||
* response_id
|
||||
@@ -199,7 +199,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
This function raise an exception
|
||||
|
||||
"""
|
||||
# get if the token of the partner or anonymous user is valid
|
||||
context = context or {}
|
||||
res = {'response_id': False, 'state': None, 'readonly': context.get('readonly', False)}
|
||||
|
||||
if not survey_id:
|
||||
@@ -223,7 +223,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
# check open and sign in
|
||||
if not context.get('edit') and survey_browse.state != "open":
|
||||
raise osv.except_osv(_('Access Denied!'), _("You cannot answer because the survey is not open."))
|
||||
if anonymous and survey_browse.sign_in:
|
||||
if anonymous and survey_browse.authenticate:
|
||||
raise osv.except_osv(_('Access Denied!'), _("Please Login to complete this survey."))
|
||||
|
||||
# get opening response
|
||||
@@ -232,8 +232,8 @@ class survey_question_wiz(osv.osv_memory):
|
||||
dom = [('survey_id', '=', survey_id), ('state', 'in', ['new', 'skip']), "|", ('date_deadline', '=', None), ('date_deadline', '>', datetime.now())]
|
||||
|
||||
# check for private token
|
||||
if context.get("survey_token"):
|
||||
response_ids = sur_response_obj.search(cr, SUPERUSER_ID, dom + [("token", "=", context.get("survey_token"))], context=context, limit=1, order="id DESC")
|
||||
if survey_token:
|
||||
response_ids = sur_response_obj.search(cr, SUPERUSER_ID, dom + [("token", "=", survey_token)], context=context, limit=1, order="id DESC")
|
||||
# check for admin preview responses
|
||||
if not response_ids and context.get("response_id"):
|
||||
try:
|
||||
@@ -253,7 +253,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
res['state'] = response.state
|
||||
|
||||
# errors
|
||||
if not res['response_id'] and not context.get('edit') and (survey_browse.state != 'open' or survey_browse.token != context.get("survey_token")):
|
||||
if not res['response_id'] and not context.get('edit') and (survey_browse.state != 'open' or survey_browse.token != 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)
|
||||
if not response_ids:
|
||||
@@ -340,7 +340,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
fields = {}
|
||||
|
||||
# get if the token of the partner or anonymous user is valid
|
||||
response_info = self.get_response_info_from_token(cr, uid, survey_id, context)
|
||||
response_info = self.get_response_info_from_token(cr, uid, survey_id, context.get("survey_token"), context)
|
||||
|
||||
# have acces to this survey
|
||||
edit_mode = context.get('edit', False)
|
||||
@@ -457,7 +457,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
tot_per = (float(100) * (int(field.split('_')[2]) + 1) / len(tot_page_id.page_ids))
|
||||
value[field] = tot_per
|
||||
|
||||
response_info = self.get_response_info_from_token(cr, uid, context.get('survey_id'), context)
|
||||
response_info = self.get_response_info_from_token(cr, uid, context.get('survey_id'), context.get("survey_token"), context)
|
||||
|
||||
response_ans = False
|
||||
sur_response_obj = self.pool.get('survey.response')
|
||||
@@ -529,7 +529,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
|
||||
sur_response_obj = self.pool.get('survey.response')
|
||||
|
||||
response_info = self.get_response_info_from_token(cr, uid, context['survey_id'], context)
|
||||
response_info = self.get_response_info_from_token(cr, uid, context['survey_id'], context.get("survey_token"), context)
|
||||
|
||||
survey_question_wiz_id = super(survey_question_wiz, self).create(cr, uid, {'name': vals.get('name')}, context=context)
|
||||
if context.get('edit', False) or response_info['readonly']:
|
||||
@@ -1154,7 +1154,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
def action_done(self, cr, uid, ids, context=None):
|
||||
""" Goes to previous page.
|
||||
"""
|
||||
response_info = self.get_response_info_from_token(cr, uid, context['survey_id'], context)
|
||||
response_info = self.get_response_info_from_token(cr, uid, context['survey_id'], context.get("survey_token"), context)
|
||||
if response_info['response_id']:
|
||||
response_id = response_info['response_id']
|
||||
else:
|
||||
@@ -1177,6 +1177,36 @@ class survey_question_wiz(osv.osv_memory):
|
||||
'view_id': view_id,
|
||||
}
|
||||
|
||||
def _action_filling(self, cr, uid, ids, context=None):
|
||||
""" Check if the user have access to the survey and open survey
|
||||
"""
|
||||
context.update({
|
||||
'survey_id': context['active_id'],
|
||||
'survey_token': context['params'],
|
||||
'ir_actions_act_window_target': 'inline'})
|
||||
|
||||
# check if the user must be authenticate
|
||||
survey_browse = self.pool.get('survey').browse(cr, SUPERUSER_ID, context['survey_id'], context=context)
|
||||
user_browse = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
|
||||
model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_anonymous')
|
||||
anonymous = model_id and model_id[1] in [x.id for x in user_browse.groups_id]
|
||||
if anonymous and survey_browse.state == "open" and survey_browse.authenticate:
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'login',
|
||||
'context': context,
|
||||
}
|
||||
|
||||
response_info = self.get_response_info_from_token(cr, uid, context['survey_id'], context['survey_token'], context)
|
||||
return {
|
||||
'view_type': 'form',
|
||||
"view_mode": 'form',
|
||||
'res_model': 'survey.question.wiz',
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'inline',
|
||||
'context': context,
|
||||
}
|
||||
|
||||
survey_question_wiz()
|
||||
|
||||
# vim: expandtab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4:
|
||||
|
||||
@@ -33,13 +33,13 @@
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="action_fill_survey" model="ir.actions.act_window">
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">survey.question.wiz</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">inline</field>
|
||||
<field name="context">{'survey_id': active_id, 'survey_token': params, 'ir_actions_act_window_target': 'inline'}</field>
|
||||
<record id="action_filling" model="ir.actions.server">
|
||||
<field name="name">Filling Survey</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="model_survey_question_wiz"/>
|
||||
<field name="code">action = self._action_filling(cr, uid, None, context)</field>
|
||||
<field name="condition">True</field>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
|
||||
Reference in New Issue
Block a user