Skip to content
Permalink
Browse files

Merge pull request #17 from trojikman/12.0-saas_public-add-module

🎉 saas_public
  • Loading branch information...
yelizariev committed Jul 9, 2019
2 parents 03debc5 + 5b0c5b7 commit 6ff5fa2626e0bfc819706f04f12b64e30da79d07
@@ -74,8 +74,6 @@ Further information

Demo: http://runbot.it-projects.info/demo/saas-addons/12.0

HTML Description: https://apps.odoo.com/apps/modules/12.0/saas/

Usage instructions: `<doc/index.rst>`_

Changelog: `<doc/changelog.rst>`_
@@ -1,2 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_saas
from . import test_saas, common_saas_test
@@ -0,0 +1,73 @@
# Copyright 2019 Denis Mudarisov <https://it-projects.info/team/trojikman>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.service import db

DB_TEMPLATE_1 = 'db_template_1'
DB_TEMPLATE_2 = 'db_template_2'
MODULE_TO_INSTALL = 'mail'
TEMPLATE_TEST_SUBJECT = 'Dummy subject name to test that code is applied on template database'
BUILD_TEST_SUBJECT = 'Dummy subject name to test that code is applied on build database'
DEFAULT_BUILD_PYTHON_CODE = """# Available variables:
# - env: Odoo Environment on which the action is triggered
# - time, datetime, dateutil, timezone: useful Python libraries
# - log: log(message, level='info'): logging function to record debug information in ir.logging table
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {{...}}
# You can specify places for variables that can be passed when creating a build like this:
# env['{key_name_1}'].create({{'subject': '{key_name_2}', }})
# When you need curly braces in build post init code use doubling for escaping\n\n\n\n"""


class Common(object):
def setup_saas_env(self):
self.env = self.env(context=dict(
self.env.context,
test_queue_job_no_delay=True,
))

self.saas_template_1 = self.env['saas.template'].create({
'template_module_ids': [(0, 0, {
'name': MODULE_TO_INSTALL,
})],
'template_post_init': 'env[\'mail.message\'].create({\'subject\': \'' + TEMPLATE_TEST_SUBJECT + '\', })',
'build_post_init': DEFAULT_BUILD_PYTHON_CODE + 'env[\'{mail_message}\'].create({{\'subject\': \'' + BUILD_TEST_SUBJECT + '\', }})',
})

self.saas_template_2 = self.env['saas.template'].create({
'template_module_ids': [(0, 0, {
'name': 'mail',
})],
'template_post_init': 'env[\'mail.message\'].create({\'subject\': \'' + TEMPLATE_TEST_SUBJECT + '\', })',
})

self.saas_operator_1 = self.env['saas.operator'].create({
'type': 'local',
'db_url_template': 'http://{db_name}.{db_id}.127.0.0.1.nip.io:8069',
'master_url': 'http://saas.127.0.0.1.nip.io:8069',
})

self.saas_operator_2 = self.env['saas.operator'].create({
'type': 'local',
'db_url_template': 'http://{db_name}.{db_id}.127.0.0.1.nip.io:8069',
'master_url': 'http://saas.127.0.0.1.nip.io:8069',
})

self.saas_template_operator_1 = self.env['saas.template.operator'].create({
'template_id': self.saas_template_1.id,
'operator_id': self.saas_operator_1.id,
'operator_db_name': DB_TEMPLATE_1,
})

self.saas_template_operator_2 = self.env['saas.template.operator'].create({
'template_id': self.saas_template_2.id,
'operator_id': self.saas_operator_2.id,
'operator_db_name': DB_TEMPLATE_2,
})

def drop_dbs(self, db_list=None):
if not db_list:
db_list = []
db_list += [DB_TEMPLATE_1, DB_TEMPLATE_2, 'template_database']
for i in db_list:
if i in db.list_dbs():
db.exp_drop(i)
@@ -1,33 +1,20 @@
# Copyright 2018-2019 Denis Mudarisov <https://it-projects.info/team/trojikman>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from .common_saas_test import Common, DB_TEMPLATE_1, DB_TEMPLATE_2, MODULE_TO_INSTALL, TEMPLATE_TEST_SUBJECT, \
BUILD_TEST_SUBJECT

import odoo
from odoo import SUPERUSER_ID
from odoo.tests.common import tagged, SavepointCase
from odoo.service import db

