Browse Source

[FIX] emc_w_taxshelter: Access right issue

Fix access right to the subscription and the share certificate.
pull/1/head
Rémy Taymans 7 years ago
parent
commit
9aca525e1a
  1. 76
      easy_my_coop_website_taxshelter/controllers/main.py
  2. 4
      easy_my_coop_website_taxshelter/security/ir.model.access.csv
  3. 43
      easy_my_coop_website_taxshelter/security/tax_shelter_portal_security.xml
  4. 22
      easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml

76
easy_my_coop_website_taxshelter/controllers/main.py

@ -6,10 +6,11 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models, http
from werkzeug.exceptions import Forbidden, NotFound
from openerp import http
from openerp.exceptions import AccessError, MissingError
from openerp.http import request
from openerp import tools
from openerp.tools.translate import _
from openerp.addons.website_portal_v10.controllers.main import WebsiteAccount
@ -78,3 +79,72 @@ class CooperatorWebsiteAccount(WebsiteAccount):
"easy_my_coop_website_taxshelter.portal_my_tax_shelter",
values
)
@http.route(['/my/subscription_certificate/pdf/<int:oid>'],
type='http', auth="user", website=True)
def get_subscription_certificate_pdf(self, oid=-1):
"""Render the Subscription Certificate pdf of the given
Tax Shelter Report
"""
# Get the subscription certificate and raise an error if the user
# is not allowed to access to it or if the object is not found.
partner = request.env.user.partner_id
tax_shelter_mgr = request.env['tax.shelter.certificate'].sudo()
tax_shelter = tax_shelter_mgr.browse(oid)
try:
if tax_shelter.partner_id != partner:
raise Forbidden()
except AccessError:
raise Forbidden()
except MissingError:
raise NotFound()
# Get the pdf
report_mgr = request.env['report'].sudo()
pdf = report_mgr.get_pdf(
tax_shelter.ids,
'easy_my_coop_taxshelter_report.tax_shelter_subscription_report'
)
filename = "Subscription Certificate - {name} - {year}".format(
name=partner.name,
year=tax_shelter.declaration_id.fiscal_year
)
return self._render_pdf(pdf, filename)
@http.route(['/my/share_certificate/pdf/<int:oid>'],
type='http', auth="user", website=True)
def get_share_certificate_pdf(self, oid=-1):
"""Render the Share Certificate pdf of the given Tax Shelter
Report
"""
# Get the share certificate and raise an error if the user
# is not allowed to access to it or if the object is not found.
partner = request.env.user.partner_id
tax_shelter_mgr = request.env['tax.shelter.certificate'].sudo()
tax_shelter = tax_shelter_mgr.browse(oid)
try:
if tax_shelter.partner_id != partner:
raise Forbidden()
except AccessError:
raise Forbidden()
except MissingError:
raise NotFound()
# Get the pdf
report_mgr = request.env['report'].sudo()
pdf = report_mgr.get_pdf(
tax_shelter.ids,
'easy_my_coop_taxshelter_report.tax_shelter_shares_report'
)
filename = "Share Certificate - {name} - {year}".format(
name=partner.name,
year=tax_shelter.declaration_id.fiscal_year
)
return self._render_pdf(pdf, filename)
def _render_pdf(self, pdf, filename):
"""Render a http response for a pdf"""
pdfhttpheaders = [
('Content-Disposition', 'inline; filename="%s.pdf"' % filename),
('Content-Type', 'application/pdf'),
('Content-Length', len(pdf))
]
return request.make_response(pdf, headers=pdfhttpheaders)

4
easy_my_coop_website_taxshelter/security/ir.model.access.csv

@ -1,4 +0,0 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_tax_shelter_declaration,tax.shelter.declaration.portal,easy_my_coop_taxshelter_report.model_tax_shelter_declaration,base.group_portal,1,0,0,0
access_tax_shelter_certificate,tax.shelter.certificate.portal,easy_my_coop_taxshelter_report.model_tax_shelter_certificate,base.group_portal,1,0,0,0
access_tax_shelter_certificate_lines,certificate.line.portal,easy_my_coop_taxshelter_report.model_certificate_line,base.group_portal,1,0,0,0

43
easy_my_coop_website_taxshelter/security/tax_shelter_portal_security.xml

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2015-2016 Odoo S.A.
Copyright 2018 Rémy Taymans <remytaymans@gmail.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<data noupdate="0">
<!-- Tax Shelter Access Rules -->
<record id="emc_portal_tax_shelter_certificate_rule" model="ir.rule">
<field name="name">
Easy My Coop Portal Tax Shelter Certificate
</field>
<field name="model_id"
ref="easy_my_coop_taxshelter_report.model_tax_shelter_certificate"/>
<field name="domain_force">
[('partner_id', 'in', [user.commercial_partner_id.id])]
</field>
<field name="groups" eval="[(6, 0, [ref('base.group_portal')])]"/>
</record>
<record id="emc_portal_tax_shelter_certificate_line_rule" model="ir.rule">
<field name="name">
Easy My Coop Portal Tax Shelter Certificate line
</field>
<field name="model_id"
ref="easy_my_coop_taxshelter_report.model_certificate_line"/>
<field name="domain_force">
[('tax_shelter_certificate.partner_id','in', [user.commercial_partner_id.id])]
</field>
<field name="groups" eval="[(6, 0, [ref('base.group_portal')])]"/>
</record>
<record id="emc_portal_personal_contact" model="ir.rule">
<field name="name">Easy My Coop Portal Personal Contacts</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="domain_force">
[('id', 'in', [user.commercial_partner_id.id])]
</field>
<field name="groups" eval="[(6, 0, [ref('base.group_portal')])]"/>
</record>
</data>
</openerp>

22
easy_my_coop_website_taxshelter/views/easy_my_coop_website_taxshelter_templates.xml

@ -65,6 +65,8 @@
<thead>
<tr class="active">
<th>Declaration Year</th>
<th>Subscription Certificate</th>
<th>Share Certificate</th>
<th>Total Amount</th>
</tr>
</thead>
@ -76,7 +78,25 @@
<t t-esc="tax_shelter.declaration_id.name"/>
</a>
</td>
<td><span t-field="tax_shelter.total_amount"/></td>
<td>
<a t-att-href="'/my/subscription_certificate/pdf/%s'
% tax_shelter.id">
Subscription Certificate
</a>
</td>
<td>
<a t-att-href="'/my/share_certificate/pdf/%s'
% tax_shelter.id">
Share Certificate
</a>
</td>
<td>
<span t-field="tax_shelter.total_amount"
t-field-options='{
"widget": "monetary",
"display_currency": "tax_shelter.partner_id.company_id.currency_id"
}'/>
</td>
</tr>
</tbody>
</table>

Loading…
Cancel
Save