This commit introduces models related to sharing dashboard, and implements the sharing from dashboard view. The basic idea is the same as sharing normal spreadsheet. The major difference is that sharing a dashboard will direct to the dashboard view instead of read-only spreadsheet view. A button and a side panel which shows the global filters show up only in the dashboard view. task 3378150 closes odoo/odoo#127370 Related: odoo/enterprise#43664 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com> Co-authored-by: Lucas Lefèvre <lul@odoo.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
import base64
|
|
import uuid
|
|
from werkzeug.exceptions import Forbidden
|
|
|
|
from odoo import models, fields, api, _
|
|
from odoo.tools import consteq
|
|
|
|
class SpreadsheetDashboardShare(models.Model):
|
|
_name = 'spreadsheet.dashboard.share'
|
|
_inherit = 'spreadsheet.mixin'
|
|
_description = 'Copy of a shared dashboard'
|
|
|
|
dashboard_id = fields.Many2one('spreadsheet.dashboard', required=True, ondelete='cascade')
|
|
excel_export = fields.Binary()
|
|
access_token = fields.Char(required=True, default=lambda _x: str(uuid.uuid4()))
|
|
full_url = fields.Char(string="URL", compute='_compute_full_url')
|
|
name = fields.Char(related='dashboard_id.name')
|
|
|
|
@api.depends('access_token')
|
|
def _compute_full_url(self):
|
|
for share in self:
|
|
share.full_url = "%s/dashboard/share/%s/%s" % (share.get_base_url(), share.id, share.access_token)
|
|
|
|
@api.model
|
|
def action_get_share_url(self, vals):
|
|
if "excel_files" in vals:
|
|
excel_zip = self._zip_xslx_files(
|
|
vals["excel_files"]
|
|
)
|
|
del vals["excel_files"]
|
|
vals["excel_export"] = base64.b64encode(excel_zip)
|
|
return self.create(vals).full_url
|
|
|
|
def _check_token(self, access_token):
|
|
if not access_token:
|
|
return False
|
|
return consteq(access_token, self.access_token)
|
|
|
|
def _check_dashboard_access(self, access_token):
|
|
self.ensure_one()
|
|
token_access = self._check_token(access_token)
|
|
dashboard = self.dashboard_id.with_user(self.create_uid)
|
|
user_access = dashboard.check_access_rights("read", raise_exception=False) and dashboard._filter_access_rules("read")
|
|
if not (token_access and user_access):
|
|
raise Forbidden(_("You don't have access to this dashboard. "))
|