SHA256
1
0
forked from pool/trytond

- Version 4.6.10 - Bugfix Release

- Version 4.6.9 - Bugfix Release
- Version 4.6.8 - Bugfix Release
- Version 4.6.7 - Bugfix Release
- Version 4.6.6 - Bugfix Release
- Version 4.6.5 - Bugfix Release
- trytond_log.conf changed to new notation
- Version 4.6.4 - Bugfix Release
- Version 4.6.3 - Bugfix Release
- Version 4.6.2 - Bugfix Release
- Version 4.6.1 - Bugfix Release
- Version 4.6.0 - initial build

OBS-URL: https://build.opensuse.org/package/show/Application:ERP:GNUHealth:Factory/trytond?expand=0&rev=41
This commit is contained in:
Axel Braun 2018-12-28 14:30:20 +00:00 committed by Git OBS Bridge
parent 8501c80f2a
commit f0291e345b
12 changed files with 132 additions and 788 deletions

View File

@ -1,4 +1,3 @@
<services>
<service name="download_files" mode="localonly"/>
</services>
<service name="download_files"/></services>

View File

@ -0,0 +1,48 @@
diff -ruN a/trytond/res/user.py b/trytond/res/user.py
- --- a/trytond/res/user.py 2018-11-22 09:21:59.077931014 +0000
+++ b/trytond/res/user.py 2018-11-22 09:21:04.423129737 +0000
@@ -20,6 +20,7 @@
from sql.conditionals import Coalesce
from sql.aggregate import Count
from sql.operators import Concat
+from random import randint
try:
import bcrypt
@@ -542,12 +543,15 @@
'''
Return user id if password matches
'''
- - LoginAttempt = Pool().get('res.user.login.attempt')
- - count = LoginAttempt.count(login)
- - if count > config.getint('session', 'max_attempt', default=5):
- - LoginAttempt.add(login)
- - raise RateLimitException()
- - Transaction().atexit(time.sleep, 2 ** count - 1)
+ login_max_delay = config.getint('session', 'login_max_delay')
+
+ #Use a random delay (default between 1 and login_max_delay)
+ #If the param is not set, it defaults to 3
+
+ if (not login_max_delay) or (login_max_delay < 1):
+ login_max_delay = 3
+ delay = randint(1,login_max_delay)
+
for method in config.get(
'session', 'authentications', default='password').split(','):
try:
@@ -557,10 +561,11 @@
continue
user_id = func(login, parameters)
if user_id:
- - LoginAttempt.remove(login)
return user_id
- - LoginAttempt.add(login)
- -
+ else:
+ logger.warning('Invalid login from : %s', login)
+ time.sleep(delay)
+
@classmethod
def _login_password(cls, login, parameters):
if 'password' not in parameters:

View File

@ -55,9 +55,16 @@ Preparing the database
Tryton uses a Relational Database Management System (RDBMS) to store data. The
preferred RDBMS for Tryton is PostgreSQL.
The following steps guide you through the setup:
You have to setup this database manually. Here is a short explanation how to
achieve this.
* Make sure PostgreSQL is running:
We can distinguish two scenarios, to which the following description will reference:
1) the database is created manually (recommended for productive environments)
2) the database shall be created from the Tryton client (recommended for test)
* In both cases, make sure PostgreSQL is running:
> systemctl status postgresql
@ -131,7 +138,7 @@ Now you are ready to connect with a client, e.g. tryton-client.
Creating the database for Tryton
--------------------------------
For manual creation of the database, the following steps are to be performed:
For manual creation of the database, the folowing steps are to be performed:
* Creating the database:
@ -149,9 +156,7 @@ For manual creation of the database, the following steps are to be performed:
> /usr/bin/trytond-admin -c /etc/tryton/trytond.conf --all -d mydb
Note: Use the database name you chose in the previous step (here as default:
mydb). You will be asked for the admin password for this database.
For the first time, log in to the newly initialized database with user 'admin'
and password as set during initialization.
mydb). You will be asked for the admin password for this database. For the first time, log in to the newly initialized database with user admin and password as set during initialization.
As result you will have a bare Tryton database with the base modules installed.
@ -180,7 +185,7 @@ sao bases on nodejs, and it comes as separate package. Download and extract
tryton-sao into a directory, say /srv/tryton-sao
Make sure you have nodejs and git installed:
> zypper install nodejs git phantomjs
> zypper install nodejs git
Now change into to installation directory and install sao:
> cd /srv/tryton-sao/package
@ -251,4 +256,4 @@ Now, you're finished with the system setup. Please be aware of the following thi
This file is based on tryton-server.README.Debian
Copyright: 2009-2012 Daniel Baumann <daniel@debian.org>
2011-2014 Mathias Behrle <mathiasb@m9s.biz>
2011-2014 Mathias Behrle <mathiasb@m9s.biz>

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5b557a397dcf52e5ff3556f583e3c2fe85fb1e7164a4dc9df6826ad425b0d510
size 587423

3
trytond-4.6.10.tar.gz Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c8adac6bc4fae3eb629d7f5e0088a37fe92b4663ea1e4219497fd31d11e8aadc
size 610089

View File

