mirror of https://github.com/NaN-tic/nereid.git
Define application_user and guest_user in nereid_website (previously was part of the application spec)
This commit is contained in:
parent
ca8ae863dd
commit
f54ce00108
|
@ -0,0 +1,51 @@
|
||||||
|
=================
|
||||||
|
Migration Details
|
||||||
|
=================
|
||||||
|
|
||||||
|
Version 0.3
|
||||||
|
===========
|
||||||
|
|
||||||
|
1. SQL to move party_address to nereid_user
|
||||||
|
-------------------------------------------
|
||||||
|
|
||||||
|
Address which was used for login was migrated to nereid_user. To
|
||||||
|
retain the existing users and their IDs (used in sessions) the
|
||||||
|
users data needs to be migrated from party.address to nereid.user
|
||||||
|
|
||||||
|
SQL::
|
||||||
|
|
||||||
|
INSERT INTO nereid_user
|
||||||
|
SELECT
|
||||||
|
"address"."id" AS id,
|
||||||
|
"address"."create_date" AS create_date,
|
||||||
|
"address"."write_date" AS write_date,
|
||||||
|
"address"."create_uid" AS create_uid,
|
||||||
|
"address"."write_uid" AS write_uid,
|
||||||
|
"party"."company" AS company,
|
||||||
|
"address"."party" AS party,
|
||||||
|
"address"."activation_code" AS activation_code,
|
||||||
|
"address"."salt" AS salt,
|
||||||
|
"contact_mechanism"."value" AS email,
|
||||||
|
"address"."password" AS password
|
||||||
|
FROM party_address AS address
|
||||||
|
JOIN party_party AS party ON party.id = address.party
|
||||||
|
LEFT JOIN party_contact_mechanism AS contact_mechanism ON contact_mechanism.id = address.email
|
||||||
|
WHERE
|
||||||
|
"address"."email" IS NOT NULL
|
||||||
|
AND "address"."password" IS NOT NULL
|
||||||
|
AND "party"."company" IS NOT NULL;
|
||||||
|
|
||||||
|
|
||||||
|
2. Application Settings
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
`TRYTON_USER` and `GUEST_USER` which were application config parameters in
|
||||||
|
previous version are now part of `nereid.website` settings. This avoids
|
||||||
|
looking up IDs of these records from database to then build the app settings.
|
||||||
|
|
||||||
|
This affects two places:
|
||||||
|
|
||||||
|
1. Application settings in launchers: `TRYTON_USER` and `GUEST_USER` needs
|
||||||
|
not be specified anymore.
|
||||||
|
2. Unit Tests: `application_user` (eqv. of `TRYTON_USER`) and `guest_user`
|
||||||
|
are not
|
|
@ -241,7 +241,7 @@ class Nereid(BackendMixin, RoutingMixin,
|
||||||
self._before_request_lock = Lock()
|
self._before_request_lock = Lock()
|
||||||
|
|
||||||
_PackageBoundObject.__init__(self, __name__)
|
_PackageBoundObject.__init__(self, __name__)
|
||||||
BackendMixin.__init__(self, **config)
|
BackendMixin.__init__(self, **config)
|
||||||
RoutingMixin.__init__(self, **config)
|
RoutingMixin.__init__(self, **config)
|
||||||
CacheMixin.__init__(self, **config)
|
CacheMixin.__init__(self, **config)
|
||||||
TemplateMixin.__init__(self, **config)
|
TemplateMixin.__init__(self, **config)
|
||||||
|
|
|
@ -40,6 +40,13 @@ class BackendMixin(object):
|
||||||
#: Configuration file for Tryton
|
#: Configuration file for Tryton
|
||||||
tryton_configfile = ConfigAttribute('TRYTON_CONFIG')
|
tryton_configfile = ConfigAttribute('TRYTON_CONFIG')
|
||||||
database_name = ConfigAttribute('DATABASE_NAME')
|
database_name = ConfigAttribute('DATABASE_NAME')
|
||||||
|
|
||||||
|
#: This attribute was previously used to specify ID of the res.user
|
||||||
|
#: that nereid should be using to connect to Tryton. This attribute
|
||||||
|
#: is now set during the initialisation of the class. If any attribute
|
||||||
|
#: is set in the config settings, they are ignored
|
||||||
|
#:
|
||||||
|
#: ..versionchanged:0.3
|
||||||
tryton_user = ConfigAttribute('TRYTON_USER')
|
tryton_user = ConfigAttribute('TRYTON_USER')
|
||||||
tryton_context = ConfigAttribute('TRYTON_CONTEXT')
|
tryton_context = ConfigAttribute('TRYTON_CONTEXT')
|
||||||
|
|
||||||
|
@ -48,6 +55,26 @@ class BackendMixin(object):
|
||||||
from trytond.config import CONFIG
|
from trytond.config import CONFIG
|
||||||
CONFIG.configfile = self.tryton_configfile
|
CONFIG.configfile = self.tryton_configfile
|
||||||
CONFIG.load()
|
CONFIG.load()
|
||||||
|
with self.root_transaction:
|
||||||
|
website_obj = self.pool.get('nereid.website')
|
||||||
|
user_obj = self.pool.get('res.user')
|
||||||
|
|
||||||
|
# Find the application_user and guest_user
|
||||||
|
website_id, = website_obj.search([
|
||||||
|
('name', '=', self.site)
|
||||||
|
])
|
||||||
|
website = website_obj.browse(website_id)
|
||||||
|
self.tryton_user = website.application_user.id
|
||||||
|
self.guest_user = website.guest_user.id
|
||||||
|
|
||||||
|
# Update the Tryton context
|
||||||
|
if not self.tryton_context:
|
||||||
|
self.tryton_context = {}
|
||||||
|
new_context = user_obj._get_preferences(
|
||||||
|
website.application_user, context_only=True
|
||||||
|
)
|
||||||
|
self.tryton_context.update(new_context)
|
||||||
|
|
||||||
|
|
||||||
def load_connection(self):
|
def load_connection(self):
|
||||||
"Actual loading of connection takes place here"
|
"Actual loading of connection takes place here"
|
||||||
|
@ -81,7 +108,7 @@ class BackendMixin(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def transaction(self):
|
def transaction(self):
|
||||||
"""Allows the use of the transaction as a context manager.
|
"""Allows the use of the transaction as a context manager.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
|
@ -93,6 +120,15 @@ class BackendMixin(object):
|
||||||
return TransactionManager(
|
return TransactionManager(
|
||||||
self.database_name, self.tryton_user, self.tryton_context)
|
self.database_name, self.tryton_user, self.tryton_context)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def root_transaction(self):
|
||||||
|
"""Allows the use of the transaction as a context manager with the
|
||||||
|
root user.
|
||||||
|
|
||||||
|
.. versionadded::0.3
|
||||||
|
"""
|
||||||
|
return TransactionManager(self.database_name, 0, self.tryton_context)
|
||||||
|
|
||||||
def get_method(self, model_method):
|
def get_method(self, model_method):
|
||||||
"""Get the object from pool and fetch the method from it
|
"""Get the object from pool and fetch the method from it
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,9 @@ def create_site(obj, name, url_map=None, company=None, **options):
|
||||||
options['default_language'], = lang_obj.search(
|
options['default_language'], = lang_obj.search(
|
||||||
[('code', '=', 'en_US')])
|
[('code', '=', 'en_US')])
|
||||||
|
|
||||||
|
if 'application_user' not in options:
|
||||||
|
options['application_user'] = 1
|
||||||
|
|
||||||
return site_obj.create(options)
|
return site_obj.create(options)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue