mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[ADD]web_well_known: manage web .well-known paths
h14437
This commit is contained in:
4
web_well_known/__init__.py
Normal file
4
web_well_known/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
|
from . import controllers
|
||||||
|
from . import models
|
||||||
18
web_well_known/__manifest__.py
Normal file
18
web_well_known/__manifest__.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'Well-known Paths',
|
||||||
|
'description': 'Manage well-known paths',
|
||||||
|
'version': '1.0',
|
||||||
|
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||||
|
'depends': [
|
||||||
|
'base'
|
||||||
|
],
|
||||||
|
'category': 'Tools',
|
||||||
|
'data': [
|
||||||
|
'security/ir.model.access.csv',
|
||||||
|
'views/views.xml',
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': True,
|
||||||
|
}
|
||||||
3
web_well_known/controllers/__init__.py
Normal file
3
web_well_known/controllers/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
|
from . import controllers
|
||||||
24
web_well_known/controllers/controllers.py
Normal file
24
web_well_known/controllers/controllers.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
|
from odoo import http
|
||||||
|
from odoo.http import request, content_disposition
|
||||||
|
|
||||||
|
class WebWellKnown(http.Controller):
|
||||||
|
@http.route('/.well-known/<path:path>', type='http', auth='public', methods=['GET'], csrf=False)
|
||||||
|
def well_known_path(self, path, **kwargs):
|
||||||
|
well_known_paths = request.env['well.known.path'].sudo()
|
||||||
|
well_known_record = well_known_paths.search([('path', '=', path)], limit=1)
|
||||||
|
|
||||||
|
if not well_known_record:
|
||||||
|
return http.Response(status=404) # Return a 404 Not Found if the path does not exist
|
||||||
|
|
||||||
|
if well_known_record.file:
|
||||||
|
text_content = well_known_record.file.decode('utf-8')
|
||||||
|
|
||||||
|
return request.make_response(
|
||||||
|
text_content, # Decode binary content to a string
|
||||||
|
headers=[('Content-Type', 'text/plain; charset=utf-8')]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
return well_known_record.value or '' # Return the value if no binary content is present, or empty string if value is None
|
||||||
3
web_well_known/models/__init__.py
Normal file
3
web_well_known/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
|
from . import models
|
||||||
39
web_well_known/models/models.py
Normal file
39
web_well_known/models/models.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
|
import mimetypes
|
||||||
|
from odoo import models, fields, api
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
class WellKnownPath(models.Model):
|
||||||
|
_name = 'well.known.path'
|
||||||
|
_description = 'Well Known Path'
|
||||||
|
|
||||||
|
path = fields.Char('Path', required=True, unique=True)
|
||||||
|
value = fields.Text('Value')
|
||||||
|
file = fields.Binary('Binary Content')
|
||||||
|
filename = fields.Char('File Name')
|
||||||
|
|
||||||
|
|
||||||
|
@api.onchange('file')
|
||||||
|
def _onchange_file(self):
|
||||||
|
for record in self:
|
||||||
|
if record.file:
|
||||||
|
if not record.filename:
|
||||||
|
record.filename = "well-known.txt" # Set a default filename if none is provided
|
||||||
|
if not record._is_text_file():
|
||||||
|
raise ValidationError("Only text files are allowed.")
|
||||||
|
|
||||||
|
def _is_text_file(self):
|
||||||
|
text_mime_types = [
|
||||||
|
'text/plain',
|
||||||
|
]
|
||||||
|
file_mimetype = mimetypes.guess_type(self.filename)[0]
|
||||||
|
if file_mimetype in text_mime_types:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@api.constrains('file', 'mimetype')
|
||||||
|
def _check_text_file(self):
|
||||||
|
for record in self:
|
||||||
|
if record.file and not record._is_text_file():
|
||||||
|
raise ValidationError("Only text files are allowed.")
|
||||||
2
web_well_known/security/ir.model.access.csv
Normal file
2
web_well_known/security/ir.model.access.csv
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
manage_well_known_path,manage_well_known_path,model_well_known_path,base.group_system,1,1,1,1
|
||||||
|
37
web_well_known/views/views.xml
Normal file
37
web_well_known/views/views.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
<odoo>
|
||||||
|
<record id="view_well_known_path_tree" model="ir.ui.view">
|
||||||
|
<field name="name">well.known.path.tree</field>
|
||||||
|
<field name="model">well.known.path</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree>
|
||||||
|
<field name="path"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_well_known_path_form" model="ir.ui.view">
|
||||||
|
<field name="name">well.known.path.form</field>
|
||||||
|
<field name="model">well.known.path</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form>
|
||||||
|
<sheet>
|
||||||
|
<group>
|
||||||
|
<field name="path"/>
|
||||||
|
<field name="value"/>
|
||||||
|
<field name="file"/>
|
||||||
|
</group>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_well_known_path" model="ir.actions.act_window">
|
||||||
|
<field name="name">Well Known Paths</field>
|
||||||
|
<field name="res_model">well.known.path</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem id="well_know_paths_menu" name="Well-Known Paths" parent="base.menu_ir_property" action="action_well_known_path"/>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user