parent
c39e302253
commit
33b5d4aba8
16
__init__.py
16
__init__.py
|
@ -2,19 +2,21 @@
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
|
|
||||||
from .party import *
|
from .party import Address, Party, ContactMechanism, NereidUser, Permission, \
|
||||||
from .routing import *
|
UserPermission
|
||||||
from .static_file import *
|
from .routing import URLMap, WebSite, URLRule, URLRuleDefaults, \
|
||||||
from .currency import *
|
WebsiteCountry, WebsiteCurrency
|
||||||
from .template import *
|
from .static_file import NereidStaticFolder, NereidStaticFile
|
||||||
|
from .currency import Currency, Language
|
||||||
|
from .template import ContextProcessors
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
Pool.register(
|
Pool.register(
|
||||||
Address,
|
Address,
|
||||||
Party,
|
Party,
|
||||||
NereidUser,
|
|
||||||
ContactMechanism,
|
ContactMechanism,
|
||||||
|
NereidUser,
|
||||||
Permission,
|
Permission,
|
||||||
UserPermission,
|
UserPermission,
|
||||||
URLMap,
|
URLMap,
|
||||||
|
@ -25,8 +27,8 @@ def register():
|
||||||
WebsiteCurrency,
|
WebsiteCurrency,
|
||||||
NereidStaticFolder,
|
NereidStaticFolder,
|
||||||
NereidStaticFile,
|
NereidStaticFile,
|
||||||
|
Language,
|
||||||
Currency,
|
Currency,
|
||||||
ContextProcessors,
|
ContextProcessors,
|
||||||
Language,
|
|
||||||
module='nereid', type_='model'
|
module='nereid', type_='model'
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from nereid import request
|
||||||
|
|
||||||
__all__ = ['Currency', 'Language']
|
__all__ = ['Currency', 'Language']
|
||||||
|
|
||||||
|
|
||||||
class Currency(ModelSQL, ModelView):
|
class Currency(ModelSQL, ModelView):
|
||||||
'''Currency Manipulation for core.'''
|
'''Currency Manipulation for core.'''
|
||||||
__name__ = 'currency.currency'
|
__name__ = 'currency.currency'
|
||||||
|
|
1
i18n.py
1
i18n.py
|
@ -70,6 +70,7 @@ def ngettext(singular, plural, n, **variables):
|
||||||
return (plural if n > 1 else singular) % variables
|
return (plural if n > 1 else singular) % variables
|
||||||
return t.ungettext(singular, plural, n) % variables
|
return t.ungettext(singular, plural, n) % variables
|
||||||
|
|
||||||
|
|
||||||
def make_lazy_gettext(lookup_func):
|
def make_lazy_gettext(lookup_func):
|
||||||
"""Creates a lazy gettext function dispatches to a gettext
|
"""Creates a lazy gettext function dispatches to a gettext
|
||||||
function as returned by `lookup_func`.
|
function as returned by `lookup_func`.
|
||||||
|
|
110
party.py
110
party.py
|
@ -43,7 +43,7 @@ class RegistrationForm(Form):
|
||||||
"""
|
"""
|
||||||
return get_translations()
|
return get_translations()
|
||||||
|
|
||||||
name = TextField(_('Name'), [validators.Required(),])
|
name = TextField(_('Name'), [validators.Required(), ])
|
||||||
email = TextField(_('e-mail'), [validators.Required(), validators.Email()])
|
email = TextField(_('e-mail'), [validators.Required(), validators.Email()])
|
||||||
password = PasswordField(_('New Password'), [
|
password = PasswordField(_('New Password'), [
|
||||||
validators.Required(),
|
validators.Required(),
|
||||||
|
@ -68,12 +68,12 @@ class AddressForm(Form):
|
||||||
"""
|
"""
|
||||||
return get_translations()
|
return get_translations()
|
||||||
|
|
||||||
name = TextField(_('Name'), [validators.Required(),])
|
name = TextField(_('Name'), [validators.Required(), ])
|
||||||
street = TextField(_('Street'), [validators.Required(),])
|
street = TextField(_('Street'), [validators.Required(), ])
|
||||||
streetbis = TextField(_('Street (Bis)'))
|
streetbis = TextField(_('Street (Bis)'))
|
||||||
zip = TextField(_('Post Code'), [validators.Required(),])
|
zip = TextField(_('Post Code'), [validators.Required(), ])
|
||||||
city = TextField(_('City'), [validators.Required(),])
|
city = TextField(_('City'), [validators.Required(), ])
|
||||||
country = SelectField(_('Country'), [validators.Required(),], coerce=int)
|
country = SelectField(_('Country'), [validators.Required(), ], coerce=int)
|
||||||
subdivision = IntegerField(_('State/County'), [validators.Required()])
|
subdivision = IntegerField(_('State/County'), [validators.Required()])
|
||||||
email = TextField(_('Email'))
|
email = TextField(_('Email'))
|
||||||
phone = TextField(_('Phone'))
|
phone = TextField(_('Phone'))
|
||||||
|
@ -192,7 +192,6 @@ class Address(ModelSQL, ModelView):
|
||||||
return render_template('address.jinja')
|
return render_template('address.jinja')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Party(ModelSQL, ModelView):
|
class Party(ModelSQL, ModelView):
|
||||||
"Party"
|
"Party"
|
||||||
__name__ = 'party.party'
|
__name__ = 'party.party'
|
||||||
|
@ -202,14 +201,17 @@ class Party(ModelSQL, ModelView):
|
||||||
|
|
||||||
class ProfileForm(Form):
|
class ProfileForm(Form):
|
||||||
"""User Profile Form"""
|
"""User Profile Form"""
|
||||||
display_name = TextField('Display Name', [validators.Required(),],
|
display_name = TextField(
|
||||||
|
'Display Name', [validators.Required(), ],
|
||||||
description="Your display name"
|
description="Your display name"
|
||||||
)
|
)
|
||||||
timezone = SelectField('Timezone',
|
timezone = SelectField(
|
||||||
choices = [(tz, tz) for tz in pytz.common_timezones],
|
'Timezone',
|
||||||
|
choices=[(tz, tz) for tz in pytz.common_timezones],
|
||||||
coerce=unicode, description="Your timezone"
|
coerce=unicode, description="Your timezone"
|
||||||
)
|
)
|
||||||
email = TextField('Email', [validators.Required(), validators.Email()],
|
email = TextField(
|
||||||
|
'Email', [validators.Required(), validators.Email()],
|
||||||
description="Your Login Email. This Cannot be edited."
|
description="Your Login Email. This Cannot be edited."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -221,8 +223,10 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
__name__ = "nereid.user"
|
__name__ = "nereid.user"
|
||||||
_rec_name = 'display_name'
|
_rec_name = 'display_name'
|
||||||
|
|
||||||
party = fields.Many2One('party.party', 'Party', required=True,
|
party = fields.Many2One(
|
||||||
ondelete='CASCADE', select=1)
|
'party.party', 'Party', required=True,
|
||||||
|
ondelete='CASCADE', select=1
|
||||||
|
)
|
||||||
|
|
||||||
display_name = fields.Char('Display Name', required=True)
|
display_name = fields.Char('Display Name', required=True)
|
||||||
|
|
||||||
|
@ -254,8 +258,10 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
[(x, x) for x in pytz.common_timezones], 'Timezone', translate=False
|
[(x, x) for x in pytz.common_timezones], 'Timezone', translate=False
|
||||||
)
|
)
|
||||||
|
|
||||||
permissions = fields.Many2Many('nereid.permission-nereid.user',
|
permissions = fields.Many2Many(
|
||||||
'nereid_user', 'permission', 'Permissions')
|
'nereid.permission-nereid.user',
|
||||||
|
'nereid_user', 'permission', 'Permissions'
|
||||||
|
)
|
||||||
|
|
||||||
def get_permissions(self):
|
def get_permissions(self):
|
||||||
"""
|
"""
|
||||||
|
@ -265,19 +271,29 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
# everytime.
|
# everytime.
|
||||||
return frozenset([p.value for p in self.permissions])
|
return frozenset([p.value for p in self.permissions])
|
||||||
|
|
||||||
def has_permissions(self, permissions):
|
def has_permissions(self, perm_all=None, perm_any=None):
|
||||||
"""Check if the user has required permissions for access
|
"""Check if the user has all required permissions in perm_all and
|
||||||
|
has any permission from perm_any for access
|
||||||
|
|
||||||
:param permissions: A set/frozenset of permission values/keywords
|
:param perm_all: A set/frozenset of all permission values/keywords.
|
||||||
|
:param perm_any: A set/frozenset of any permission values/keywords.
|
||||||
|
|
||||||
:return: True/False
|
:return: True/False
|
||||||
"""
|
"""
|
||||||
if not isinstance(permissions, (set, frozenset)):
|
if not perm_all and not perm_any:
|
||||||
permissions = frozenset(permissions)
|
# Access allowed if no permission is required
|
||||||
current_user_permissions = self.get_permissions()
|
|
||||||
if permissions.issubset(current_user_permissions):
|
|
||||||
return True
|
return True
|
||||||
|
if not isinstance(perm_all, (set, frozenset)):
|
||||||
|
perm_all = frozenset(perm_all if perm_all else [])
|
||||||
|
if not isinstance(perm_any, (set, frozenset)):
|
||||||
|
perm_any = frozenset(perm_any if perm_any else [])
|
||||||
|
current_user_permissions = self.get_permissions()
|
||||||
|
|
||||||
|
if perm_all and not perm_all.issubset(current_user_permissions):
|
||||||
return False
|
return False
|
||||||
|
if perm_any and not perm_any.intersection(current_user_permissions):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default_timezone():
|
def default_timezone():
|
||||||
|
@ -345,9 +361,11 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
existing = cls.search([
|
existing = cls.search([
|
||||||
('email', '=', request.form['email']),
|
('email', '=', request.form['email']),
|
||||||
('company', '=', request.nereid_website.company.id),
|
('company', '=', request.nereid_website.company.id),
|
||||||
])
|
]
|
||||||
|
)
|
||||||
if existing:
|
if existing:
|
||||||
flash(_('A registration already exists with this email. '
|
flash(_(
|
||||||
|
'A registration already exists with this email. '
|
||||||
'Please contact customer care')
|
'Please contact customer care')
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@ -359,7 +377,8 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
'email': registration_form.email.data,
|
'email': registration_form.email.data,
|
||||||
'password': registration_form.password.data,
|
'password': registration_form.password.data,
|
||||||
'company': request.nereid_website.company.id,
|
'company': request.nereid_website.company.id,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
nereid_user.save()
|
nereid_user.save()
|
||||||
nereid_user.create_act_code()
|
nereid_user.create_act_code()
|
||||||
registration.send(nereid_user)
|
registration.send(nereid_user)
|
||||||
|
@ -381,9 +400,9 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
email_message = render_email(
|
email_message = render_email(
|
||||||
CONFIG['smtp_from'], self.email, _('Account Activation'),
|
CONFIG['smtp_from'], self.email, _('Account Activation'),
|
||||||
text_template = 'emails/activation-text.jinja',
|
text_template='emails/activation-text.jinja',
|
||||||
html_template = 'emails/activation-html.jinja',
|
html_template='emails/activation-html.jinja',
|
||||||
nereid_user = self
|
nereid_user=self
|
||||||
)
|
)
|
||||||
server = get_smtp_server()
|
server = get_smtp_server()
|
||||||
server.sendmail(
|
server.sendmail(
|
||||||
|
@ -451,9 +470,9 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
{'password': form.password.data}
|
{'password': form.password.data}
|
||||||
)
|
)
|
||||||
session.pop('allow_new_password')
|
session.pop('allow_new_password')
|
||||||
flash(_('Your password has been successfully changed! '
|
flash(_(
|
||||||
'Please login again')
|
'Your password has been successfully changed! '
|
||||||
)
|
'Please login again'))
|
||||||
session.pop('user')
|
session.pop('user')
|
||||||
return redirect(url_for('nereid.website.login'))
|
return redirect(url_for('nereid.website.login'))
|
||||||
|
|
||||||
|
@ -513,10 +532,12 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
the link, he can change his password.
|
the link, he can change his password.
|
||||||
"""
|
"""
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
user_ids = cls.search([
|
user_ids = cls.search(
|
||||||
|
[
|
||||||
('email', '=', request.form['email']),
|
('email', '=', request.form['email']),
|
||||||
('company', '=', request.nereid_website.company.id),
|
('company', '=', request.nereid_website.company.id),
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
if not user_ids or not request.form['email']:
|
if not user_ids or not request.form['email']:
|
||||||
flash(_('Invalid email address'))
|
flash(_('Invalid email address'))
|
||||||
|
@ -540,9 +561,9 @@ class NereidUser(ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
email_message = render_email(
|
email_message = render_email(
|
||||||
CONFIG['smtp_from'], self.email, _('Account Password Reset'),
|
CONFIG['smtp_from'], self.email, _('Account Password Reset'),
|
||||||
text_template = 'emails/reset-text.jinja',
|
text_template='emails/reset-text.jinja',
|
||||||
html_template = 'emails/reset-html.jinja',
|
html_template='emails/reset-html.jinja',
|
||||||
nereid_user = self
|
nereid_user=self
|
||||||
)
|
)
|
||||||
server = get_smtp_server()
|
server = get_smtp_server()
|
||||||
server.sendmail(
|
server.sendmail(
|
||||||
|
@ -804,14 +825,14 @@ class ContactMechanism(ModelSQL, ModelView):
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Permission(ModelSQL, ModelView):
|
class Permission(ModelSQL, ModelView):
|
||||||
"Nereid Permissions"
|
"Nereid Permissions"
|
||||||
__name__ = 'nereid.permission'
|
__name__ = 'nereid.permission'
|
||||||
|
|
||||||
name = fields.Char('Name', required=True, select=True)
|
name = fields.Char('Name', required=True, select=True)
|
||||||
value = fields.Char('Value', required=True, select=True)
|
value = fields.Char('Value', required=True, select=True)
|
||||||
nereid_users = fields.Many2Many('nereid.permission-nereid.user',
|
nereid_users = fields.Many2Many(
|
||||||
|
'nereid.permission-nereid.user',
|
||||||
'permission', 'nereid_user', 'Nereid Users'
|
'permission', 'nereid_user', 'Nereid Users'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -824,12 +845,15 @@ class Permission(ModelSQL, ModelView):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserPermission(ModelSQL):
|
class UserPermission(ModelSQL):
|
||||||
"Nereid User Permissions"
|
"Nereid User Permissions"
|
||||||
__name__ = 'nereid.permission-nereid.user'
|
__name__ = 'nereid.permission-nereid.user'
|
||||||
|
|
||||||
permission = fields.Many2One('nereid.permission', 'Permission',
|
permission = fields.Many2One(
|
||||||
ondelete='CASCADE', select=True, required=True)
|
'nereid.permission', 'Permission',
|
||||||
nereid_user = fields.Many2One('nereid.user', 'User',
|
ondelete='CASCADE', select=True, required=True
|
||||||
ondelete='CASCADE', select=True, required=True)
|
)
|
||||||
|
nereid_user = fields.Many2One(
|
||||||
|
'nereid.user', 'User',
|
||||||
|
ondelete='CASCADE', select=True, required=True
|
||||||
|
)
|
||||||
|
|
32
routing.py
32
routing.py
|
@ -1,6 +1,5 @@
|
||||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
from ast import literal_eval
|
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
from werkzeug import abort, redirect
|
from werkzeug import abort, redirect
|
||||||
|
@ -11,7 +10,6 @@ from nereid.globals import session, request
|
||||||
from nereid.helpers import login_required, key_from_list, get_flashed_messages
|
from nereid.helpers import login_required, key_from_list, get_flashed_messages
|
||||||
from nereid.signals import login, failed_login, logout
|
from nereid.signals import login, failed_login, logout
|
||||||
from trytond.model import ModelView, ModelSQL, fields
|
from trytond.model import ModelView, ModelSQL, fields
|
||||||
from trytond.backend import TableHandler
|
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
|
|
||||||
|
@ -78,7 +76,7 @@ class URLMap(ModelSQL, ModelView):
|
||||||
for URL Rule construction. A wrapper around the
|
for URL Rule construction. A wrapper around the
|
||||||
URL RULE get_rule_arguments
|
URL RULE get_rule_arguments
|
||||||
"""
|
"""
|
||||||
rule_args = [ ]
|
rule_args = []
|
||||||
for rule in self.rules:
|
for rule in self.rules:
|
||||||
rule_args.append(rule.get_rule_arguments())
|
rule_args.append(rule.get_rule_arguments())
|
||||||
return rule_args
|
return rule_args
|
||||||
|
@ -135,8 +133,10 @@ class WebSite(ModelSQL, ModelView):
|
||||||
'website', 'currency', 'Currencies Available')
|
'website', 'currency', 'Currencies Available')
|
||||||
|
|
||||||
#: Default language
|
#: Default language
|
||||||
default_language = fields.Many2One('ir.lang', 'Default Language',
|
default_language = fields.Many2One(
|
||||||
required=True)
|
'ir.lang', 'Default Language',
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
|
||||||
#: The res.user with which the nereid application will be loaded
|
#: The res.user with which the nereid application will be loaded
|
||||||
#: .. versionadded: 0.3
|
#: .. versionadded: 0.3
|
||||||
|
@ -172,8 +172,8 @@ class WebSite(ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
Return the list of countries in JSON
|
Return the list of countries in JSON
|
||||||
"""
|
"""
|
||||||
return jsonify(result = [
|
return jsonify(result=[
|
||||||
{'key': c.id, 'value': c.name} \
|
{'key': c.id, 'value': c.name}
|
||||||
for c in request.nereid_website.countries
|
for c in request.nereid_website.countries
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ class WebSite(ModelSQL, ModelView):
|
||||||
Subdivision = Pool().get('country.subdivision')
|
Subdivision = Pool().get('country.subdivision')
|
||||||
subdivisions = Subdivision.search([('country', '=', country)])
|
subdivisions = Subdivision.search([('country', '=', country)])
|
||||||
return jsonify(
|
return jsonify(
|
||||||
result = [{
|
result=[{
|
||||||
'id': s.id,
|
'id': s.id,
|
||||||
'name': s.name,
|
'name': s.name,
|
||||||
'code': s.code,
|
'code': s.code,
|
||||||
|
@ -285,8 +285,8 @@ class WebSite(ModelSQL, ModelView):
|
||||||
data into the context
|
data into the context
|
||||||
"""
|
"""
|
||||||
return dict(
|
return dict(
|
||||||
user = request.nereid_user,
|
user=request.nereid_user,
|
||||||
party = request.nereid_user.party,
|
party=request.nereid_user.party,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -314,8 +314,9 @@ class WebSite(ModelSQL, ModelView):
|
||||||
'id': c.id,
|
'id': c.id,
|
||||||
'name': c.name,
|
'name': c.name,
|
||||||
'symbol': c.symbol,
|
'symbol': c.symbol,
|
||||||
} for c in self.currencies]
|
} for c in self.currencies
|
||||||
cache.set(cache_key, rv, 60*60)
|
]
|
||||||
|
cache.set(cache_key, rv, 60 * 60)
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -346,7 +347,6 @@ class WebSite(ModelSQL, ModelView):
|
||||||
return jsonify(status=cls._user_status())
|
return jsonify(status=cls._user_status())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class URLRule(ModelSQL, ModelView):
|
class URLRule(ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
URL Rule
|
URL Rule
|
||||||
|
@ -472,8 +472,10 @@ class URLRuleDefaults(ModelSQL, ModelView):
|
||||||
|
|
||||||
key = fields.Char('Key', required=True, select=True)
|
key = fields.Char('Key', required=True, select=True)
|
||||||
value = fields.Char('Value', required=True, select=True)
|
value = fields.Char('Value', required=True, select=True)
|
||||||
rule = fields.Many2One('nereid.url_rule', 'Rule', required=True,
|
rule = fields.Many2One(
|
||||||
select=True)
|
'nereid.url_rule', 'Rule', required=True,
|
||||||
|
select=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class WebsiteCountry(ModelSQL):
|
class WebsiteCountry(ModelSQL):
|
||||||
|
|
|
@ -91,8 +91,9 @@ class NereidStaticFile(ModelSQL, ModelView):
|
||||||
], 'File Type')
|
], 'File Type')
|
||||||
|
|
||||||
#: URL of the remote file if the :attr:`type` is remote
|
#: URL of the remote file if the :attr:`type` is remote
|
||||||
remote_path = fields.Char('Remote File', select=True, translate=True,
|
remote_path = fields.Char(
|
||||||
states = {
|
'Remote File', select=True, translate=True,
|
||||||
|
states={
|
||||||
'required': Equal(Eval('type'), 'remote'),
|
'required': Equal(Eval('type'), 'remote'),
|
||||||
'invisible': Not(Equal(Eval('type'), 'remote'))
|
'invisible': Not(Equal(Eval('type'), 'remote'))
|
||||||
}
|
}
|
||||||
|
|
14
template.py
14
template.py
|
@ -11,11 +11,15 @@ class ContextProcessors(ModelSQL, ModelView):
|
||||||
__name__ = 'nereid.template.context_processor'
|
__name__ = 'nereid.template.context_processor'
|
||||||
_rec_name = 'method'
|
_rec_name = 'method'
|
||||||
|
|
||||||
method = fields.Char('Method', required=True,
|
method = fields.Char(
|
||||||
help="Context processor method in <model>.<method>")
|
'Method', required=True,
|
||||||
model = fields.Char('Model',
|
help="Context processor method in <model>.<method>"
|
||||||
|
)
|
||||||
|
model = fields.Char(
|
||||||
|
'Model',
|
||||||
help="This will restrict the loading when URLs with"
|
help="This will restrict the loading when URLs with"
|
||||||
" the model are called")
|
" the model are called"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_processors(cls):
|
def get_processors(cls):
|
||||||
|
@ -23,7 +27,7 @@ class ContextProcessors(ModelSQL, ModelView):
|
||||||
Return the list of processors. Separate function
|
Return the list of processors. Separate function
|
||||||
since its important to have caching on this
|
since its important to have caching on this
|
||||||
"""
|
"""
|
||||||
result = { }
|
result = {}
|
||||||
ctx_processors = cls.search([])
|
ctx_processors = cls.search([])
|
||||||
for ctx_proc in ctx_processors:
|
for ctx_proc in ctx_processors:
|
||||||
model, method = ctx_proc.method.rsplit('.', 1)
|
model, method = ctx_proc.method.rsplit('.', 1)
|
||||||
|
|
|
@ -36,7 +36,6 @@ class TestNereid(unittest.TestCase):
|
||||||
test_depends()
|
test_depends()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
test_suite = trytond.tests.test_tryton.suite()
|
test_suite = trytond.tests.test_tryton.suite()
|
||||||
test_suite.addTests(
|
test_suite.addTests(
|
||||||
|
|
|
@ -166,8 +166,7 @@ class TestAddress(NereidTestCase):
|
||||||
'phone': '1234567890',
|
'phone': '1234567890',
|
||||||
'country': self.available_countries[0].id,
|
'country': self.available_countries[0].id,
|
||||||
'subdivision': self.country_obj(
|
'subdivision': self.country_obj(
|
||||||
self.available_countries[0]
|
self.available_countries[0]).subdivisions[0].id,
|
||||||
).subdivisions[0].id,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
with app.test_client() as c:
|
with app.test_client() as c:
|
||||||
|
|
|
@ -306,7 +306,8 @@ class TestAuth(NereidTestCase):
|
||||||
})
|
})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
"The current password you entered is invalid" in response.data
|
"The current password you entered is invalid"
|
||||||
|
in response.data
|
||||||
)
|
)
|
||||||
|
|
||||||
response = c.post('/en_US/change-password', data={
|
response = c.post('/en_US/change-password', data={
|
||||||
|
@ -318,7 +319,8 @@ class TestAuth(NereidTestCase):
|
||||||
response = c.get('/en_US')
|
response = c.get('/en_US')
|
||||||
|
|
||||||
# Login now using new password
|
# Login now using new password
|
||||||
response = c.post('/en_US/login',
|
response = c.post(
|
||||||
|
'/en_US/login',
|
||||||
data={
|
data={
|
||||||
'email': data['email'],
|
'email': data['email'],
|
||||||
'password': 'new-password'
|
'password': 'new-password'
|
||||||
|
@ -397,7 +399,8 @@ class TestAuth(NereidTestCase):
|
||||||
regd_user = self.nereid_user_obj(regd_user.id)
|
regd_user = self.nereid_user_obj(regd_user.id)
|
||||||
self.assertFalse(regd_user.activation_code)
|
self.assertFalse(regd_user.activation_code)
|
||||||
|
|
||||||
response = c.post('/en_US/login',
|
response = c.post(
|
||||||
|
'/en_US/login',
|
||||||
data={
|
data={
|
||||||
'email': data['email'],
|
'email': data['email'],
|
||||||
'password': 'wrong-password'
|
'password': 'wrong-password'
|
||||||
|
@ -405,7 +408,8 @@ class TestAuth(NereidTestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200) # Login rejected
|
self.assertEqual(response.status_code, 200) # Login rejected
|
||||||
|
|
||||||
response = c.post('/en_US/login',
|
response = c.post(
|
||||||
|
'/en_US/login',
|
||||||
data={
|
data={
|
||||||
'email': data['email'],
|
'email': data['email'],
|
||||||
'password': 'reset-password'
|
'password': 'reset-password'
|
||||||
|
@ -509,6 +513,7 @@ class TestAuth(NereidTestCase):
|
||||||
self.nereid_user_obj.write(
|
self.nereid_user_obj.write(
|
||||||
[self.guest_user], {'permissions': [('set', [perm_admin])]}
|
[self.guest_user], {'permissions': [('set', [perm_admin])]}
|
||||||
)
|
)
|
||||||
|
|
||||||
@permissions_required(['admin'])
|
@permissions_required(['admin'])
|
||||||
def test_permission_2():
|
def test_permission_2():
|
||||||
return True
|
return True
|
||||||
|
@ -594,6 +599,67 @@ class TestAuth(NereidTestCase):
|
||||||
response = c.get('/en_US/me')
|
response = c.get('/en_US/me')
|
||||||
self.assertEqual(response.data, 'Regd User')
|
self.assertEqual(response.data, 'Regd User')
|
||||||
|
|
||||||
|
def test_0100_has_permission(self):
|
||||||
|
'''
|
||||||
|
Test the functionality of has_permissions
|
||||||
|
'''
|
||||||
|
with Transaction().start(DB_NAME, USER, CONTEXT):
|
||||||
|
self.setup_defaults()
|
||||||
|
p1, p2, p3, p4 = self.nereid_permission_obj.create([
|
||||||
|
{'name': 'p1', 'value': 'nereid.perm1'},
|
||||||
|
{'name': 'p2', 'value': 'nereid.perm2'},
|
||||||
|
{'name': 'p3', 'value': 'nereid.perm3'},
|
||||||
|
{'name': 'p4', 'value': 'nereid.perm4'},
|
||||||
|
])
|
||||||
|
self.nereid_user_obj.write(
|
||||||
|
[self.guest_user],
|
||||||
|
{
|
||||||
|
'permissions': [
|
||||||
|
('add', [p1, p2])
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# all = [], any = [] = True
|
||||||
|
self.assertTrue(self.guest_user.has_permissions())
|
||||||
|
|
||||||
|
# all = [p1, p2], any = [] == True
|
||||||
|
self.assertTrue(self.guest_user.has_permissions(
|
||||||
|
perm_all=[p1.value, p2.value]
|
||||||
|
))
|
||||||
|
|
||||||
|
# all = [p1, p2], any = [p3, p4] == False
|
||||||
|
self.assertFalse(self.guest_user.has_permissions(
|
||||||
|
perm_all=[p1.value, p2.value],
|
||||||
|
perm_any=[p3.value, p4.value]
|
||||||
|
))
|
||||||
|
|
||||||
|
# all = [p1, p3], any = [] == False
|
||||||
|
self.assertFalse(self.guest_user.has_permissions(
|
||||||
|
perm_all=[p1.value, p3.value],
|
||||||
|
))
|
||||||
|
|
||||||
|
# all = [p1, p3], any = [p1, p3, p4] == False
|
||||||
|
self.assertFalse(self.guest_user.has_permissions(
|
||||||
|
perm_all=[p1.value, p3.value],
|
||||||
|
perm_any=[p1.value, p3.value, p4.value]
|
||||||
|
))
|
||||||
|
|
||||||
|
# all = [p1, p2], any = [p1, p3, p4] == True
|
||||||
|
self.assertTrue(self.guest_user.has_permissions(
|
||||||
|
perm_all=[p1.value, p2.value],
|
||||||
|
perm_any=[p1.value, p3.value, p4.value]
|
||||||
|
))
|
||||||
|
|
||||||
|
# all = [], any = [p1, p2, p3] == True
|
||||||
|
self.assertTrue(self.guest_user.has_permissions(
|
||||||
|
perm_any=[p1.value, p2.value, p3.value]
|
||||||
|
))
|
||||||
|
|
||||||
|
# all = [], any = [p3, p4] == False
|
||||||
|
self.assertFalse(self.guest_user.has_permissions(
|
||||||
|
perm_any=[p3.value, p4.value]
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
|
|
@ -121,7 +121,6 @@ class TestCurrency(NereidTestCase):
|
||||||
self.currency_obj.convert(Decimal('100')), Decimal('100')
|
self.currency_obj.convert(Decimal('100')), Decimal('100')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_0020_currency_from_language(self):
|
def test_0020_currency_from_language(self):
|
||||||
"""
|
"""
|
||||||
Set the currency for the language and check if the currency
|
Set the currency for the language and check if the currency
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[tryton]
|
[tryton]
|
||||||
version=2.8.0.2
|
version=2.8.0.5
|
||||||
depends:
|
depends:
|
||||||
ir
|
ir
|
||||||
res
|
res
|
||||||
|
|
Loading…
Reference in New Issue