DB_TEMPLATE_1 = 'db_template_1'
DB_TEMPLATE_2 = 'db_template_2'
DB_INSTANCE_1 = 'db_instance_1'
DB_INSTANCE_2 = 'db_instance_2'
MODULE_TO_INSTALL = 'mail'
TEMPLATE_TEST_SUBJECT = 'Dummy subject name to test that code is applied on template database'
BUILD_TEST_SUBJECT = 'Dummy subject name to test that code is applied on build database'
DEFAULT_BUILD_PYTHON_CODE = """# Available variables:
# - env: Odoo Environment on which the action is triggered
# - time, datetime, dateutil, timezone: useful Python libraries
# - log: log(message, level='info'): logging function to record debug information in ir.logging table
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {{...}}
# You can specify places for variables that can be passed when creating a build like this:
# env['{key_name_1}'].create({{'subject': '{key_name_2}', }})
# When you need curly braces in build post init code use doubling for escaping\n\n\n\n"""
KEY_VALUES = {'mail_message': 'mail.message'}


@tagged('post_install', 'at_install')
class TestSaas(SavepointCase):
class TestSaas(SavepointCase, Common):

def assert_modules_is_installed(self, db_name, module):
db = odoo.sql_db.db_connect(db_name)
@@ -56,58 +43,10 @@ def assert_no_error_in_db(self, dbname):
@classmethod
def setUpClass(cls):
super(TestSaas, cls).setUpClass()
cls.env = cls.env(context=dict(
cls.env.context,
test_queue_job_no_delay=True,
))

cls.saas_template_1 = cls.env['saas.template'].create({
'template_module_ids': [(0, 0, {
'name': MODULE_TO_INSTALL,
})],
'template_post_init': 'env[\'mail.message\'].create({\'subject\': \'' + TEMPLATE_TEST_SUBJECT + '\', })',
'build_post_init': DEFAULT_BUILD_PYTHON_CODE + 'env[\'{mail_message}\'].create({{\'subject\': \'' + BUILD_TEST_SUBJECT + '\', }})',
})

cls.saas_template_2 = cls.env['saas.template'].create({
'template_module_ids': [(0, 0, {
'name': 'mail',
})],
'template_post_init': 'env[\'mail.message\'].create({\'subject\': \'' + TEMPLATE_TEST_SUBJECT + '\', })',
})

cls.saas_operator_1 = cls.env['saas.operator'].create({
'type': 'local',
'db_url_template': 'http://{db_name}.{db_id}.127.0.0.1.nip.io:8069',
'master_url': 'http://saas.127.0.0.1.nip.io:8069',
})

cls.saas_operator_2 = cls.env['saas.operator'].create({
'type': 'local',
'db_url_template': 'http://{db_name}.{db_id}.127.0.0.1.nip.io:8069',
'master_url': 'http://saas.127.0.0.1.nip.io:8069',
})

cls.saas_template_operator_1 = cls.env['saas.template.operator'].create({
'template_id': cls.saas_template_1.id,
'operator_id': cls.saas_operator_1.id,
'operator_db_name': DB_TEMPLATE_1,
})

cls.saas_template_operator_2 = cls.env['saas.template.operator'].create({
'template_id': cls.saas_template_2.id,
'operator_id': cls.saas_operator_2.id,
'operator_db_name': DB_TEMPLATE_2,
})
cls.setup_saas_env(cls)

def test_template_operator(self):
# FIXME: that check needed when last tests didn't pass, not sure that it is correct way to drop db
if DB_TEMPLATE_1 in db.list_dbs():
db.exp_drop(DB_TEMPLATE_1)
if DB_TEMPLATE_2 in db.list_dbs():
db.exp_drop(DB_TEMPLATE_2)
if 'template_database' in db.list_dbs():
db.exp_drop('template_database')
self.drop_dbs([DB_INSTANCE_1, DB_INSTANCE_2])
self.env['saas.template.operator'].preparing_template_next()

# Tests that template db created correctly
@@ -136,11 +75,6 @@ def test_template_operator(self):
self.assert_record_is_created(DB_TEMPLATE_2, 'mail.message', [('subject', '=', TEMPLATE_TEST_SUBJECT)])

# Check that database instance created correctly
if DB_INSTANCE_1 in db.list_dbs():
db.exp_drop(DB_INSTANCE_1)
if DB_INSTANCE_2 in db.list_dbs():
db.exp_drop(DB_INSTANCE_2)

self.saas_template_operator_1.create_db(KEY_VALUES, DB_INSTANCE_1)
self.assertIn(DB_INSTANCE_1, db.list_dbs())
self.assert_no_error_in_db(DB_INSTANCE_1)
@@ -0,0 +1,40 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

===============
SaaS Public
===============

Create builds for non-authenticated users:

* User opens a link and gets a build

Credits
=======

Contributors
------------
* `Denis Mudarisov <https://it-projects.info/team/trojikman>`__

Sponsors
--------
* `IT-Projects LLC <https://it-projects.info>`__

Maintainers
-----------
* `IT-Projects LLC <https://it-projects.info>`__


Further information
===================

Demo: http://runbot.it-projects.info/demo/saas-addons/12.0

Usage instructions: `<doc/index.rst>`_

Changelog: `<doc/changelog.rst>`_

Notifications on updates: `via Atom <https://github.com/it-projects-llc/saas-addons/commits/12.0/saas_public.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/it-projects-llc/saas-addons/commits/12.0/saas_public.atom>`_

Tested on Odoo 12.0 4b22f1ff5e7c350fa37459c106f52305e26f2ec9
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import controllers, models
@@ -0,0 +1,41 @@
# Copyright 2019 Denis Mudarisov <https://it-projects.info/team/trojikman>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": """SaaS Public""",
"summary": """Module for creating public builds""",
"category": "SaaS",
"images": [],
"version": "12.0.1.0.0",
"application": False,

"author": "IT-Projects LLC, Denis Mudarisov",
"support": "apps@it-projects.info",
"website": "https://it-projects.info/team/trojikman",
"license": "AGPL-3",
# "price": 9.00,
# "currency": "EUR",

"depends": [
"saas",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
"views/saas_template_operator_views.xml",
],
"demo": [
"demo/public_saas_template_demo.xml",
],
"auto_install": False,
"installable": True,

# "demo_title": "{MODULE_NAME}",
# "demo_addons": [
# ],
# "demo_addons_hidden": [
# ],
# "demo_url": "DEMO-URL",
# "demo_summary": "{SHORT_DESCRIPTION_OF_THE_MODULE}",
# "demo_images": [
# "images/MAIN_IMAGE",
# ]
}
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import saas_public
@@ -0,0 +1,19 @@
# Copyright 2019 Denis Mudarisov <https://it-projects.info/team/trojikman>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.http import route, request, Controller


class SaaSPublicController(Controller):
@route('/saas_public/<model("saas.template"):template_id>/create-fast-build', type='http', auth='public')
def create_fast_build(self, template_id, **kwargs):
if not kwargs:
kwargs = {}
if template_id and template_id.sudo().public_access:
template_operator_id = template_id.sudo().operator_ids.random_ready_operator()
build = template_operator_id.sudo().create_db(kwargs, with_delay=False)
build_url = build.get_url()
return request.env['auth_quick_master.token'].sudo().redirect_with_token(build_url, build.id,
build_login='admin')
else:
return request.not_found()
@@ -0,0 +1,7 @@
<!-- Copyright 2019 Denis Mudarisov <https://it-projects.info/team/trojikman>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).-->
<odoo>
<record id="saas.saas_template" model="saas.template">
<field name="public_access" eval="True"/>
</record>
</odoo>
@@ -0,0 +1,4 @@
`1.0.0`
-------

- **Init version**
@@ -0,0 +1,25 @@
===============
SaaS Public
===============

Installation
============

* Follow the insallation instruction of `SaaS Base <https://github.com/it-projects-llc/saas-addons/blob/12.0/saas/doc/index.rst>`__ module
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way

Configuration
=============

* Open menu ``[[ SaaS ]] >> Templates``
* Open your template or create new for which you need to create a build
* Set **[x] Public Access**
* RESULT: Now you can create public builds on the template

Usage
=====

* Open menu ``[[ SaaS ]] >> Templates``
* Choose or create Template that has Template's deployment(s) with public access
* Open link `yourdomain.example/saas_public/*template_id*/create-fast-build` in browser either as logged in or logged out user. Instead of *template_id*, insert template id with public access
* RESULT: You will be redirected to the newly created build
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import saas_template
@@ -0,0 +1,10 @@
# Copyright 2019 Denis Mudarisov <https://it-projects.info/team/trojikman>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models, fields


class SAASTemplate(models.Model):
_inherit = 'saas.template'

public_access = fields.Boolean(default=False)
Binary file not shown.
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_saas_public

0 comments on commit 6ff5fa2

Please sign in to comment.
You can’t perform that action at this time.