OCA-git-bot
5 years ago
17 changed files with 906 additions and 0 deletions
-
98base_directory_file_download/README.rst
-
3base_directory_file_download/__init__.py
-
21base_directory_file_download/__manifest__.py
-
4base_directory_file_download/models/__init__.py
-
98base_directory_file_download/models/ir_filesystem_directory.py
-
58base_directory_file_download/models/ir_filesystem_file.py
-
3base_directory_file_download/readme/CONFIGURE.rst
-
1base_directory_file_download/readme/CONTRIBUTORS.rst
-
8base_directory_file_download/readme/DESCRIPTION.rst
-
7base_directory_file_download/readme/USAGE.rst
-
6base_directory_file_download/security/groups.xml
-
2base_directory_file_download/security/ir.model.access.csv
-
BINbase_directory_file_download/static/description/icon.png
-
444base_directory_file_download/static/description/index.html
-
3base_directory_file_download/tests/__init__.py
-
74base_directory_file_download/tests/test_directory_files_download.py
-
76base_directory_file_download/views/ir_filesystem_directory.xml
@ -0,0 +1,98 @@ |
|||||
|
======================== |
||||
|
Directory Files Download |
||||
|
======================== |
||||
|
|
||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
|
||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png |
||||
|
:target: https://odoo-community.org/page/development-status |
||||
|
:alt: Beta |
||||
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github |
||||
|
:target: https://github.com/OCA/server-tools/tree/11.0/base_directory_file_download |
||||
|
:alt: OCA/server-tools |
||||
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png |
||||
|
:target: https://translation.odoo-community.org/projects/server-tools-11-0/server-tools-11-0-base_directory_file_download |
||||
|
:alt: Translate me on Weblate |
||||
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png |
||||
|
:target: https://runbot.odoo-community.org/runbot/149/11.0 |
||||
|
:alt: Try me on Runbot |
||||
|
|
||||
|
|badge1| |badge2| |badge3| |badge4| |badge5| |
||||
|
|
||||
|
View and download the files contained in a directory on the server. |
||||
|
|
||||
|
This functionality can have impacts on the security of your system, |
||||
|
since it allows to download the content of a directory. |
||||
|
Be careful when choosing the directory! |
||||
|
|
||||
|
Notice that, for security reasons, files like symbolic links |
||||
|
and up-level references are ignored. |
||||
|
|
||||
|
**Table of contents** |
||||
|
|
||||
|
.. contents:: |
||||
|
:local: |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
|
||||
|
To configure this module, you need to: |
||||
|
|
||||
|
#. Set the group "Download files of directory" for the users who need this functionality. |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
To use this module, you need to: |
||||
|
|
||||
|
#. Go to Settings -> Downloads -> Directory Content |
||||
|
#. Create a record specifying Name and Directory of the server |
||||
|
#. Save; a list of files contained in the selected directory is displayed |
||||
|
#. Download the file you need |
||||
|
#. In case the content of the directory is modified, refresh the list by clicking the button on the top-right of the form |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed |
||||
|
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_directory_file_download%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Do not contact contributors directly about support or help with technical issues. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Authors |
||||
|
~~~~~~~ |
||||
|
|
||||
|
* Onestein |
||||
|
|
||||
|
Contributors |
||||
|
~~~~~~~~~~~~ |
||||
|
|
||||
|
* Andrea Stirpe <a.stirpe@onestein.nl> |
||||
|
|
||||
|
Maintainers |
||||
|
~~~~~~~~~~~ |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/11.0/base_directory_file_download>`_ project on GitHub. |
||||
|
|
||||
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
@ -0,0 +1,3 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import models |
@ -0,0 +1,21 @@ |
|||||
|
# Copyright 2017-2019 Onestein (<https://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
{ |
||||
|
'name': 'Directory Files Download', |
||||
|
'summary': 'Download all files of a directory on server', |
||||
|
'author': 'Onestein, Odoo Community Association (OCA)', |
||||
|
'website': 'https://github.com/OCA/server-tools', |
||||
|
'category': 'Tools', |
||||
|
'version': '11.0.1.0.0', |
||||
|
'license': 'AGPL-3', |
||||
|
'depends': [ |
||||
|
'base_setup', |
||||
|
], |
||||
|
'data': [ |
||||
|
'security/groups.xml', |
||||
|
'security/ir.model.access.csv', |
||||
|
'views/ir_filesystem_directory.xml', |
||||
|
], |
||||
|
'installable': True, |
||||
|
} |
@ -0,0 +1,4 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import ir_filesystem_directory |
||||
|
from . import ir_filesystem_file |
@ -0,0 +1,98 @@ |
|||||
|
# Copyright 2017-2019 Onestein (<https://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
import logging |
||||
|
|
||||
|
from glob import glob |
||||
|
from os.path import basename, isfile, join, exists, normpath, realpath |
||||
|
|
||||
|
from odoo import api, fields, models, _ |
||||
|
from odoo.exceptions import UserError |
||||
|
|
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class IrFilesystemDirectory(models.Model): |
||||
|
_name = 'ir.filesystem.directory' |
||||
|
_description = 'Filesystem Directory' |
||||
|
|
||||
|
name = fields.Char(required=True, copy=False) |
||||
|
directory = fields.Char() |
||||
|
file_ids = fields.One2many( |
||||
|
'ir.filesystem.file', |
||||
|
compute='_compute_file_ids', |
||||
|
string='Files', |
||||
|
) |
||||
|
file_count = fields.Integer( |
||||
|
compute='_compute_file_count', |
||||
|
string="# Files", |
||||
|
) |
||||
|
files_filter = fields.Char() |
||||
|
|
||||
|
@api.multi |
||||
|
def get_dir(self): |
||||
|
self.ensure_one() |
||||
|
directory = self.directory or '' |
||||
|
# adds slash character at the end if missing |
||||
|
return join(directory, '') |
||||
|
|
||||
|
@api.multi |
||||
|
def _compute_file_ids(self): |
||||
|
File = self.env['ir.filesystem.file'] |
||||
|
for directory in self: |
||||
|
directory.file_ids = None |
||||
|
if directory.get_dir(): |
||||
|
for file_name in directory._get_directory_files(): |
||||
|
directory.file_ids += File.create({ |
||||
|
'name': file_name, |
||||
|
'filename': file_name, |
||||
|
'stored_filename': file_name, |
||||
|
'directory_id': directory.id, |
||||
|
}) |
||||
|
|
||||
|
@api.onchange('directory') |
||||
|
def onchange_directory(self): |
||||
|
if self.directory and not exists(self.directory): |
||||
|
raise UserError(_('Directory does not exist')) |
||||
|
|
||||
|
@api.multi |
||||
|
def _compute_file_count(self): |
||||
|
for directory in self: |
||||
|
directory.file_count = len(directory.file_ids) |
||||
|
|
||||
|
@api.multi |
||||
|
def _get_directory_files(self): |
||||
|
|
||||
|
def get_files(directory, files_filter): |
||||
|
glob_path = join(directory, files_filter) |
||||
|
content = glob(glob_path) |
||||
|
for full_path in content: |
||||
|
file_name = basename(full_path) |
||||
|
# Symbolic links and up-level references are not considered |
||||
|
norm_path = normpath(realpath(full_path)) |
||||
|
if norm_path in full_path: |
||||
|
if isfile(full_path) and file_name[0] != '.': |
||||
|
files.append(file_name) |
||||
|
|
||||
|
self.ensure_one() |
||||
|
files = [] |
||||
|
if self.get_dir() and exists(self.get_dir()): |
||||
|
try: |
||||
|
get_files(self.get_dir(), self.files_filter or '*') |
||||
|
except (IOError, OSError): |
||||
|
_logger.info( |
||||
|
"_get_directory_files reading %s", |
||||
|
self.get_dir(), |
||||
|
exc_info=True |
||||
|
) |
||||
|
return files |
||||
|
|
||||
|
@api.multi |
||||
|
def reload(self): |
||||
|
self.onchange_directory() |
||||
|
|
||||
|
@api.multi |
||||
|
def copy(self, default=None): |
||||
|
self.ensure_one() |
||||
|
default = dict(default or {}, name=_("%s (copy)") % self.name) |
||||
|
return super(IrFilesystemDirectory, self).copy(default=default) |
@ -0,0 +1,58 @@ |
|||||
|
# Copyright 2017-2019 Onestein (<https://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
import base64 |
||||
|
import logging |
||||
|
import os |
||||
|
|
||||
|
from odoo import api, fields, models, _ |
||||
|
from odoo.exceptions import UserError |
||||
|
from odoo.tools import human_size |
||||
|
|
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class IrFilesystemDirectoryLine(models.TransientModel): |
||||
|
_name = 'ir.filesystem.file' |
||||
|
_description = 'File in filesystem' |
||||
|
|
||||
|
name = fields.Char(required=True) |
||||
|
filename = fields.Char() |
||||
|
file_content = fields.Binary(compute='_compute_file') |
||||
|
stored_filename = fields.Char() |
||||
|
directory_id = fields.Many2one( |
||||
|
'ir.filesystem.directory', |
||||
|
string='Directory', |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
def _file_read(self, fname, bin_size=False): |
||||
|
|
||||
|
def file_not_found(fname): |
||||
|
raise UserError(_( |
||||
|
'''Error while reading file %s. |
||||
|
Maybe it was removed or permission is changed. |
||||
|
Please refresh the list.''' % fname)) |
||||
|
|
||||
|
self.ensure_one() |
||||
|
r = '' |
||||
|
directory = self.directory_id.get_dir() |
||||
|
full_path = directory + fname |
||||
|
if not (directory and os.path.isfile(full_path)): |
||||
|
file_not_found(fname) |
||||
|
try: |
||||
|
if bin_size: |
||||
|
r = human_size(os.path.getsize(full_path)) |
||||
|
else: |
||||
|
r = base64.b64encode(open(full_path, 'rb').read()) |
||||
|
except (IOError, OSError): |
||||
|
_logger.info("_read_file reading %s", fname, exc_info=True) |
||||
|
return r |
||||
|
|
||||
|
@api.depends('stored_filename') |
||||
|
def _compute_file(self): |
||||
|
bin_size = self.env.context.get('bin_size') |
||||
|
for line in self: |
||||
|
if line.stored_filename: |
||||
|
content = line._file_read(line.stored_filename, bin_size) |
||||
|
line.file_content = content |
@ -0,0 +1,3 @@ |
|||||
|
To configure this module, you need to: |
||||
|
|
||||
|
#. Set the group "Download files of directory" for the users who need this functionality. |
@ -0,0 +1 @@ |
|||||
|
* Andrea Stirpe <a.stirpe@onestein.nl> |
@ -0,0 +1,8 @@ |
|||||
|
View and download the files contained in a directory on the server. |
||||
|
|
||||
|
This functionality can have impacts on the security of your system, |
||||
|
since it allows to download the content of a directory. |
||||
|
Be careful when choosing the directory! |
||||
|
|
||||
|
Notice that, for security reasons, files like symbolic links |
||||
|
and up-level references are ignored. |
@ -0,0 +1,7 @@ |
|||||
|
To use this module, you need to: |
||||
|
|
||||
|
#. Go to Settings -> Downloads -> Directory Content |
||||
|
#. Create a record specifying Name and Directory of the server |
||||
|
#. Save; a list of files contained in the selected directory is displayed |
||||
|
#. Download the file you need |
||||
|
#. In case the content of the directory is modified, refresh the list by clicking the button on the top-right of the form |
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<record model="res.groups" id="group_filesystem_directory"> |
||||
|
<field name="name">Download files of directory</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,2 @@ |
|||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink |
||||
|
access_ir_filesystem_directory,ir_filesystem_directory,model_ir_filesystem_directory,group_filesystem_directory,1,1,1,1 |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1,444 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8" ?> |
||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
||||
|
<head> |
||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||
|
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" /> |
||||
|
<title>Directory Files Download</title> |
||||
|
<style type="text/css"> |
||||
|
|
||||
|
/* |
||||
|
:Author: David Goodger (goodger@python.org) |
||||
|
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $ |
||||
|
:Copyright: This stylesheet has been placed in the public domain. |
||||
|
|
||||
|
Default cascading style sheet for the HTML output of Docutils. |
||||
|
|
||||
|
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to |
||||
|
customize this style sheet. |
||||
|
*/ |
||||
|
|
||||
|
/* used to remove borders from tables and images */ |
||||
|
.borderless, table.borderless td, table.borderless th { |
||||
|
border: 0 } |
||||
|
|
||||
|
table.borderless td, table.borderless th { |
||||
|
/* Override padding for "table.docutils td" with "! important". |
||||
|
The right padding separates the table cells. */ |
||||
|
padding: 0 0.5em 0 0 ! important } |
||||
|
|
||||
|
.first { |
||||
|
/* Override more specific margin styles with "! important". */ |
||||
|
margin-top: 0 ! important } |
||||
|
|
||||
|
.last, .with-subtitle { |
||||
|
margin-bottom: 0 ! important } |
||||
|
|
||||
|
.hidden { |
||||
|
display: none } |
||||
|
|
||||
|
.subscript { |
||||
|
vertical-align: sub; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
.superscript { |
||||
|
vertical-align: super; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
a.toc-backref { |
||||
|
text-decoration: none ; |
||||
|
color: black } |
||||
|
|
||||
|
blockquote.epigraph { |
||||
|
margin: 2em 5em ; } |
||||
|
|
||||
|
dl.docutils dd { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] { |
||||
|
overflow: hidden; |
||||
|
} |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get bold-faced definition list terms |
||||
|
dl.docutils dt { |
||||
|
font-weight: bold } |
||||
|
*/ |
||||
|
|
||||
|
div.abstract { |
||||
|
margin: 2em 5em } |
||||
|
|
||||
|
div.abstract p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
text-align: center } |
||||
|
|
||||
|
div.admonition, div.attention, div.caution, div.danger, div.error, |
||||
|
div.hint, div.important, div.note, div.tip, div.warning { |
||||
|
margin: 2em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.admonition p.admonition-title, div.hint p.admonition-title, |
||||
|
div.important p.admonition-title, div.note p.admonition-title, |
||||
|
div.tip p.admonition-title { |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
div.attention p.admonition-title, div.caution p.admonition-title, |
||||
|
div.danger p.admonition-title, div.error p.admonition-title, |
||||
|
div.warning p.admonition-title, .code .error { |
||||
|
color: red ; |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get reduced vertical space in |
||||
|
compound paragraphs. |
||||
|
div.compound .compound-first, div.compound .compound-middle { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
div.compound .compound-last, div.compound .compound-middle { |
||||
|
margin-top: 0.5em } |
||||
|
*/ |
||||
|
|
||||
|
div.dedication { |
||||
|
margin: 2em 5em ; |
||||
|
text-align: center ; |
||||
|
font-style: italic } |
||||
|
|
||||
|
div.dedication p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
font-style: normal } |
||||
|
|
||||
|
div.figure { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
div.footer, div.header { |
||||
|
clear: both; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
div.line-block { |
||||
|
display: block ; |
||||
|
margin-top: 1em ; |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
div.line-block div.line-block { |
||||
|
margin-top: 0 ; |
||||
|
margin-bottom: 0 ; |
||||
|
margin-left: 1.5em } |
||||
|
|
||||
|
div.sidebar { |
||||
|
margin: 0 0 0.5em 1em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em ; |
||||
|
background-color: #ffffee ; |
||||
|
width: 40% ; |
||||
|
float: right ; |
||||
|
clear: right } |
||||
|
|
||||
|
div.sidebar p.rubric { |
||||
|
font-family: sans-serif ; |
||||
|
font-size: medium } |
||||
|
|
||||
|
div.system-messages { |
||||
|
margin: 5em } |
||||
|
|
||||
|
div.system-messages h1 { |
||||
|
color: red } |
||||
|
|
||||
|
div.system-message { |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.system-message p.system-message-title { |
||||
|
color: red ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
div.topic { |
||||
|
margin: 2em } |
||||
|
|
||||
|
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, |
||||
|
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { |
||||
|
margin-top: 0.4em } |
||||
|
|
||||
|
h1.title { |
||||
|
text-align: center } |
||||
|
|
||||
|
h2.subtitle { |
||||
|
text-align: center } |
||||
|
|
||||
|
hr.docutils { |
||||
|
width: 75% } |
||||
|
|
||||
|
img.align-left, .figure.align-left, object.align-left, table.align-left { |
||||
|
clear: left ; |
||||
|
float: left ; |
||||
|
margin-right: 1em } |
||||
|
|
||||
|
img.align-right, .figure.align-right, object.align-right, table.align-right { |
||||
|
clear: right ; |
||||
|
float: right ; |
||||
|
margin-left: 1em } |
||||
|
|
||||
|
img.align-center, .figure.align-center, object.align-center { |
||||
|
display: block; |
||||
|
margin-left: auto; |
||||
|
margin-right: auto; |
||||
|
} |
||||
|
|
||||
|
table.align-center { |
||||
|
margin-left: auto; |
||||
|
margin-right: auto; |
||||
|
} |
||||
|
|
||||
|
.align-left { |
||||
|
text-align: left } |
||||
|
|
||||
|
.align-center { |
||||
|
clear: both ; |
||||
|
text-align: center } |
||||
|
|
||||
|
.align-right { |
||||
|
text-align: right } |
||||
|
|
||||
|
/* reset inner alignment in figures */ |
||||
|
div.align-right { |
||||
|
text-align: inherit } |
||||
|
|
||||
|
/* div.align-center * { */ |
||||
|
/* text-align: left } */ |
||||
|
|
||||
|
.align-top { |
||||
|
vertical-align: top } |
||||
|
|
||||
|
.align-middle { |
||||
|
vertical-align: middle } |
||||
|
|
||||
|
.align-bottom { |
||||
|
vertical-align: bottom } |
||||
|
|
||||
|
ol.simple, ul.simple { |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
ol.arabic { |
||||
|
list-style: decimal } |
||||
|
|
||||
|
ol.loweralpha { |
||||
|
list-style: lower-alpha } |
||||
|
|
||||
|
ol.upperalpha { |
||||
|
list-style: upper-alpha } |
||||
|
|
||||
|
ol.lowerroman { |
||||
|
list-style: lower-roman } |
||||
|
|
||||
|
ol.upperroman { |
||||
|
list-style: upper-roman } |
||||
|
|
||||
|
p.attribution { |
||||
|
text-align: right ; |
||||
|
margin-left: 50% } |
||||
|
|
||||
|
p.caption { |
||||
|
font-style: italic } |
||||
|
|
||||
|
p.credits { |
||||
|
font-style: italic ; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
p.label { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
p.rubric { |
||||
|
font-weight: bold ; |
||||
|
font-size: larger ; |
||||
|
color: maroon ; |
||||
|
text-align: center } |
||||
|
|
||||
|
p.sidebar-title { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold ; |
||||
|
font-size: larger } |
||||
|
|
||||
|
p.sidebar-subtitle { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
p.topic-title { |
||||
|
font-weight: bold } |
||||
|
|
||||
|
pre.address { |
||||
|
margin-bottom: 0 ; |
||||
|
margin-top: 0 ; |
||||
|
font: inherit } |
||||
|
|
||||
|
pre.literal-block, pre.doctest-block, pre.math, pre.code { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
pre.code .ln { color: grey; } /* line numbers */ |
||||
|
pre.code, code { background-color: #eeeeee } |
||||
|
pre.code .comment, code .comment { color: #5C6576 } |
||||
|
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } |
||||
|
pre.code .literal.string, code .literal.string { color: #0C5404 } |
||||
|
pre.code .name.builtin, code .name.builtin { color: #352B84 } |
||||
|
pre.code .deleted, code .deleted { background-color: #DEB0A1} |
||||
|
pre.code .inserted, code .inserted { background-color: #A3D289} |
||||
|
|
||||
|
span.classifier { |
||||
|
font-family: sans-serif ; |
||||
|
font-style: oblique } |
||||
|
|
||||
|
span.classifier-delimiter { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
span.interpreted { |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
span.option { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
span.pre { |
||||
|
white-space: pre } |
||||
|
|
||||
|
span.problematic { |
||||
|
color: red } |
||||
|
|
||||
|
span.section-subtitle { |
||||
|
/* font-size relative to parent (h1..h6 element) */ |
||||
|
font-size: 80% } |
||||
|
|
||||
|
table.citation { |
||||
|
border-left: solid 1px gray; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docinfo { |
||||
|
margin: 2em 4em } |
||||
|
|
||||
|
table.docutils { |
||||
|
margin-top: 0.5em ; |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
table.footnote { |
||||
|
border-left: solid 1px black; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docutils td, table.docutils th, |
||||
|
table.docinfo td, table.docinfo th { |
||||
|
padding-left: 0.5em ; |
||||
|
padding-right: 0.5em ; |
||||
|
vertical-align: top } |
||||
|
|
||||
|
table.docutils th.field-name, table.docinfo th.docinfo-name { |
||||
|
font-weight: bold ; |
||||
|
text-align: left ; |
||||
|
white-space: nowrap ; |
||||
|
padding-left: 0 } |
||||
|
|
||||
|
/* "booktabs" style (no vertical lines) */ |
||||
|
table.docutils.booktabs { |
||||
|
border: 0px; |
||||
|
border-top: 2px solid; |
||||
|
border-bottom: 2px solid; |
||||
|
border-collapse: collapse; |
||||
|
} |
||||
|
table.docutils.booktabs * { |
||||
|
border: 0px; |
||||
|
} |
||||
|
table.docutils.booktabs th { |
||||
|
border-bottom: thin solid; |
||||
|
text-align: left; |
||||
|
} |
||||
|
|
||||
|
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, |
||||
|
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { |
||||
|
font-size: 100% } |
||||
|
|
||||
|
ul.auto-toc { |
||||
|
list-style-type: none } |
||||
|
|
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div class="document" id="directory-files-download"> |
||||
|
<h1 class="title">Directory Files Download</h1> |
||||
|
|
||||
|
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> |
||||
|
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-tools/tree/10.0/base_directory_file_download"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-tools-10-0/server-tools-10-0-base_directory_file_download"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/149/10.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> |
||||
|
<p>View and download the files contained in a directory on the server.</p> |
||||
|
<p>This functionality can have impacts on the security of your system, |
||||
|
since it allows to download the content of a directory. |
||||
|
Be careful when choosing the directory!</p> |
||||
|
<p>Notice that, for security reasons, files like symbolic links |
||||
|
and up-level references are ignored.</p> |
||||
|
<p><strong>Table of contents</strong></p> |
||||
|
<div class="contents local topic" id="contents"> |
||||
|
<ul class="simple"> |
||||
|
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li> |
||||
|
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li> |
||||
|
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li> |
||||
|
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul> |
||||
|
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li> |
||||
|
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li> |
||||
|
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li> |
||||
|
</ul> |
||||
|
</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="configuration"> |
||||
|
<h1><a class="toc-backref" href="#id1">Configuration</a></h1> |
||||
|
<p>To configure this module, you need to:</p> |
||||
|
<ol class="arabic simple"> |
||||
|
<li>Set the group “Download files of directory” for the users who need this functionality.</li> |
||||
|
</ol> |
||||
|
</div> |
||||
|
<div class="section" id="usage"> |
||||
|
<h1><a class="toc-backref" href="#id2">Usage</a></h1> |
||||
|
<p>To use this module, you need to:</p> |
||||
|
<ol class="arabic simple"> |
||||
|
<li>Go to Settings -> Downloads -> Directory Content</li> |
||||
|
<li>Create a record specifying Name and Directory of the server</li> |
||||
|
<li>Save; a list of files contained in the selected directory is displayed</li> |
||||
|
<li>Download the file you need</li> |
||||
|
<li>In case the content of the directory is modified, refresh the list by clicking the button on the top-right of the form</li> |
||||
|
</ol> |
||||
|
</div> |
||||
|
<div class="section" id="bug-tracker"> |
||||
|
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1> |
||||
|
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed |
||||
|
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_directory_file_download%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> |
||||
|
<p>Do not contact contributors directly about support or help with technical issues.</p> |
||||
|
</div> |
||||
|
<div class="section" id="credits"> |
||||
|
<h1><a class="toc-backref" href="#id4">Credits</a></h1> |
||||
|
<div class="section" id="authors"> |
||||
|
<h2><a class="toc-backref" href="#id5">Authors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Onestein</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="contributors"> |
||||
|
<h2><a class="toc-backref" href="#id6">Contributors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Andrea Stirpe <<a class="reference external" href="mailto:a.stirpe@onestein.nl">a.stirpe@onestein.nl</a>></li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="maintainers"> |
||||
|
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2> |
||||
|
<p>This module is maintained by the OCA.</p> |
||||
|
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> |
||||
|
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use.</p> |
||||
|
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/10.0/base_directory_file_download">OCA/server-tools</a> project on GitHub.</p> |
||||
|
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,3 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import test_directory_files_download |
@ -0,0 +1,74 @@ |
|||||
|
# Copyright 2017-2019 Onestein (<https://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
import base64 |
||||
|
import os |
||||
|
from tempfile import gettempdir |
||||
|
|
||||
|
from odoo.tests import common |
||||
|
from odoo.exceptions import UserError |
||||
|
|
||||
|
|
||||
|
class TestBaseDirectoryFilesDownload(common.TransactionCase): |
||||
|
|
||||
|
def test_01_create(self): |
||||
|
test_dir = self.env['ir.filesystem.directory'].create({ |
||||
|
'name': 'Test Directory 1', |
||||
|
'directory': gettempdir() |
||||
|
}) |
||||
|
|
||||
|
# test method get_dir() |
||||
|
full_dir = test_dir.get_dir() |
||||
|
self.assertEqual(full_dir[-1], '/') |
||||
|
|
||||
|
# test computed field file_ids |
||||
|
self.assertGreaterEqual(len(test_dir.file_ids), 0) |
||||
|
|
||||
|
# test count list of directory |
||||
|
self.assertEqual(len(test_dir.file_ids), test_dir.file_count) |
||||
|
|
||||
|
# test reload list of directory |
||||
|
test_dir.reload() |
||||
|
self.assertEqual(len(test_dir.file_ids), test_dir.file_count) |
||||
|
|
||||
|
# test content of files |
||||
|
for file in test_dir.file_ids: |
||||
|
filename = file.stored_filename |
||||
|
directory = test_dir.get_dir() |
||||
|
with open(os.path.join(directory, filename), 'rb') as f: |
||||
|
content = base64.b64encode(f.read()) |
||||
|
self.assertEqual(file.file_content, content) |
||||
|
|
||||
|
# test onchange directory (to not existing) |
||||
|
test_dir.directory = '/txxx' |
||||
|
with self.assertRaises(UserError): |
||||
|
test_dir.onchange_directory() |
||||
|
self.assertEqual(len(test_dir.file_ids), 0) |
||||
|
with self.assertRaises(UserError): |
||||
|
test_dir.reload() |
||||
|
self.assertEqual(len(test_dir.file_ids), 0) |
||||
|
|
||||
|
def test_02_copy(self): |
||||
|
test_dir = self.env['ir.filesystem.directory'].create({ |
||||
|
'name': 'Test Orig', |
||||
|
'directory': gettempdir() |
||||
|
}) |
||||
|
|
||||
|
# test copy |
||||
|
dir_copy = test_dir.copy() |
||||
|
self.assertEqual(dir_copy.name, 'Test Orig (copy)') |
||||
|
self.assertEqual(len(dir_copy.file_ids), test_dir.file_count) |
||||
|
self.assertEqual(dir_copy.file_count, test_dir.file_count) |
||||
|
|
||||
|
def test_03_not_existing_directory(self): |
||||
|
test_dir = self.env['ir.filesystem.directory'].create({ |
||||
|
'name': 'Test Not Existing Directory', |
||||
|
'directory': '/tpd' |
||||
|
}) |
||||
|
self.assertEqual(len(test_dir.file_ids), 0) |
||||
|
self.assertEqual(len(test_dir.file_ids), test_dir.file_count) |
||||
|
|
||||
|
# test onchange directory (to existing) |
||||
|
test_dir.directory = gettempdir() |
||||
|
self.assertGreaterEqual(len(test_dir.file_ids), 0) |
||||
|
self.assertEqual(len(test_dir.file_ids), test_dir.file_count) |
@ -0,0 +1,76 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
|
||||
|
<record id="ir_filesystem_directory_form" model="ir.ui.view"> |
||||
|
<field name="model">ir.filesystem.directory</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form> |
||||
|
<sheet> |
||||
|
<div class="oe_button_box" name="button_box"> |
||||
|
<button name="reload" type="object" |
||||
|
string="Files:" |
||||
|
class="oe_stat_button" icon="fa-repeat"> |
||||
|
<field name="file_count" /> |
||||
|
</button> |
||||
|
</div> |
||||
|
<h1> |
||||
|
<field name="name"/> |
||||
|
</h1> |
||||
|
<group> |
||||
|
<field name="directory" required="1"/> |
||||
|
<field name="files_filter" placeholder="Enter a pattern to filter file names, eg.: *.txt"/> |
||||
|
</group> |
||||
|
<notebook name="notebook"> |
||||
|
<page name="files" string="Files"> |
||||
|
<field name="file_ids" readonly="1"> |
||||
|
<form> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="name"/> |
||||
|
</group> |
||||
|
<group> |
||||
|
<field name="file_content" filename="filename"/> |
||||
|
<field name="filename" invisible="1" class="oe_inline oe_right"/> |
||||
|
</group> |
||||
|
</group> |
||||
|
</form> |
||||
|
<tree> |
||||
|
<field name="name"/> |
||||
|
<field name="file_content" filename="filename"/> |
||||
|
<field name="filename" invisible="1"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</page> |
||||
|
</notebook> |
||||
|
</sheet> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="ir_filesystem_directory_tree" model="ir.ui.view"> |
||||
|
<field name="model">ir.filesystem.directory</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<tree> |
||||
|
<field name="name" /> |
||||
|
<field name="directory" /> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="ir_filesystem_directory_action" model="ir.actions.act_window"> |
||||
|
<field name="name">Directory Content</field> |
||||
|
<field name="res_model">ir.filesystem.directory</field> |
||||
|
<field name="view_type">form</field> |
||||
|
<field name="view_mode">tree,form</field> |
||||
|
</record> |
||||
|
|
||||
|
<menuitem id="menu_ir_filesystem" |
||||
|
name="Downloads" |
||||
|
parent="base.menu_administration"/> |
||||
|
|
||||
|
<menuitem id="menu_ir_filesystem_directory" |
||||
|
action="ir_filesystem_directory_action" |
||||
|
groups="group_filesystem_directory" |
||||
|
parent="menu_ir_filesystem" /> |
||||
|
|
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue