[IMP] google_drive : better google drive configuration
Improve the configuration setting of google drive to make it more userfriendly Display a message when google drive is enabled but no token have been generated Task: 1894961 closes odoo/odoo#29562
This commit is contained in:
committed by
Martin Trigaux
parent
af199c4ced
commit
624fdc77d4
@@ -56,7 +56,7 @@ class GoogleDrive(models.Model):
|
||||
if not google_drive_refresh_token:
|
||||
if user_is_admin:
|
||||
dummy, action_id = self.env['ir.model.data'].get_object_reference('base_setup', 'action_general_configuration')
|
||||
msg = _("You haven't configured 'Authorization Code' generated from google, Please generate and configure it .")
|
||||
msg = _("There is no refresh code set for Google Drive. You can set it up from the configuration panel.")
|
||||
raise RedirectWarning(msg, action_id, _('Go to the configuration panel'))
|
||||
else:
|
||||
raise UserError(_("Google Drive is not yet configured. Please contact your administrator."))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
@@ -9,6 +9,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
|
||||
google_drive_authorization_code = fields.Char(string='Authorization Code', config_parameter='google_drive_authorization_code')
|
||||
google_drive_uri = fields.Char(compute='_compute_drive_uri', string='URI', help="The URL to generate the authorization code from Google")
|
||||
is_google_drive_token_generated = fields.Boolean(string='Refresh Token Generated')
|
||||
|
||||
@api.depends('google_drive_authorization_code')
|
||||
def _compute_drive_uri(self):
|
||||
@@ -16,12 +17,30 @@ class ResConfigSettings(models.TransientModel):
|
||||
for config in self:
|
||||
config.google_drive_uri = google_drive_uri
|
||||
|
||||
def set_values(self):
|
||||
def get_values(self):
|
||||
res = super(ResConfigSettings, self).get_values()
|
||||
refresh_token = self.env['ir.config_parameter'].sudo().get_param('google_drive_refresh_token', False)
|
||||
res.update(is_google_drive_token_generated=bool(refresh_token))
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def confirm_setup_token(self):
|
||||
params = self.env['ir.config_parameter'].sudo()
|
||||
authorization_code_before = params.get_param('google_drive_authorization_code')
|
||||
super(ResConfigSettings, self).set_values()
|
||||
authorization_code = self.google_drive_authorization_code
|
||||
refresh_token = False
|
||||
if authorization_code and authorization_code != authorization_code_before:
|
||||
refresh_token = self.env['google.service'].generate_refresh_token('drive', authorization_code)
|
||||
params.set_param('google_drive_refresh_token', refresh_token)
|
||||
|
||||
@api.multi
|
||||
def action_setup_token(self):
|
||||
self.ensure_one()
|
||||
template = self.env.ref('google_drive.google_drive_auth_code_wizard')
|
||||
return {
|
||||
'name': _('Set up refresh token'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'res.config.settings',
|
||||
'views': [(template.id, 'form')],
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@@ -7,22 +7,71 @@
|
||||
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<div id="msg_module_google_drive" position="replace">
|
||||
<div class="content-group" attrs="{'invisible': [('module_google_drive','=',False)]}">
|
||||
<div class="mt16 row">
|
||||
<label for="google_drive_authorization_code" class="col-lg-3 o_light_label"/>
|
||||
<field name="google_drive_authorization_code"/>
|
||||
<div class="content-group"
|
||||
attrs="{'invisible': [('module_google_drive','=',False)]}">
|
||||
<div class="mt-2 row">
|
||||
<div class="col-sm">
|
||||
<field name="is_google_drive_token_generated" invisible="1"/>
|
||||
<div role="alert"
|
||||
attrs="{'invisible': [('is_google_drive_token_generated', '=', False)]}">
|
||||
<i class="text-success fa fa-check"></i> &nbsp; Refresh token set
|
||||
</div>
|
||||
<div role="alert"
|
||||
attrs="{'invisible': [('is_google_drive_token_generated', '=', True)]}">
|
||||
<i class="fa fa-exclamation-triangle text-warning"></i> &nbsp; No refresh token set
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm text-center"
|
||||
attrs="{'invisible': [('is_google_drive_token_generated', '=', True)]}">
|
||||
<button class="btn btn-link pt-0"
|
||||
name="action_setup_token"
|
||||
type="object"><i class="fa fa-arrow-right"></i> Set up token</button>
|
||||
</div>
|
||||
<div class="col-sm text-center"
|
||||
attrs="{'invisible': [('is_google_drive_token_generated', '=', False)]}">
|
||||
<button class="btn btn-link pt-0"
|
||||
name="action_setup_token"
|
||||
type="object"><i class="fa fa-arrow-right"></i> Reset token</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<a role="button" class="btn-link o_btn-link-as-button fa-arrow-right">
|
||||
<field name="google_drive_uri" widget="url" text="Get Authorization Code"/>
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<button type="action" name="%(action_google_drive_users_config)d" string="Google Drive Templates" icon="fa-arrow-right" class="btn-link"/>
|
||||
<button type="action"
|
||||
name="%(action_google_drive_users_config)d"
|
||||
string="Google Drive Templates"
|
||||
icon="fa-arrow-right"
|
||||
class="btn-link"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="google_drive_auth_code_wizard" model="ir.ui.view">
|
||||
<field name="name">google.drive.authorization.wizard</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="mode">primary</field>
|
||||
<field name="priority">2048</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<span>Get an authorization code and set it in the field below.</span>
|
||||
<field name="google_drive_uri"
|
||||
class="fa fa-arrow-right mt-1"
|
||||
widget="url"
|
||||
text="Get Authorization Code"
|
||||
nolabel="1"/>
|
||||
</group>
|
||||
<group class="mt-3">
|
||||
<field name="google_drive_authorization_code" required="1"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Confirm"
|
||||
class="btn btn-primary"
|
||||
name="confirm_setup_token"
|
||||
type="object"/>
|
||||
<button special="cancel" string="Cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user