@ -1,215 +1,59 @@
-------------------------------------------------------------------
Mon Dec 10 19:09:03 UTC 2018 - Axel Braun <axel.braun@gmx.de>
Mon Dec 10 19:28:20 UTC 2018 - Axel Braun <axel.braun@gmx.de>
- Version 4.2.17 - Bugfix Release
- Version 4.6.10 - Bugfix Release
-------------------------------------------------------------------
Tue Nov 13 15:13:58 UTC 2018 - Axel Braun <axel.braun@gmx.de>
Tue Nov 13 15:06:31 UTC 2018 - Axel Braun <axel.braun@gmx.de>
- Version 4.2.16 - Bugfix Release
- Version 4.6.9 - Bugfix Release
-------------------------------------------------------------------
Wed Aug 22 13:03:07 UTC 2018 - axel.braun@gmx.de
Wed Aug 22 12:55:01 UTC 2018 - axel.braun@gmx.de
- Version 4.2.15 - Bugfix Release (boo#1107771)
- Version 4.6.8 - Bugfix Release
-------------------------------------------------------------------
Sat Aug 4 07:28:52 UTC 2018 - axel.braun@gmx.de
Sat Aug 4 07:52:55 UTC 2018 - axel.braun@gmx.de
- Version 4.2.14 - Bugfix Release
- Version 4.6.7 - Bugfix Release
-------------------------------------------------------------------
Thu Jul 19 15:19:55 UTC 2018 - axel.braun@gmx.de
Wed Jul 11 17:18:38 UTC 2018 - axel.braun@gmx.de
- trytond42_psql10.diff applied for postgres10 compatibility
Kudos to mbehrle@m9s.biz!
- Version 4.6.6 - Bugfix Release
-------------------------------------------------------------------
Wed Jul 11 12:35:03 UTC 2018 - axel.braun@gmx.de
Mon Jun 11 09:13:45 UTC 2018 - axel.braun@gmx.de
- Version 4.2.13 - Bugfix Release
- Version 4.6.5 - Bugfix Release
-------------------------------------------------------------------
Tue Jun 12 19:04:04 UTC 2018 - axel.braun@gmx.de
Thu May 17 19:07:59 UTC 2018 - axel.braun@gmx.de
- boo#1096706 set postgres96 using update-alternatives (openQA failure)
- trytond_log.conf changed to new notation
-------------------------------------------------------------------
Mon Jun 11 09:20:09 UTC 2018 - axel.braun@gmx.de
Sat May 12 13:06:15 UTC 2018 - axel.braun@gmx.de
- Version 4.2.12 - Bugfix Release
boo#1096706 requirement for postgres96 fixed
copyright to log file and readme added
Specfile cleaned up
- Version 4.6.4 - Bugfix Release
-------------------------------------------------------------------
Sat May 12 12:59:31 UTC 2018 - axel.braun@gmx.de
Fri Mar 2 09:08:14 UTC 2018 - axel.braun@gmx.de
- Version 4.2.11 - Bugfix Release
- Version 4.6.3 - Bugfix Release
-------------------------------------------------------------------
Fri Apr 27 18:52:20 UTC 2018 - axel.braun@gmx.de
Fri Jan 5 18:53:08 UTC 2018 - axel.braun@gmx.de
- requires postgres96, otherwise trytond-admin fails (Leap 15)
- Version 4.6.2 - Bugfix Release
-------------------------------------------------------------------
Fri Mar 2 09:11:30 UTC 2018 - axel.braun@gmx.de
Tue Dec 5 19:54:28 UTC 2017 - axel.braun@gmx.de
- Version 4.2.10 - Bugfix Release
- Version 4.6.1 - Bugfix Release
-------------------------------------------------------------------
Sat Feb 17 06:47:27 UTC 2018 - axel.braun@gmx.de
Sun Oct 29 19:58:45 UTC 2017 - axel.braun@gmx.de
- user_login.patch replaced by trytond_get_login.patch
see boo#1078111
-------------------------------------------------------------------
Fri Jan 5 19:59:52 UTC 2018 - axel.braun@gmx.de
- Version 4.2.9 - Bugfix Release
-------------------------------------------------------------------
Tue Dec 5 20:19:55 UTC 2017 - axel.braun@gmx.de
- Version 4.2.8 - Bugfix Release
-------------------------------------------------------------------
Thu Nov 9 06:05:31 UTC 2017 - axel.braun@gmx.de
- Version 4.2.7 - Bugfix Release
-------------------------------------------------------------------
Thu Sep 14 19:24:19 UTC 2017 - axel.braun@gmx.de
- Documentation updated
-------------------------------------------------------------------
Thu Aug 10 20:04:47 UTC 2017 - axel.braun@gmx.de
- Version 4.2.6
bugfix release
typo in trytond.conf removed
-------------------------------------------------------------------
Mon Jul 10 14:07:26 UTC 2017 - axel.braun@gmx.de
- default setting for database access in trytond.conf
-------------------------------------------------------------------
Mon Jul 3 09:12:15 UTC 2017 - axel.braun@gmx.de
- Version 4.2.5
-------------------------------------------------------------------
Tue Jun 20 16:26:42 UTC 2017 - axel.braun@gmx.de
- Patch for user login user_login.patch from GNU Health 3.20 applied
trytond_server.diff removed as not needed anymore
-------------------------------------------------------------------
Tue Jun 6 07:50:44 UTC 2017 - axel.braun@gmx.de
- Version 4.2.4
-------------------------------------------------------------------
Mon Apr 3 19:36:48 UTC 2017 - axel.braun@gmx.de
- Version 4.2.3
-------------------------------------------------------------------
Fri Mar 10 10:24:56 UTC 2017 - axel.braun@gmx.de
- Version 4.2.2
-------------------------------------------------------------------
Fri Jan 6 15:27:55 UTC 2017 - axel.braun@gmx.de
- Version 4.2.1
-------------------------------------------------------------------
Mon Nov 28 18:22:41 UTC 2016 - axel.braun@gmx.de
- Tryton Release 4.2
-------------------------------------------------------------------
Wed Aug 24 13:52:32 UTC 2016 - axel.braun@gmx.de
- Update description
- Add missing %service_add_pre and convert open-coded other
three scriptlets to %service_*.
-------------------------------------------------------------------
Tue Jul 5 09:46:31 UTC 2016 - axel.braun@gmx.de
- version 4.0.2
-------------------------------------------------------------------
Tue May 02 10:24:48 UTC 2016 - axel.braun@gmx.de
- Tryton Release 4.0
-------------------------------------------------------------------
Mon Mar 28 11:58:39 UTC 2016 - axel.braun@gmx.de
- patch for security vulnerability applied, see
https://savannah.gnu.org/forum/forum.php?forum_id=8482
-------------------------------------------------------------------
Sun Jan 17 12:48:36 UTC 2016 - axel.braun@gmx.de
- Installation of sao (webfrontend) documented
-------------------------------------------------------------------
Wed Oct 19 20:14:38 UTC 2015 - axel.braun@gmx.de
- Tryton Release 3.8
-------------------------------------------------------------------
Wed May 27 08:27:18 UTC 2015 - axel.braun@gmx.de
- version 3.6.1
* clean up of specfile
-------------------------------------------------------------------
Wed Apr 15 07:24:15 UTC 2015 - axel.braun@gmx.de
- Tryton Release 3.6
-------------------------------------------------------------------
Sat Feb 28 11:48:03 UTC 2015 - axel.braun@gmx.de
- sample file for confirguration added (trytond.conf.example)
tryton-server.README.SUSE updated
-------------------------------------------------------------------
Fri Nov 14 15:52:52 UTC 2014 - axel.braun@gmx.de
- systemd startup file corrected, sample file for log config added
-------------------------------------------------------------------
Tue Nov 4 10:24:39 UTC 2014 - axel.braun@gmx.de
- added trytond.conf
-------------------------------------------------------------------
Sun Nov 2 20:38:21 UTC 2014 - axel.braun@gmx.de
- version 3.4
-------------------------------------------------------------------
Wed Oct 23 14:59:59 UTC 2013 - axel.braun@gmx.de
- new branch 3.0, added python-sql
-------------------------------------------------------------------
Tue Oct 22 18:01:29 UTC 2013 - axel.braun@gmx.de
- Tryton 3.0, spec file adapted
* Sat Jun 22 2013 axel.braun@gmx.de
- new spec with regard to systemd
- setup of user tryton if not existing
* Sun Mar 29 2009 axel.braun@gmx.de
- packaged tryton version 1.0.3 using the buildservice spec file wizard
- Version 4.6.0 - initial build

View File

@ -20,14 +20,14 @@
uri = postgresql:///
#
#
# PostgreSQL via TCP/IP
# (e.g. connecting to a PostgreSQL database running on a remote machine or
# by means of md5 authentication. Needs PostgreSQL to be configured to accept
# those connections (pg_hba.conf).)
#
#uri = postgresql://tryton:tryton@localhost:5432/
#
# The path to the directory where the Tryton Server stores files.
# The server must have write permissions to this directory.
# (Internal default: /var/lib/trytond)
@ -84,7 +84,7 @@ listen = [::]:8000
# Settings for the WebDAV network interface
# The IP/host and port number of the interface
listen = localhost:8080
#listen = localhost:8080
[session]
# Session settings
@ -92,16 +92,6 @@ listen = localhost:8080
# The time (in seconds) until an inactive session expires
#timeout = 3600
# The server administration password used by the client for
# the execution of database management tasks. It is encrypted
# using using the Unix crypt(3) routine. A password can be
# generated using the following command line (on one line):
# $ python -c 'import getpass,crypt,random,string; \
# print crypt.crypt(getpass.getpass(), \
# "".join(random.sample(string.ascii_letters + string.digits, 8)))'
# Example password with 'admin'
#super_pwd = jkUbZGvFNeugk
[email]
# Mail settings
@ -135,4 +125,4 @@ listen = localhost:8080
[web]
# Path for the web-frontend
#root = /usr/lib/node_modules/tryton-sao
#root = /usr/lib/node-modules/tryton-sao

View File

@ -15,13 +15,17 @@
# PostgreSQL via Unix domain sockets
# (e.g. PostgreSQL database running on the same machine (localhost))
#uri = postgresql://tryton:tryton@/
#
#Default setting for a local postgres database
uri = postgresql:///
#
# PostgreSQL via TCP/IP
# (e.g. connecting to a PostgreSQL database running on a remote machine or
# by means of md5 authentication. Needs PostgreSQL to be configured to accept
# those connections (pg_hba.conf).)
uri = postgresql://tryton:tryton@localhost:5432/
#uri = postgresql://tryton:tryton@localhost:5432/
# The path to the directory where the Tryton Server stores files.
# The server must have write permissions to this directory.
@ -132,4 +136,4 @@ super_pwd = jkUbZGvFNeugk
[web]
# Path for the web-frontend
#root = /usr/lib/node_modules/tryton-sao
#root = /usr/lib/node-modules/tryton-sao

View File

@ -2,7 +2,7 @@
# spec file for package trytond
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2015 - 2018 Dr. Axel Braun
# Copyright (c) 2015-2018 Dr. Axel Braun
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -17,10 +17,10 @@
#
%define majorver 4.2
%define majorver 4.6
%define base_name tryton
Name: trytond
Version: %{majorver}.17
Version: %{majorver}.10
Release: 0
Summary: An Enterprise Resource Planning (ERP) system
@ -28,28 +28,26 @@ License: GPL-3.0-or-later
Group: Productivity/Office/Management
Url: http://www.tryton.org/
Source0: http://downloads.tryton.org/%{majorver}/%{name}-%{version}.tar.gz
#Patch0: trytond340.patch
Source1: tryton-server.README.SUSE
Source2: trytond.conf.example
Source3: %{name}.conf
Source4: %{name}_log.conf
# GNU Health patch for user login
Patch0: trytond_get_login.patch
Patch1: trytond42_psql10.diff
Source20: %{name}.service
Patch0: get_login_trytond-46.patch
# List of additional build dependencies
BuildRequires: fdupes
BuildRequires: postgresql
BuildRequires: postgresql-server
BuildRequires: python3-Werkzeug
BuildRequires: python3-bcrypt
BuildRequires: python3-lxml
BuildRequires: python3-lxml >= 2.0
BuildRequires: python3-psycopg2
BuildRequires: python3-pydot3
BuildRequires: python3-python-sql
BuildRequires: python3-setuptools
BuildRequires: python3-wrapt
BuildRequires: systemd-rpm-macros
Requires: html2text
Requires: libreoffice-pyuno
Requires: postgresql-server
Requires: python3-Genshi
@ -61,20 +59,16 @@ Requires: python3-dateutil
Requires: python3-lxml
Requires: python3-mock
Requires: python3-polib
Requires: python3-psycopg2
Requires: python3-python-sql
Requires: python3-relatorio
Requires: python3-psycopg2 >= 2.5.4
Requires: python3-python-sql >= 0.4
Requires: python3-relatorio >= 0.7.0
Requires: python3-simpleeval
Requires: python3-wrapt
Requires: unoconv
Requires(pre): /usr/sbin/groupadd
Requires(pre): /usr/sbin/useradd
# Post requires update-alternatives to install tool update-alternatives.
#Requires(post): update-alternatives
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%{?systemd_requires}
%description
@ -88,8 +82,7 @@ security.
%setup -q
cp %{S:1} .
cp %{S:2} .
%patch0 -p0
%patch1 -p1 -F2
%patch0 -p1
%build
python3 setup.py build
@ -105,19 +98,24 @@ mkdir -p $RPM_BUILD_ROOT%{_unitdir}
install -p -m 644 %{SOURCE20} $RPM_BUILD_ROOT%{_unitdir}/%{name}.service
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/{lib,log}/%{base_name}
%fdupes -s %{buildroot}
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%pre
getent group tryton > /dev/null || %{_sbindir}/groupadd -r tryton
#Write GH Variable /etc/tryton/gnuhealthrc
cat > /etc/tryton/gnuhealthrc << "EOF"
TRYTON_VERSION=%{version}
EOF
getent group tryton > /dev/null || %{_sbindir}/groupadd -r tryton || :
getent passwd tryton > /dev/null || %{_sbindir}/useradd -r -g tryton \
-d %{_localstatedir}/lib/%{name} -s /sbin/nologin \
-c 'Tryton ERP' tryton
-c 'Tryton ERP' tryton || :
%service_add_pre trytond.service
%post
%service_add_post trytond.service
# Postgresql 96 is required for tryton series 4.2.x!
#update-alternatives --set postgresql /usr/lib/postgresql96
%preun
%service_del_preun trytond.service

View File

@ -1,504 +0,0 @@
# Copyright (c) 2018 Mathias Behrle <mbehrle@m9s.biz>
diff --git a/trytond/backend/database.py b/trytond/backend/database.py
index 22567cd61c7683ee88cb0e38c732a3a5ffb6b887..bff64d62fb45d0dbb45de5972375cb76414f1be4 100644
--- a/trytond/backend/database.py
+++ b/trytond/backend/database.py
@@ -172,3 +172,46 @@ class DatabaseInterface(object):
def has_multirow_insert(self):
'Return True if database supports multirow insert'
return False
+
+ @classmethod
+ def has_sequence(cls):
+ "Return if database supports sequence querying and assignation"
+ return False
+
+ def sequence_exist(self, connection, name):
+ "Return if a sequence exists"
+ if not self.has_sequence():
+ return
+ raise NotImplementedError
+
+ def sequence_create(
+ self, connection, name, number_increment=1, start_value=1):
+ "Creates a sequence"
+ if not self.has_sequence():
+ return
+ raise NotImplementedError
+
+ def sequence_update(
+ self, connection, name, number_increment=1, start_value=1):
+ "Modifies a sequence"
+ if not self.has_sequence():
+ return
+ raise NotImplementedError
+
+ def sequence_rename(self, connection, old_name, new_name):
+ "Renames a sequence"
+ if not self.has_sequence():
+ return
+ raise NotImplementedError
+
+ def sequence_delete(self, connection, name):
+ "Removes a sequence"
+ if not self.has_sequence():
+ return
+ raise NotImplementedError
+
+ def sequence_next_number(self, connection, name):
+ "Gets the next number of a sequence"
+ if not self.has_sequence():
+ return
+ raise NotImplementedError
diff --git a/trytond/backend/mysql/table.py b/trytond/backend/mysql/table.py
index bfe6031250787a0ed0d593dd4822ec25bb596b55..c09065f37ccf2c242007e69a44bf111e4e1e8632 100644
--- a/trytond/backend/mysql/table.py
+++ b/trytond/backend/mysql/table.py
@@ -75,14 +75,6 @@ class TableHandler(TableHandlerInterface):
cursor.execute('ALTER TABLE `%s` RENAME TO `%s`'
% (old_history, new_history))
- @staticmethod
- def sequence_exist(sequence_name):
- return True
-
- @staticmethod
- def sequence_rename(old_name, new_name):
- pass
-
def column_exist(self, column_name):
return column_name in self._columns
diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py
index 505973a8785ca5c11889aa757222a9242acb182a..6967b7d28c73d1968b216d57814a604f5af10199 100644
--- a/trytond/backend/postgresql/database.py
+++ b/trytond/backend/postgresql/database.py
@@ -2,7 +2,6 @@
# this repository contains the full copyright notices and license terms.
import time
import logging
-import re
import os
import urllib
from decimal import Decimal
@@ -34,8 +33,6 @@ __all__ = ['Database', 'DatabaseIntegrityError', 'DatabaseOperationalError']
logger = logging.getLogger(__name__)
-RE_VERSION = re.compile(r'\S+ (\d+)\.(\d+)')
-
os.environ['PGTZ'] = os.environ.get('TZ', '')
@@ -131,10 +128,11 @@ class Database(DatabaseInterface):
def get_version(self, connection):
if self.name not in self._version_cache:
cursor = connection.cursor()
- cursor.execute('SELECT version()')
+ cursor.execute('SHOW server_version_num')
version, = cursor.fetchone()
- self._version_cache[self.name] = tuple(map(int,
- RE_VERSION.search(version).groups()))
+ major, rest = divmod(int(version), 10000)
+ minor, patch = divmod(rest, 100)
+ self._version_cache[self.name] = (major, minor, patch)
return self._version_cache[self.name]
@staticmethod
@@ -353,6 +351,80 @@ class Database(DatabaseInterface):
self.put_connection(connection)
return self._search_path
+ @classmethod
+ def has_sequence(cls):
+ return True
+
+ def sequence_exist(self, connection, name):
+ cursor = connection.cursor()
+ for schema in self.search_path:
+ cursor.execute('SELECT 1 '
+ 'FROM information_schema.sequences '
+ 'WHERE sequence_name = %s AND sequence_schema = %s',
+ (name, schema))
+ if cursor.rowcount:
+ return True
+ return False
+
+ def sequence_create(
+ self, connection, name, number_increment=1, start_value=1):
+ cursor = connection.cursor()
+
+ param = self.flavor.param
+ cursor.execute(
+ 'CREATE SEQUENCE "%s" '
+ 'INCREMENT BY %s '
+ 'START WITH %s'
+ % (name, param, param),
+ (number_increment, start_value))
+
+ def sequence_update(
+ self, connection, name, number_increment=1, start_value=1):
+ cursor = connection.cursor()
+ param = self.flavor.param
+ cursor.execute(
+ 'ALTER SEQUENCE "%s" '
+ 'INCREMENT BY %s '
+ 'RESTART WITH %s'
+ % (name, param, param),
+ (number_increment, start_value))
+
+ def sequence_rename(self, connection, old_name, new_name):
+ cursor = connection.cursor()
+ if (self.sequence_exist(connection, old_name)
+ and not self.sequence_exist(connection, new_name)):
+ cursor.execute('ALTER TABLE "%s" RENAME TO "%s"'
+ % (old_name, new_name))
+
+ def sequence_delete(self, connection, name):
+ cursor = connection.cursor()
+ cursor.execute('DROP SEQUENCE "%s"' % name)
+
+ def sequence_next_number(self, connection, name):
+ cursor = connection.cursor()
+ version = self.get_version(connection)
+ if version >= (10, 0):
+ cursor.execute(
+ 'SELECT increment_by '
+ 'FROM pg_sequences '
+ 'WHERE sequencename=%s '
+ % self.flavor.param,
+ (name,))
+ increment, = cursor.fetchone()
+ cursor.execute(
+ 'SELECT CASE WHEN NOT is_called THEN last_value '
+ 'ELSE last_value + %s '
+ 'END '
+ 'FROM "%s"' % (self.flavor.param, name),
+ (increment,))
+ else:
+ cursor.execute(
+ 'SELECT CASE WHEN NOT is_called THEN last_value '
+ 'ELSE last_value + increment_by '
+ 'END '
+ 'FROM "%s"' % name)
+ return cursor.fetchone()[0]
+
register_type(UNICODE)
if PYDATE:
register_type(PYDATE)
diff --git a/trytond/backend/postgresql/table.py b/trytond/backend/postgresql/table.py
index a3323041c98be880cf9053b98589dc78e16265b5..8cae6ca12fcacf5a5cdd924416f26ef0ca7ca7bf 100644
--- a/trytond/backend/postgresql/table.py
+++ b/trytond/backend/postgresql/table.py
@@ -22,8 +22,10 @@ class TableHandler(TableHandlerInterface):
transaction = Transaction()
cursor = transaction.connection.cursor()
# Create sequence if necessary
- if not self.sequence_exist(self.sequence_name):
- cursor.execute('CREATE SEQUENCE "%s"' % self.sequence_name)
+ if not transaction.database.sequence_exist(
+ transaction.connection, self.sequence_name):
+ transaction.database.sequence_create(
+ transaction.connection, self.sequence_name)
# Create new table if necessary
if not self.table_exist(self.table_name):
@@ -81,7 +83,8 @@ class TableHandler(TableHandlerInterface):
@staticmethod
def table_rename(old_name, new_name):
- cursor = Transaction().connection.cursor()
+ transaction = Transaction()
+ cursor = transaction.connection.cursor()
# Rename table
if (TableHandler.table_exist(old_name)
and not TableHandler.table_exist(new_name)):
@@ -90,7 +93,8 @@ class TableHandler(TableHandlerInterface):
# Rename sequence
old_sequence = old_name + '_id_seq'
new_sequence = new_name + '_id_seq'
- TableHandler.sequence_rename(old_sequence, new_sequence)
+ transaction.database.sequence_rename(
+ transaction.connection, old_sequence, new_sequence)
# Rename history table
old_history = old_name + "__history"
new_history = new_name + "__history"
@@ -99,30 +103,6 @@ class TableHandler(TableHandlerInterface):
cursor.execute('ALTER TABLE "%s" RENAME TO "%s"'
% (old_history, new_history))
- @classmethod
- def sequence_schema(cls, sequence_name):
- transaction = Transaction()
- cursor = transaction.connection.cursor()
- for schema in transaction.database.search_path:
- cursor.execute('SELECT 1 '
- 'FROM information_schema.sequences '
- 'WHERE sequence_name = %s AND sequence_schema = %s',
- (sequence_name, schema))
- if cursor.rowcount:
- return schema
-
- @classmethod
- def sequence_exist(cls, sequence_name):
- return bool(cls.sequence_schema(sequence_name))
-
- @staticmethod
- def sequence_rename(old_name, new_name):
- cursor = Transaction().connection.cursor()
- if (TableHandler.sequence_exist(old_name)
- and not TableHandler.sequence_exist(new_name)):
- cursor.execute('ALTER TABLE "%s" RENAME TO "%s"'
- % (old_name, new_name))
-
def column_exist(self, column_name):
return column_name in self._columns
diff --git a/trytond/backend/table.py b/trytond/backend/table.py
index 887d415af80a3f69061808797b70621f73c0108d..853c51918e0b918f0aa9ad392eac7d22697990dd 100644
--- a/trytond/backend/table.py
+++ b/trytond/backend/table.py
@@ -46,26 +46,6 @@ class TableHandlerInterface(object):
'''
raise NotImplementedError
- @staticmethod
- def sequence_exist(sequence_name):
- '''
- Sequence exist
-
- :param sequence_name: the sequence name
- :return: a boolean
- '''
- raise NotImplementedError
-
- @staticmethod
- def sequence_rename(old_name, new_name):
- '''
- Rename sequence
-
- :param old_name: the old sequence name
- :param new_name: the new sequence name
- '''
- raise NotImplementedError
-
def column_exist(self, column_name):
'''
Column exist
diff --git a/trytond/ir/sequence.py b/trytond/ir/sequence.py
index 21bc3c12ee62990ce91fe675520582e3db8c41a8..f6791cf692fb6f9161d7a8607c01f638a576309d 100644
--- a/trytond/ir/sequence.py
+++ b/trytond/ir/sequence.py
@@ -3,7 +3,7 @@
from string import Template
import time
from itertools import izip
-from sql import Flavor
+from sql import Literal, For
from ..model import ModelView, ModelSQL, fields, Check
from ..tools import datetime_strftime
@@ -16,7 +16,7 @@ __all__ = [
'SequenceType', 'Sequence', 'SequenceStrict',
]
-sql_sequence = backend.name() == 'postgresql'
+sql_sequence = backend.get('Database').has_sequence()
class SequenceType(ModelSQL, ModelView):
@@ -104,6 +104,7 @@ class Sequence(ModelSQL, ModelView):
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
table = TableHandler(cls, module_name)
+ transaction = Transaction()
# Migration from 2.0 rename number_next into number_next_internal
table.column_rename('number_next', 'number_next_internal')
@@ -116,8 +117,8 @@ class Sequence(ModelSQL, ModelView):
for sequence in sequences:
if sequence.type != 'incremental':
continue
- if not TableHandler.sequence_exist(
- sequence._sql_sequence_name):
+ if not transaction.database.sequence_exist(
+ transaction.connection, sequence._sql_sequence_name):
sequence.create_sql_sequence(sequence.number_next_internal)
@staticmethod
@@ -159,14 +160,11 @@ class Sequence(ModelSQL, ModelView):
def get_number_next(self, name):
if self.type != 'incremental':
return
- cursor = Transaction().connection.cursor()
- sql_name = self._sql_sequence_name
+
+ transaction = Transaction()
if sql_sequence and not self._strict:
- cursor.execute('SELECT '
- 'CASE WHEN NOT is_called THEN last_value '
- 'ELSE last_value + increment_by '
- 'END FROM "%s"' % sql_name)
- return cursor.fetchone()[0]
+ return transaction.database.sequence_next_number(
+ transaction.connection, self._sql_sequence_name)
else:
return self.number_next_internal
@@ -260,22 +258,22 @@ class Sequence(ModelSQL, ModelView):
def create_sql_sequence(self, number_next=None):
'Create the SQL sequence'
- cursor = Transaction().connection.cursor()
- param = Flavor.get().param
+ transaction = Transaction()
+
if self.type != 'incremental':
return
if number_next is None:
number_next = self.number_next
- cursor.execute('CREATE SEQUENCE "' + self._sql_sequence_name
- + '" INCREMENT BY ' + param + ' START WITH ' + param,
- (self.number_increment, number_next))
+ if sql_sequence:
+ transaction.database.sequence_create(transaction.connection,
+ self._sql_sequence_name, self.number_increment, number_next)
def update_sql_sequence(self, number_next=None):
'Update the SQL sequence'
- TableHandler = backend.get('TableHandler')
- cursor = Transaction().connection.cursor()
- param = Flavor.get().param
- exist = TableHandler.sequence_exist(self._sql_sequence_name)
+ transaction = Transaction()
+
+ exist = transaction.database.sequence_exist(
+ transaction.connection, self._sql_sequence_name)
if self.type != 'incremental':
if exist:
self.delete_sql_sequence()
@@ -285,17 +283,16 @@ class Sequence(ModelSQL, ModelView):
return
if number_next is None:
number_next = self.number_next
- cursor.execute('ALTER SEQUENCE "' + self._sql_sequence_name
- + '" INCREMENT BY ' + param + ' RESTART WITH ' + param,
- (self.number_increment, number_next))
+ transaction.database.sequence_update(transaction.connection,
+ self._sql_sequence_name, self.number_increment, number_next)
def delete_sql_sequence(self):
'Delete the SQL sequence'
- cursor = Transaction().connection.cursor()
+ transaction = Transaction()
if self.type != 'incremental':
return
- cursor.execute('DROP SEQUENCE "%s"'
- % self._sql_sequence_name)
+ transaction.database.sequence_delete(
+ transaction.connection, self._sql_sequence_name)
@staticmethod
def _process(string, date=None):
diff --git a/trytond/res/ir.py b/trytond/res/ir.py
index 754a6226a6b5e1d7aca4b5575ed8232f9525eb2a..0265c46e4e6857753613a27d6a44575d003c4718 100644
--- a/trytond/res/ir.py
+++ b/trytond/res/ir.py
@@ -3,6 +3,7 @@
from ..model import ModelSQL, fields
from .. import backend
from ..pool import Pool, PoolMeta
+from ..transaction import Transaction
__all__ = [
'UIMenuGroup', 'ActionGroup', 'ModelFieldGroup', 'ModelButtonGroup',
@@ -23,10 +24,11 @@ class UIMenuGroup(ModelSQL):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
+ transaction = Transaction()
# Migration from 1.0 table name change
TableHandler.table_rename('ir_ui_menu_group_rel', cls._table)
- TableHandler.sequence_rename('ir_ui_menu_group_rel_id_seq',
- cls._table + '_id_seq')
+ transaction.database.sequence_rename(transaction.connection,
+ 'ir_ui_menu_group_rel_id_seq', cls._table + '_id_seq')
# Migration from 2.0 menu_id and gid renamed into menu group
table = TableHandler(cls, module_name)
table.column_rename('menu_id', 'menu')
@@ -64,10 +66,11 @@ class ActionGroup(ModelSQL):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
+ transaction = Transaction()
# Migration from 1.0 table name change
TableHandler.table_rename('ir_action_group_rel', cls._table)
- TableHandler.sequence_rename('ir_action_group_rel_id_seq',
- cls._table + '_id_seq')
+ transaction.database.sequence_rename(transaction.connection,
+ 'ir_action_group_rel_id_seq', cls._table + '_id_seq')
# Migration from 2.0 action_id and gid renamed into action and group
table = TableHandler(cls, module_name)
table.column_rename('action_id', 'action')
@@ -118,10 +121,12 @@ class ModelFieldGroup(ModelSQL):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
+ database = Transaction().database
+ transaction = Transaction()
# Migration from 1.0 table name change
TableHandler.table_rename('ir_model_field_group_rel', cls._table)
- TableHandler.sequence_rename('ir_model_field_group_rel_id_seq',
- cls._table + '_id_seq')
+ transaction.database.sequence_rename(transaction.connection,
+ 'ir_model_field_group_rel_id_seq', cls._table + '_id_seq')
table = TableHandler(cls, module_name)
# Migration from 2.6: field_id and group_id renamed to field and group
table.column_rename('field_id', 'field')
@@ -176,10 +181,11 @@ class RuleGroupGroup(ModelSQL):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
+ transaction = Transaction()
# Migration from 1.0 table name change
TableHandler.table_rename('group_rule_group_rel', cls._table)
- TableHandler.sequence_rename('group_rule_group_rel_id_seq',
- cls._table + '_id_seq')
+ transaction.database.sequence_rename(transaction.connection,
+ 'group_rule_group_rel_id_seq', cls._table + '_id_seq')
# Migration from 2.0 rule_group_id and group_id renamed into rule_group
# and group
table = TableHandler(cls, module_name)
@@ -199,10 +205,11 @@ class RuleGroupUser(ModelSQL):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
+ transaction = Transaction()
# Migration from 1.0 table name change
TableHandler.table_rename('user_rule_group_rel', cls._table)
- TableHandler.sequence_rename('user_rule_group_rel_id_seq',
- cls._table + '_id_seq')
+ transaction.database.sequence_rename(transaction.connection,
+ 'user_rule_group_rel_id_seq', cls._table + '_id_seq')
# Migration from 2.0 rule_group_id and user_id renamed into rule_group
# and user
table = TableHandler(cls, module_name)
diff --git a/trytond/res/user.py b/trytond/res/user.py
index ac539065b01127b77540c4f3dbdca9b3383d8978..dd13df43b05f9f243d9e1e29573252c0640b7122 100644
--- a/trytond/res/user.py
+++ b/trytond/res/user.py
@@ -645,10 +645,12 @@ class UserGroup(ModelSQL):
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
+ transaction = Transaction()
+
# Migration from 1.0 table name change
TableHandler.table_rename('res_group_user_rel', cls._table)
- TableHandler.sequence_rename('res_group_user_rel_id_seq',
- cls._table + '_id_seq')
+ transaction.database.sequence_rename(transaction.connection,
+ 'res_group_user_rel_id_seq', cls._table + '_id_seq')
# Migration from 2.0 uid and gid rename into user and group
table = TableHandler(cls, module_name)
table.column_rename('uid', 'user')

View File

@ -1,40 +0,0 @@
--- trytond/res/user.py 2018-02-15 13:09:37.735716404 +0000
+++ trytond/res/user.py 2018-02-15 22:08:51.966998130 +0000
@@ -18,6 +18,7 @@
from sql.conditionals import Coalesce
from sql.aggregate import Count
from sql.operators import Concat
+from random import randint
try:
import bcrypt
@@ -495,7 +496,16 @@
Return user id if password matches
'''
LoginAttempt = Pool().get('res.user.login.attempt')
- time.sleep(2 ** LoginAttempt.count(login) - 1)
+
+ login_max_delay = config.getint('session', 'login_max_delay')
+
+ if (not login_max_delay) or (login_max_delay < 1):
+ login_max_delay = 3
+
+ #Use a random delay (default between 1 and login_max_delay) in login
+ #if the param is not set, it defaults to 3
+ delay = randint(1,login_max_delay)
+ time.sleep(delay)
for method in config.get(
'session', 'authentications', default='password').split(','):
try:
@@ -505,9 +515,9 @@
continue
user_id = func(login, parameters)
if user_id:
- LoginAttempt.remove(login)
return user_id
- LoginAttempt.add(login)
+ else:
+ logger.info('Invalid login from : %s', login)
@classmethod
def _login_password(cls, login, parameters):

View File

@ -7,23 +7,23 @@
[database]
[formatters]
keys: simple
keys=simple
[handlers]
keys: rotate
keys=rotate
[loggers]
keys: root
keys=root
[formatter_simple]
format: %(asctime)s] %(levelname)s:%(name)s:%(message)s
datefmt: %a %b %d %H:%M:%S %Y
format=%(asctime)s] %(levelname)s:%(name)s:%(message)s
datefmt=%a %b %d %H:%M:%S %Y
[handler_rotate]
class: handlers.TimedRotatingFileHandler
args: ('/var/log/tryton/trytond.log', 'D', 1, 30)
formatter: simple
class=handlers.TimedRotatingFileHandler
args=('/var/log/tryton/trytond.log', 'D', 1, 30)
formatter=simple
[logger_root]
level: INFO
handlers: rotate
level=INFO
handlers=rotate