commit
a28edaaeff
|
@ -35,7 +35,7 @@ class res_users(Model):
|
||||||
|
|
||||||
# Private Function section
|
# Private Function section
|
||||||
def _get_translation(self, cr, lang, text):
|
def _get_translation(self, cr, lang, text):
|
||||||
context = {'lang': lang}
|
context = {'lang': lang} # noqa: _() checks page for locals
|
||||||
return _(text)
|
return _(text)
|
||||||
|
|
||||||
def _send_email_passkey(self, cr, user_id, user_agent_env):
|
def _send_email_passkey(self, cr, user_id, user_agent_env):
|
||||||
|
|
|
@ -36,7 +36,8 @@ def init(self, params):
|
||||||
base_location=self.httprequest.url_root.rstrip('/'),
|
base_location=self.httprequest.url_root.rstrip('/'),
|
||||||
HTTP_HOST=self.httprequest.environ['HTTP_HOST'],
|
HTTP_HOST=self.httprequest.environ['HTTP_HOST'],
|
||||||
REMOTE_ADDR=self.httprequest.environ['REMOTE_ADDR']
|
REMOTE_ADDR=self.httprequest.environ['REMOTE_ADDR']
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
WebRequest.init = init
|
WebRequest.init = init
|
||||||
|
|
||||||
|
|
|
@ -34,13 +34,15 @@ try:
|
||||||
try:
|
try:
|
||||||
import pymssql
|
import pymssql
|
||||||
CONNECTORS.append(('mssql', 'Microsoft SQL Server'))
|
CONNECTORS.append(('mssql', 'Microsoft SQL Server'))
|
||||||
except:
|
assert pymssql
|
||||||
|
except ImportError, AssertionError:
|
||||||
_logger.info('MS SQL Server not available. Please install "pymssql"\
|
_logger.info('MS SQL Server not available. Please install "pymssql"\
|
||||||
python package.')
|
python package.')
|
||||||
try:
|
try:
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
CONNECTORS.append(('mysql', 'MySQL'))
|
CONNECTORS.append(('mysql', 'MySQL'))
|
||||||
except:
|
assert MySQLdb
|
||||||
|
except ImportError, AssertionError:
|
||||||
_logger.info('MySQL not available. Please install "mysqldb"\
|
_logger.info('MySQL not available. Please install "mysqldb"\
|
||||||
python package.')
|
python package.')
|
||||||
except:
|
except:
|
||||||
|
@ -90,15 +92,15 @@ Sample connection strings:
|
||||||
}
|
}
|
||||||
|
|
||||||
def conn_open(self, cr, uid, id1):
|
def conn_open(self, cr, uid, id1):
|
||||||
#Get dbsource record
|
# Get dbsource record
|
||||||
data = self.browse(cr, uid, id1)
|
data = self.browse(cr, uid, id1)
|
||||||
#Build the full connection string
|
# Build the full connection string
|
||||||
connStr = data.conn_string
|
connStr = data.conn_string
|
||||||
if data.password:
|
if data.password:
|
||||||
if '%s' not in data.conn_string:
|
if '%s' not in data.conn_string:
|
||||||
connStr += ';PWD=%s'
|
connStr += ';PWD=%s'
|
||||||
connStr = connStr % data.password
|
connStr = connStr % data.password
|
||||||
#Try to connect
|
# Try to connect
|
||||||
if data.connector == 'cx_Oracle':
|
if data.connector == 'cx_Oracle':
|
||||||
os.environ['NLS_LANG'] = 'AMERICAN_AMERICA.UTF8'
|
os.environ['NLS_LANG'] = 'AMERICAN_AMERICA.UTF8'
|
||||||
conn = cx_Oracle.connect(connStr)
|
conn = cx_Oracle.connect(connStr)
|
||||||
|
@ -134,13 +136,13 @@ Sample connection strings:
|
||||||
for obj in data:
|
for obj in data:
|
||||||
conn = self.conn_open(cr, uid, obj.id)
|
conn = self.conn_open(cr, uid, obj.id)
|
||||||
if obj.connector in ["sqlite", "mysql", "mssql"]:
|
if obj.connector in ["sqlite", "mysql", "mssql"]:
|
||||||
#using sqlalchemy
|
# using sqlalchemy
|
||||||
cur = conn.execute(sqlquery, sqlparams)
|
cur = conn.execute(sqlquery, sqlparams)
|
||||||
if metadata:
|
if metadata:
|
||||||
cols = cur.keys()
|
cols = cur.keys()
|
||||||
rows = [r for r in cur]
|
rows = [r for r in cur]
|
||||||
else:
|
else:
|
||||||
#using other db connectors
|
# using other db connectors
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute(sqlquery, sqlparams)
|
cur.execute(sqlquery, sqlparams)
|
||||||
if metadata:
|
if metadata:
|
||||||
|
@ -168,8 +170,6 @@ Sample connection strings:
|
||||||
except Exception:
|
except Exception:
|
||||||
# ignored, just a consequence of the previous exception
|
# ignored, just a consequence of the previous exception
|
||||||
pass
|
pass
|
||||||
#TODO: if OK a (wizard) message box should be displayed
|
# TODO: if OK a (wizard) message box should be displayed
|
||||||
raise orm.except_orm(_("Connection test succeeded!"),
|
raise orm.except_orm(_("Connection test succeeded!"),
|
||||||
_("Everything seems properly set up!"))
|
_("Everything seems properly set up!"))
|
||||||
|
|
||||||
#EOF
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class AbstractConfigSettings(orm.AbstractModel):
|
||||||
super(AbstractConfigSettings, self).__init__(pool, cr)
|
super(AbstractConfigSettings, self).__init__(pool, cr)
|
||||||
if self._companyObject:
|
if self._companyObject:
|
||||||
for field_key in self._companyObject._columns:
|
for field_key in self._companyObject._columns:
|
||||||
#allows to exclude some field
|
# allows to exclude some field
|
||||||
if self._filter_field(field_key):
|
if self._filter_field(field_key):
|
||||||
args = ('company_id', field_key)
|
args = ('company_id', field_key)
|
||||||
kwargs = {
|
kwargs = {
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
{
|
{
|
||||||
"name" : "dbfilter_from_header",
|
"name": "dbfilter_from_header",
|
||||||
"version" : "1.0",
|
"version": "1.0",
|
||||||
"author" : "Therp BV",
|
"author": "Therp BV",
|
||||||
"complexity": "normal",
|
"complexity": "normal",
|
||||||
"description": """
|
"description": """
|
||||||
This addon lets you pass a dbfilter as a HTTP header.
|
This addon lets you pass a dbfilter as a HTTP header.
|
||||||
|
@ -34,11 +34,11 @@
|
||||||
|
|
||||||
The addon has to be loaded as server-wide module.
|
The addon has to be loaded as server-wide module.
|
||||||
""",
|
""",
|
||||||
"category" : "Tools",
|
"category": "Tools",
|
||||||
"depends" : [
|
"depends": [
|
||||||
'web',
|
'web',
|
||||||
],
|
],
|
||||||
"data" : [
|
"data": [
|
||||||
],
|
],
|
||||||
"js": [
|
"js": [
|
||||||
],
|
],
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
],
|
],
|
||||||
"auto_install": False,
|
"auto_install": False,
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"external_dependencies" : {
|
"external_dependencies": {
|
||||||
'python' : [],
|
'python': [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,13 +77,18 @@ And it will be evaluated to
|
||||||
Example city
|
Example city
|
||||||
Example Corp footer
|
Example Corp footer
|
||||||
|
|
||||||
Given the way evaluation works internally (body_text of the template template is evaluated two times, first with the instance of email.template of your own template, then with the object your template refers to), you can do some trickery if you know that a template template is always used with the same kind of model (that is, models that have the same field name):
|
Given the way evaluation works internally (body_text of the template template
|
||||||
|
is evaluated two times, first with the instance of email.template of your own
|
||||||
|
template, then with the object your template refers to), you can do some
|
||||||
|
trickery if you know that a template template is always used with the same
|
||||||
|
kind of model (that is, models that have the same field name):
|
||||||
|
|
||||||
In your template template:
|
In your template template:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
Dear ${'${object.name}'}, <-- gets evaluated to "${object.name}" in the first step, then to the content of object.name
|
Dear ${'${object.name}'}, <-- gets evaluated to "${object.name}" in the
|
||||||
|
first step, then to the content of object.name
|
||||||
${object.body_html}
|
${object.body_html}
|
||||||
Best,
|
Best,
|
||||||
Example Corp
|
Example Corp
|
||||||
|
|
|
@ -26,9 +26,13 @@
|
||||||
'description': """
|
'description': """
|
||||||
This module allows to create configurable calendars.
|
This module allows to create configurable calendars.
|
||||||
|
|
||||||
Through the 'calendar configurator' object, you can specify which models have to be merged in the super calendar. For each model, you have to define the 'description' and 'date_start' fields at least. Then you can define 'duration' and the 'user_id' fields.
|
Through the 'calendar configurator' object, you can specify which models have
|
||||||
|
to be merged in the super calendar. For each model, you have to define the
|
||||||
|
'description' and 'date_start' fields at least. Then you can define 'duration'
|
||||||
|
and the 'user_id' fields.
|
||||||
|
|
||||||
The 'super.calendar' object contains the the merged calendars. The 'super.calendar' can be updated by 'ir.cron' or manually.
|
The 'super.calendar' object contains the the merged calendars. The
|
||||||
|
'super.calendar' can be updated by 'ir.cron' or manually.
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
@ -37,7 +41,8 @@ After installing the module you can go to
|
||||||
|
|
||||||
Super calendar → Configuration → Configurators
|
Super calendar → Configuration → Configurators
|
||||||
|
|
||||||
and create a new configurator. For instance, if you want to see meetings and phone calls, you can create the following lines
|
and create a new configurator. For instance, if you want to see meetings and
|
||||||
|
phone calls, you can create the following lines
|
||||||
|
|
||||||
.. image:: http://planet.domsense.com/wp-content/uploads/2012/04/meetings.png
|
.. image:: http://planet.domsense.com/wp-content/uploads/2012/04/meetings.png
|
||||||
:width: 400 px
|
:width: 400 px
|
||||||
|
@ -45,7 +50,8 @@ and create a new configurator. For instance, if you want to see meetings and pho
|
||||||
.. image:: http://planet.domsense.com/wp-content/uploads/2012/04/phone_calls.png
|
.. image:: http://planet.domsense.com/wp-content/uploads/2012/04/phone_calls.png
|
||||||
:width: 400 px
|
:width: 400 px
|
||||||
|
|
||||||
Then, you can use the ‘Generate Calendar’ button or wait for the scheduled action (‘Generate Calendar Records’) to be run.
|
Then, you can use the ‘Generate Calendar’ button or wait for the scheduled
|
||||||
|
action (‘Generate Calendar Records’) to be run.
|
||||||
|
|
||||||
When the calendar is generated, you can visualize it by the ‘super calendar’ main menu.
|
When the calendar is generated, you can visualize it by the ‘super calendar’ main menu.
|
||||||
|
|
||||||
|
@ -59,13 +65,17 @@ And here is the weekly one:
|
||||||
.. image:: http://planet.domsense.com/wp-content/uploads/2012/04/week_calendar.png
|
.. image:: http://planet.domsense.com/wp-content/uploads/2012/04/week_calendar.png
|
||||||
:width: 400 px
|
:width: 400 px
|
||||||
|
|
||||||
As you can see, several filters are available. A typical usage consists in filtering by ‘Configurator’ (if you have several configurators, ‘Scheduled calls and meetings’ can be one of them) and by your user. Once you filtered, you can save the filter as ‘Advanced filter’ or even add it to a dashboard.
|
As you can see, several filters are available. A typical usage consists in
|
||||||
|
filtering by ‘Configurator’ (if you have several configurators,
|
||||||
|
‘Scheduled calls and meetings’ can be one of them) and by your user.
|
||||||
|
Once you filtered, you can save the filter as ‘Advanced filter’ or even
|
||||||
|
add it to a dashboard.
|
||||||
""",
|
""",
|
||||||
'author': 'Agile Business Group',
|
'author': 'Agile Business Group',
|
||||||
'website': 'http://www.agilebg.com',
|
'website': 'http://www.agilebg.com',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'depends' : ['base'],
|
'depends': ['base'],
|
||||||
"data" : [
|
"data": [
|
||||||
'super_calendar_view.xml',
|
'super_calendar_view.xml',
|
||||||
'cron_data.xml',
|
'cron_data.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, osv, orm
|
from openerp.osv import fields, orm
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
import logging
|
import logging
|
||||||
from mako.template import Template
|
from mako.template import Template
|
||||||
|
@ -27,12 +27,14 @@ from datetime import datetime
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
from openerp.tools.safe_eval import safe_eval
|
from openerp.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
|
|
||||||
def _models_get(self, cr, uid, context=None):
|
def _models_get(self, cr, uid, context=None):
|
||||||
obj = self.pool.get('ir.model')
|
obj = self.pool.get('ir.model')
|
||||||
ids = obj.search(cr, uid, [])
|
ids = obj.search(cr, uid, [])
|
||||||
res = obj.read(cr, uid, ids, ['model', 'name'], context)
|
res = obj.read(cr, uid, ids, ['model', 'name'], context)
|
||||||
return [(r['model'], r['name']) for r in res]
|
return [(r['model'], r['name']) for r in res]
|
||||||
|
|
||||||
|
|
||||||
class super_calendar_configurator(orm.Model):
|
class super_calendar_configurator(orm.Model):
|
||||||
_logger = logging.getLogger('super.calendar')
|
_logger = logging.getLogger('super.calendar')
|
||||||
_name = 'super.calendar.configurator'
|
_name = 'super.calendar.configurator'
|
||||||
|
@ -60,19 +62,29 @@ class super_calendar_configurator(orm.Model):
|
||||||
|
|
||||||
for current_record_id in current_record_ids:
|
for current_record_id in current_record_ids:
|
||||||
current_record = current_pool.browse(cr, uid, current_record_id, context=context)
|
current_record = current_pool.browse(cr, uid, current_record_id, context=context)
|
||||||
if line.user_field_id and \
|
if (line.user_field_id and
|
||||||
current_record[line.user_field_id.name] and current_record[line.user_field_id.name]._table_name != 'res.users':
|
current_record[line.user_field_id.name] and
|
||||||
raise osv.except_osv(_('Error'),
|
current_record[line.user_field_id.name]._table_name != 'res.users'):
|
||||||
|
raise orm.except_orm(
|
||||||
|
_('Error'),
|
||||||
_("The 'User' field of record %s (%s) does not refer to res.users")
|
_("The 'User' field of record %s (%s) does not refer to res.users")
|
||||||
% (current_record[line.description_field_id.name], line.name.model))
|
% (current_record[line.description_field_id.name], line.name.model))
|
||||||
if (((line.description_field_id
|
if (((line.description_field_id and current_record[line.description_field_id.name]) or
|
||||||
and current_record[line.description_field_id.name])
|
line.description_code) and
|
||||||
or line.description_code)
|
current_record[line.date_start_field_id.name]):
|
||||||
and current_record[line.date_start_field_id.name]):
|
|
||||||
duration = False
|
duration = False
|
||||||
if not line.duration_field_id and line.date_stop_field_id and current_record[line.date_start_field_id.name] and current_record[line.date_stop_field_id.name]:
|
if (not line.duration_field_id and
|
||||||
date_start= datetime.strptime(current_record[line.date_start_field_id.name], tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
line.date_stop_field_id and
|
||||||
date_stop= datetime.strptime(current_record[line.date_stop_field_id.name], tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
current_record[line.date_start_field_id.name] and
|
||||||
|
current_record[line.date_stop_field_id.name]):
|
||||||
|
date_start = datetime.strptime(
|
||||||
|
current_record[line.date_start_field_id.name],
|
||||||
|
tools.DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
|
)
|
||||||
|
date_stop = datetime.strptime(
|
||||||
|
current_record[line.date_stop_field_id.name],
|
||||||
|
tools.DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
|
)
|
||||||
duration = (date_stop - date_start).total_seconds() / 3600
|
duration = (date_stop - date_start).total_seconds() / 3600
|
||||||
elif line.duration_field_id:
|
elif line.duration_field_id:
|
||||||
duration = current_record[line.duration_field_id.name]
|
duration = current_record[line.duration_field_id.name]
|
||||||
|
@ -81,13 +93,18 @@ class super_calendar_configurator(orm.Model):
|
||||||
else:
|
else:
|
||||||
parse_dict = {'o': current_record}
|
parse_dict = {'o': current_record}
|
||||||
mytemplate = Template(line.description_code)
|
mytemplate = Template(line.description_code)
|
||||||
name= mytemplate.render(**parse_dict)
|
name = mytemplate.render(**parse_dict)
|
||||||
super_calendar_values = {
|
super_calendar_values = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'model_description': line.description,
|
'model_description': line.description,
|
||||||
'date_start': current_record[line.date_start_field_id.name],
|
'date_start': current_record[line.date_start_field_id.name],
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'user_id': line.user_field_id and current_record[line.user_field_id.name] and current_record[line.user_field_id.name].id or False,
|
'user_id': (
|
||||||
|
line.user_field_id and
|
||||||
|
current_record[line.user_field_id.name] and
|
||||||
|
current_record[line.user_field_id.name].id or
|
||||||
|
False
|
||||||
|
),
|
||||||
'configurator_id': configurator.id,
|
'configurator_id': configurator.id,
|
||||||
'res_id': line.name.model+','+str(current_record['id']),
|
'res_id': line.name.model+','+str(current_record['id']),
|
||||||
'model_id': line.name.id,
|
'model_id': line.name.id,
|
||||||
|
@ -108,17 +125,26 @@ class super_calendar_configurator_line(orm.Model):
|
||||||
('field', 'Field'),
|
('field', 'Field'),
|
||||||
('code', 'Code'),
|
('code', 'Code'),
|
||||||
], string="Description Type"),
|
], string="Description Type"),
|
||||||
'description_field_id': fields.many2one('ir.model.fields', 'Description field',
|
'description_field_id': fields.many2one(
|
||||||
|
'ir.model.fields', 'Description field',
|
||||||
domain="[('model_id', '=', name),('ttype', '=', 'char')]"),
|
domain="[('model_id', '=', name),('ttype', '=', 'char')]"),
|
||||||
'description_code': fields.text('Description field', help="Use '${o}' to refer to the involved object. E.g.: '${o.project_id.name}'"),
|
'description_code': fields.text(
|
||||||
'date_start_field_id': fields.many2one('ir.model.fields', 'Start date field',
|
'Description field',
|
||||||
|
help="Use '${o}' to refer to the involved object. E.g.: '${o.project_id.name}'"
|
||||||
|
),
|
||||||
|
'date_start_field_id': fields.many2one(
|
||||||
|
'ir.model.fields', 'Start date field',
|
||||||
domain="['&','|',('ttype', '=', 'datetime'),('ttype', '=', 'date'),('model_id', '=', name)]",
|
domain="['&','|',('ttype', '=', 'datetime'),('ttype', '=', 'date'),('model_id', '=', name)]",
|
||||||
required=True),
|
required=True),
|
||||||
'date_stop_field_id': fields.many2one('ir.model.fields', 'End date field',
|
'date_stop_field_id': fields.many2one(
|
||||||
domain="['&',('ttype', '=', 'datetime'),('model_id', '=', name)]"),
|
'ir.model.fields', 'End date field',
|
||||||
'duration_field_id': fields.many2one('ir.model.fields', 'Duration field',
|
domain="['&',('ttype', '=', 'datetime'),('model_id', '=', name)]"
|
||||||
|
),
|
||||||
|
'duration_field_id': fields.many2one(
|
||||||
|
'ir.model.fields', 'Duration field',
|
||||||
domain="['&',('ttype', '=', 'float'),('model_id', '=', name)]"),
|
domain="['&',('ttype', '=', 'float'),('model_id', '=', name)]"),
|
||||||
'user_field_id': fields.many2one('ir.model.fields', 'User field',
|
'user_field_id': fields.many2one(
|
||||||
|
'ir.model.fields', 'User field',
|
||||||
domain="['&',('ttype', '=', 'many2one'),('model_id', '=', name)]"),
|
domain="['&',('ttype', '=', 'many2one'),('model_id', '=', name)]"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +154,8 @@ class super_calendar(orm.Model):
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Description', size=512, required=True),
|
'name': fields.char('Description', size=512, required=True),
|
||||||
'model_description': fields.char('Model Description', size=128, required=True),
|
'model_description': fields.char('Model Description', size=128, required=True),
|
||||||
'date_start':fields.datetime('Start date', required=True),
|
'date_start': fields.datetime('Start date', required=True),
|
||||||
'duration':fields.float('Duration'),
|
'duration': fields.float('Duration'),
|
||||||
'user_id': fields.many2one('res.users', 'User'),
|
'user_id': fields.many2one('res.users', 'User'),
|
||||||
'configurator_id': fields.many2one('super.calendar.configurator', 'Configurator'),
|
'configurator_id': fields.many2one('super.calendar.configurator', 'Configurator'),
|
||||||
'res_id': fields.reference('Resource', selection=_models_get, size=128),
|
'res_id': fields.reference('Resource', selection=_models_get, size=128),
|
||||||
|
|
|
@ -20,11 +20,11 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
{
|
{
|
||||||
"name" : "Groups assignment",
|
"name": "Groups assignment",
|
||||||
"version" : "1.2",
|
"version": "1.2",
|
||||||
"depends" : ["auth_ldap"],
|
"depends": ["auth_ldap"],
|
||||||
"author" : "Therp BV",
|
"author": "Therp BV",
|
||||||
"description": """
|
"description": """
|
||||||
Adds user accounts to groups based on rules defined by the administrator.
|
Adds user accounts to groups based on rules defined by the administrator.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
@ -49,14 +49,13 @@ The operator query matches if the filter in value returns something, and value
|
||||||
can contain $[attribute] which will be replaced by the first value of the
|
can contain $[attribute] which will be replaced by the first value of the
|
||||||
user's ldap record's attribute named [attribute].
|
user's ldap record's attribute named [attribute].
|
||||||
""",
|
""",
|
||||||
"category" : "Tools",
|
"category": "Tools",
|
||||||
"data" : [
|
"data": [
|
||||||
'users_ldap_groups.xml',
|
'users_ldap_groups.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"external_dependencies" : {
|
"external_dependencies": {
|
||||||
'python' : ['ldap'],
|
'python': ['ldap'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
||||||
|
|
|
@ -23,76 +23,85 @@ from openerp.osv import fields, orm
|
||||||
import logging
|
import logging
|
||||||
import users_ldap_groups_operators
|
import users_ldap_groups_operators
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
|
||||||
|
|
||||||
class CompanyLDAPGroupMapping(orm.Model):
|
class CompanyLDAPGroupMapping(orm.Model):
|
||||||
_name='res.company.ldap.group_mapping'
|
_name = 'res.company.ldap.group_mapping'
|
||||||
_rec_name='ldap_attribute'
|
_rec_name = 'ldap_attribute'
|
||||||
_order='ldap_attribute'
|
_order = 'ldap_attribute'
|
||||||
|
|
||||||
def _get_operators(self, cr, uid, context=None):
|
def _get_operators(self, cr, uid, context=None):
|
||||||
operators=[]
|
operators = []
|
||||||
for name, operator in inspect.getmembers(users_ldap_groups_operators,
|
members = inspect.getmembers(
|
||||||
|
users_ldap_groups_operators,
|
||||||
lambda cls: inspect.isclass(cls)
|
lambda cls: inspect.isclass(cls)
|
||||||
and cls!=users_ldap_groups_operators.LDAPOperator):
|
and cls != users_ldap_groups_operators.LDAPOperator)
|
||||||
|
for name, operator in members:
|
||||||
operators.append((name, name))
|
operators.append((name, name))
|
||||||
return tuple(operators)
|
return tuple(operators)
|
||||||
|
|
||||||
_columns={
|
_columns = {
|
||||||
'ldap_id': fields.many2one('res.company.ldap', 'LDAP server',
|
'ldap_id': fields.many2one('res.company.ldap', 'LDAP server', required=True),
|
||||||
required=True),
|
'ldap_attribute': fields.char(
|
||||||
'ldap_attribute': fields.char('LDAP attribute', size=64,
|
'LDAP attribute', size=64,
|
||||||
help='The LDAP attribute to check.\n'
|
help='The LDAP attribute to check.\n'
|
||||||
'For active directory, use memberOf.'),
|
'For active directory, use memberOf.'),
|
||||||
'operator': fields.selection(_get_operators, 'Operator',
|
'operator': fields.selection(
|
||||||
|
_get_operators, 'Operator',
|
||||||
help='The operator to check the attribute against the value\n'
|
help='The operator to check the attribute against the value\n'
|
||||||
'For active directory, use \'contains\'', required=True),
|
'For active directory, use \'contains\'', required=True),
|
||||||
'value': fields.char('Value', size=1024,
|
'value': fields.char(
|
||||||
|
'Value', size=1024,
|
||||||
help='The value to check the attribute against.\n'
|
help='The value to check the attribute against.\n'
|
||||||
'For active directory, use the dn of the desired group',
|
'For active directory, use the dn of the desired group',
|
||||||
required=True),
|
required=True),
|
||||||
'group': fields.many2one('res.groups', 'OpenERP group',
|
'group': fields.many2one(
|
||||||
|
'res.groups', 'OpenERP group',
|
||||||
help='The OpenERP group to assign', required=True),
|
help='The OpenERP group to assign', required=True),
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompanyLDAP(orm.Model):
|
|
||||||
_inherit='res.company.ldap'
|
|
||||||
|
|
||||||
_columns={
|
class CompanyLDAP(orm.Model):
|
||||||
'group_mappings': fields.one2many('res.company.ldap.group_mapping',
|
_inherit = 'res.company.ldap'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'group_mappings': fields.one2many(
|
||||||
|
'res.company.ldap.group_mapping',
|
||||||
'ldap_id', 'Group mappings',
|
'ldap_id', 'Group mappings',
|
||||||
help='Define how OpenERP groups are assigned to ldap users'),
|
help='Define how OpenERP groups are assigned to ldap users'),
|
||||||
'only_ldap_groups': fields.boolean('Only ldap groups',
|
'only_ldap_groups': fields.boolean(
|
||||||
|
'Only ldap groups',
|
||||||
help='If this is checked, manual changes to group membership are '
|
help='If this is checked, manual changes to group membership are '
|
||||||
'undone on every login (so OpenERP groups are always synchronous '
|
'undone on every login (so OpenERP groups are always synchronous '
|
||||||
'with LDAP groups). If not, manually added groups are preserved.')
|
'with LDAP groups). If not, manually added groups are preserved.')
|
||||||
}
|
}
|
||||||
|
|
||||||
_default={
|
_default = {
|
||||||
'only_ldap_groups': False
|
'only_ldap_groups': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_or_create_user(self, cr, uid, conf, login, ldap_entry, context=None):
|
def get_or_create_user(self, cr, uid, conf, login, ldap_entry, context=None):
|
||||||
user_id=super(CompanyLDAP, self).get_or_create_user(cr, uid, conf, login,
|
user_id = super(CompanyLDAP, self).get_or_create_user(cr, uid, conf, login,
|
||||||
ldap_entry, context)
|
ldap_entry, context)
|
||||||
if not user_id:
|
if not user_id:
|
||||||
return user_id
|
return user_id
|
||||||
logger=logging.getLogger('users_ldap_groups')
|
logger = logging.getLogger('users_ldap_groups')
|
||||||
mappingobj=self.pool.get('res.company.ldap.group_mapping')
|
mappingobj = self.pool.get('res.company.ldap.group_mapping')
|
||||||
userobj=self.pool.get('res.users')
|
userobj = self.pool.get('res.users')
|
||||||
conf_all=self.read(cr, uid, conf['id'], ['only_ldap_groups'])
|
conf_all = self.read(cr, uid, conf['id'], ['only_ldap_groups'])
|
||||||
if(conf_all['only_ldap_groups']):
|
if(conf_all['only_ldap_groups']):
|
||||||
logger.debug('deleting all groups from user %d' % user_id)
|
logger.debug('deleting all groups from user %d' % user_id)
|
||||||
userobj.write(cr, uid, [user_id], {'groups_id': [(5, )]})
|
userobj.write(cr, uid, [user_id], {'groups_id': [(5, )]}, context=context)
|
||||||
|
|
||||||
for mapping in mappingobj.read(cr, uid, mappingobj.search(cr, uid,
|
for mapping in mappingobj.read(cr, uid, mappingobj.search(
|
||||||
[('ldap_id', '=', conf['id'])]), []):
|
cr, uid, [('ldap_id', '=', conf['id'])]), []):
|
||||||
operator=getattr(users_ldap_groups_operators, mapping['operator'])()
|
operator = getattr(users_ldap_groups_operators, mapping['operator'])()
|
||||||
logger.debug('checking mapping %s' % mapping)
|
logger.debug('checking mapping %s' % mapping)
|
||||||
if operator.check_value(ldap_entry, mapping['ldap_attribute'],
|
if operator.check_value(ldap_entry, mapping['ldap_attribute'],
|
||||||
mapping['value'], conf, self, logger):
|
mapping['value'], conf, self, logger):
|
||||||
logger.debug('adding user %d to group %s' %
|
logger.debug('adding user %d to group %s' %
|
||||||
(user_id, mapping['group'][1]))
|
(user_id, mapping['group'][1]))
|
||||||
userobj.write(cr, uid, [user_id],
|
userobj.write(cr, uid, [user_id],
|
||||||
{'groups_id': [(4, mapping['group'][0])]})
|
{'groups_id': [(4, mapping['group'][0])]},
|
||||||
|
context=context)
|
||||||
return user_id
|
return user_id
|
||||||
|
|
|
@ -20,25 +20,28 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
from string import Template
|
from string import Template
|
||||||
|
|
||||||
|
|
||||||
class LDAPOperator:
|
class LDAPOperator:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class contains(LDAPOperator):
|
class contains(LDAPOperator):
|
||||||
def check_value(self, ldap_entry, attribute, value, ldap_config, company,
|
def check_value(self, ldap_entry, attribute, value, ldap_config, company, logger):
|
||||||
logger):
|
|
||||||
return (attribute in ldap_entry[1]) and (value in ldap_entry[1][attribute])
|
return (attribute in ldap_entry[1]) and (value in ldap_entry[1][attribute])
|
||||||
|
|
||||||
|
|
||||||
class equals(LDAPOperator):
|
class equals(LDAPOperator):
|
||||||
def check_value(self, ldap_entry, attribute, value, ldap_config, company,
|
def check_value(self, ldap_entry, attribute, value, ldap_config, company, logger):
|
||||||
logger):
|
return attribute in ldap_entry[1] and unicode(value) == unicode(ldap_entry[1][attribute])
|
||||||
return (attribute in ldap_entry[1]) and (str(value)==str(ldap_entry[1][attribute]))
|
|
||||||
|
|
||||||
class query(LDAPOperator):
|
class query(LDAPOperator):
|
||||||
def check_value(self, ldap_entry, attribute, value, ldap_config, company,
|
def check_value(self, ldap_entry, attribute, value, ldap_config, company, logger):
|
||||||
logger):
|
query_string = Template(value).safe_substitute(dict(
|
||||||
query_string=Template(value).safe_substitute(dict([(attribute,
|
[(attr, ldap_entry[1][attribute][0]) for attr in ldap_entry[1]]
|
||||||
ldap_entry[1][attribute][0]) for attribute in ldap_entry[1]]))
|
)
|
||||||
logger.debug('evaluating query group mapping, filter: %s'%query_string)
|
)
|
||||||
results=company.query(ldap_config, query_string)
|
logger.debug('evaluating query group mapping, filter: %s' % query_string)
|
||||||
|
results = company.query(ldap_config, query_string)
|
||||||
logger.debug(results)
|
logger.debug(results)
|
||||||
return bool(results)
|
return bool(results)
|
||||||
|
|
|
@ -20,21 +20,20 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': "LDAP mapping for user name and e-mail",
|
'name': "LDAP mapping for user name and e-mail",
|
||||||
'version': "1.0",
|
'version': "1.0",
|
||||||
'depends': ["auth_ldap"],
|
'depends': ["auth_ldap"],
|
||||||
'author': "Daniel Reis (https://launchpad.com/~dreis-pt)",
|
'author': "Daniel Reis (https://launchpad.com/~dreis-pt)",
|
||||||
'description': """\
|
'description': """\
|
||||||
Allows to define the LDAP attributes to use to retrieve user name and e-mail address.
|
Allows to define the LDAP attributes to use to retrieve user name and e-mail address.
|
||||||
|
|
||||||
The default attribute used for the name is "cn".
|
The default attribute used for the name is "cn".
|
||||||
For Active Directory, you might prefer to use "displayName" instead.
|
For Active Directory, you might prefer to use "displayName" instead.
|
||||||
AD also supports the "mail" attribute, so it can be mapped into OpenERP.
|
AD also supports the "mail" attribute, so it can be mapped into OpenERP.
|
||||||
""",
|
""",
|
||||||
'category': "Tools",
|
'category': "Tools",
|
||||||
'data': [
|
'data': [
|
||||||
'users_ldap_view.xml',
|
'users_ldap_view.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
||||||
|
|
|
@ -24,13 +24,16 @@ from openerp.osv import fields, orm
|
||||||
import logging
|
import logging
|
||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CompanyLDAP(orm.Model):
|
class CompanyLDAP(orm.Model):
|
||||||
_inherit = 'res.company.ldap'
|
_inherit = 'res.company.ldap'
|
||||||
_columns = {
|
_columns = {
|
||||||
'name_attribute': fields.char('Name Attribute', size=64,
|
'name_attribute': fields.char(
|
||||||
|
'Name Attribute', size=64,
|
||||||
help="By default 'cn' is used. "
|
help="By default 'cn' is used. "
|
||||||
"For ActiveDirectory you might use 'displayName' instead."),
|
"For ActiveDirectory you might use 'displayName' instead."),
|
||||||
'mail_attribute': fields.char('E-mail attribute', size=64,
|
'mail_attribute': fields.char(
|
||||||
|
'E-mail attribute', size=64,
|
||||||
help="LDAP attribute to use to retrieve em-mail address."),
|
help="LDAP attribute to use to retrieve em-mail address."),
|
||||||
}
|
}
|
||||||
_defaults = {
|
_defaults = {
|
||||||
|
@ -71,4 +74,3 @@ class CompanyLDAP(orm.Model):
|
||||||
_log.warning('No LDAP attribute "%s" found for login "%s"' % (
|
_log.warning('No LDAP attribute "%s" found for login "%s"' % (
|
||||||
conf.get(conf_name), values.get('login')))
|
conf.get(conf_name), values.get('login')))
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,10 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from osv import osv, fields
|
from osv import orm, fields
|
||||||
|
|
||||||
class CompanyLDAPPopulateWizard(osv.TransientModel):
|
|
||||||
|
class CompanyLDAPPopulateWizard(orm.TransientModel):
|
||||||
_name = 'res.company.ldap.populate_wizard'
|
_name = 'res.company.ldap.populate_wizard'
|
||||||
_description = 'Populate users from LDAP'
|
_description = 'Populate users from LDAP'
|
||||||
_columns = {
|
_columns = {
|
||||||
|
@ -34,7 +35,6 @@ class CompanyLDAPPopulateWizard(osv.TransientModel):
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
def create(self, cr, uid, vals, context=None):
|
||||||
ldap_pool = self.pool.get('res.company.ldap')
|
ldap_pool = self.pool.get('res.company.ldap')
|
||||||
users_pool = self.pool.get('res.users')
|
|
||||||
if 'ldap_id' in vals:
|
if 'ldap_id' in vals:
|
||||||
vals['users_created'] = ldap_pool.action_populate(
|
vals['users_created'] = ldap_pool.action_populate(
|
||||||
cr, uid, vals['ldap_id'], context=context)
|
cr, uid, vals['ldap_id'], context=context)
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from ldap.filter import filter_format
|
from ldap.filter import filter_format
|
||||||
from openerp.osv import orm, fields
|
from openerp.osv import orm
|
||||||
import openerp.exceptions
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class CompanyLDAP(orm.Model):
|
class CompanyLDAP(orm.Model):
|
||||||
_inherit = 'res.company.ldap'
|
_inherit = 'res.company.ldap'
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class CompanyLDAP(orm.Model):
|
||||||
if attribute_match:
|
if attribute_match:
|
||||||
login_attr = attribute_match.group(1)
|
login_attr = attribute_match.group(1)
|
||||||
else:
|
else:
|
||||||
raise osv.except_osv(
|
raise orm.except_orm(
|
||||||
"No login attribute found",
|
"No login attribute found",
|
||||||
"Could not extract login attribute from filter %s" %
|
"Could not extract login attribute from filter %s" %
|
||||||
conf['ldap_filter'])
|
conf['ldap_filter'])
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
'category': 'Hidden',
|
'category': 'Hidden',
|
||||||
'author': 'Akretion',
|
'author': 'Akretion',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'description':"""
|
'description': """
|
||||||
Web Context Tunnel.
|
Web Context Tunnel.
|
||||||
===================
|
===================
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue