Skip to content

Commit a9005ff

Browse files
committed
Dec 12 : [ADD] Initial Commit 'amazon_s3_connector'
1 parent 5b2a0c4 commit a9005ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1429
-0
lines changed

amazon_s3_connector/README.rst

Lines changed: 54 additions & 0 deletions

amazon_s3_connector/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
###############################################################################
3+
#
4+
# Cybrosys Technologies Pvt. Ltd.
5+
#
6+
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
7+
# Author: Aslam A K( [email protected] )
8+
#
9+
# You can modify it under the terms of the GNU AFFERO
10+
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
16+
#
17+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
18+
# (AGPL v3) along with this program.
19+
# If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
###############################################################################
22+
from . import models
23+
from . import wizard
24+
from .hooks import uninstall_hook

amazon_s3_connector/__manifest__.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
###############################################################################
3+
#
4+
# Cybrosys Technologies Pvt. Ltd.
5+
#
6+
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
7+
# Author: Aslam A K( [email protected] )
8+
#
9+
# You can modify it under the terms of the GNU AFFERO
10+
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
16+
#
17+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
18+
# (AGPL v3) along with this program.
19+
# If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
###############################################################################
22+
{
23+
'name': "Amazon S3 Connector",
24+
'version': "15.0.1.0.0'",
25+
'category': "Document Management",
26+
'summary': """Connect with Amazon S3 Files from Odoo""",
27+
'description': """ This module was developed to upload to Amazon S3 Cloud
28+
Storage as well as access files from Amazon S3 Cloud Storage in Odoo.""",
29+
'author': 'Cybrosys Techno Solutions',
30+
'company': 'Cybrosys Techno Solutions',
31+
'maintainer': 'Cybrosys Techno Solutions',
32+
'website': "https://www.cybrosys.com",
33+
'depends': ['base_setup'],
34+
'data': [
35+
'security/ir.model.access.csv',
36+
'views/amazon_dashboard_views.xml',
37+
'views/res_config_settings_views.xml',
38+
'wizard/amazon_upload_file_views.xml'
39+
],
40+
'assets': {
41+
'web.assets_backend': [
42+
'amazon_s3_connector/static/src/js/amazon.js',
43+
'/amazon_s3_connector/static/src/scss/amazon.scss'
44+
],
45+
'web.assets_qweb': [
46+
'/amazon_s3_connector/static/src/xml/amazon_dashboard_template.xml',
47+
],
48+
},
49+
'external_dependencies': {'python': ['boto3']},
50+
'images': ['static/description/banner.png'],
51+
'license': 'AGPL-3',
52+
'installable': True,
53+
'auto_install': False,
54+
'application': True,
55+
'uninstall_hook': 'uninstall_hook',
56+
}
Lines changed: 6 additions & 0 deletions

amazon_s3_connector/hooks.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
###############################################################################
3+
#
4+
# Cybrosys Technologies Pvt. Ltd.
5+
#
6+
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
7+
# Author: Aslam A K( [email protected] )
8+
#
9+
# You can modify it under the terms of the GNU AFFERO
10+
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
16+
#
17+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
18+
# (AGPL v3) along with this program.
19+
# If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
###############################################################################
22+
from odoo import api, SUPERUSER_ID
23+
24+
25+
def uninstall_hook(cr, registry):
26+
""" Deletes System Parameters on uninstalling application """
27+
env = api.Environment(cr, SUPERUSER_ID, {})
28+
env['ir.config_parameter'].sudo().search(
29+
[('key', '=', 'amazon_s3_connector.amazon_access_key')]).unlink()
30+
env['ir.config_parameter'].sudo().search(
31+
[('key', '=', 'amazon_s3_connector.amazon_secret_key')]).unlink()
32+
env['ir.config_parameter'].sudo().search(
33+
[('key', '=', 'amazon_s3_connector.amazon_bucket_name')]).unlink()
34+
env['ir.config_parameter'].sudo().search(
35+
[('key', '=', 'amazon_s3_connector.amazon_button')]).unlink()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
###############################################################################
3+
#
4+
# Cybrosys Technologies Pvt. Ltd.
5+
#
6+
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
7+
# Author: Aslam A K( [email protected] )
8+
#
9+
# You can modify it under the terms of the GNU AFFERO
10+
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
16+
#
17+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
18+
# (AGPL v3) along with this program.
19+
# If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
###############################################################################
22+
from . import amazon_dashboard
23+
from . import res_config_settings
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- coding: utf-8 -*-
2+
###############################################################################
3+
#
4+
# Cybrosys Technologies Pvt. Ltd.
5+
#
6+
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
7+
# Author: Aslam A K( [email protected] )
8+
#
9+
# You can modify it under the terms of the GNU AFFERO
10+
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
16+
#
17+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
18+
# (AGPL v3) along with this program.
19+
# If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
###############################################################################
22+
import boto3
23+
import os
24+
from odoo import models
25+
26+
27+
class AmazonDashboard(models.Model):
28+
""" Dashboard model to connect with Amazon S3 """
29+
_name = 'amazon.dashboard'
30+
_description = "Amazon Dashboard"
31+
32+
def amazon_view_files(self):
33+
""" Fetch all files from s3 and returns it. """
34+
access_key = self.env['ir.config_parameter'].get_param(
35+
'amazon_s3_connector.amazon_access_key')
36+
access_secret = self.env['ir.config_parameter'].get_param(
37+
'amazon_s3_connector.amazon_secret_key')
38+
bucket_name = self.env['ir.config_parameter'].get_param(
39+
'amazon_s3_connector.amazon_bucket_name')
40+
if not access_key or not access_secret or not bucket_name:
41+
return False
42+
try:
43+
client = boto3.client('s3', aws_access_key_id=access_key,
44+
aws_secret_access_key=access_secret)
45+
region = client.get_bucket_location(Bucket=bucket_name)
46+
client = boto3.client(
47+
's3', region_name=region['LocationConstraint'],
48+
aws_access_key_id=access_key,
49+
aws_secret_access_key=access_secret
50+
)
51+
response = client.list_objects(Bucket=bucket_name)
52+
file = []
53+
for data in response['Contents']:
54+
url = client.generate_presigned_url(
55+
ClientMethod='get_object',
56+
Params={'Bucket': bucket_name, 'Key': data['Key']})
57+
if data['Size'] == 0:
58+
continue
59+
size_bytes = data['Size'] / 1024
60+
if size_bytes > 1024:
61+
size = str(round(data['Size'] / (1024 * 1024), 1)) + ' MB'
62+
else:
63+
size = str(round(data['Size'] / 1024, 1)) + ' KB'
64+
file_type = str.upper(
65+
os.path.splitext(data['Key'])[1].replace('.', ''))
66+
file.append([data['Key'], url, file_type,
67+
str(data['LastModified']), size])
68+
return file
69+
except Exception as error:
70+
return ['e', error]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- coding: utf-8 -*-
2+
###############################################################################
3+
#
4+
# Cybrosys Technologies Pvt. Ltd.
5+
#
6+
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
7+
# Author: Aslam A K( [email protected] )
8+
#
9+
# You can modify it under the terms of the GNU AFFERO
10+
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
16+
#
17+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
18+
# (AGPL v3) along with this program.
19+
# If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
###############################################################################
22+
from odoo import fields, models
23+
24+
25+
class ResConfigSettings(models.TransientModel):
26+
""" Configure the access credentials """
27+
_inherit = 'res.config.settings'
28+
29+
amazon_access_key = fields.Char(string='Amazon S3 Access Key', copy=False,
30+
config_parameter='amazon_s3_connector.'
31+
'amazon_access_key',
32+
help='Enter your Amazon S3 Access Key'
33+
' here.')
34+
amazon_secret_key = fields.Char(string='Amazon S3 Secret key',
35+
config_parameter='amazon_s3_connector.'
36+
'amazon_secret_key',
37+
help='Enter your Amazon S3 Secret Key '
38+
'here.')
39+
amazon_bucket_name = fields.Char(string='Folder ID',
40+
config_parameter='amazon_s3_connector.'
41+
'amazon_bucket_name',
42+
help='Enter the name of your Amazon S3 '
43+
'Bucket here.')
44+
is_amazon_connector = fields.Boolean(string="Amazon S3 Connector",
45+
config_parameter='amazon_s3_connector'
46+
'.amazon_button',
47+
help='Enable or disable the Amazon S3'
48+
' connector.')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
2+
access_amazon_dashboard,access.amazon.dashboard,model_amazon_dashboard,base.group_user,1,1,1,1
3+
access_amazon_upload_file,access.amazon.upload.file,model_amazon_upload_file,base.group_user,1,1,1,1

0 commit comments

Comments
 (0)