2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
2013-09-18 05:06:07 -05:00
|
|
|
# This file is part of Appy, a framework for building applications in the Python
|
|
|
|
# language. Copyright (C) 2007 Gaetan Delannay
|
|
|
|
|
|
|
|
# Appy is free software; you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
|
|
|
|
# Appy is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Appy. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-29 07:06:01 -05:00
|
|
|
|
2013-07-08 16:39:16 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Import stuff from appy.fields (and from a few other places too).
|
|
|
|
# This way, when an app gets "from appy.gen import *", everything is available.
|
2013-09-18 05:06:07 -05:00
|
|
|
from appy import Object
|
|
|
|
from appy.px import Px
|
2013-08-21 06:54:56 -05:00
|
|
|
from appy.fields import Field
|
2013-07-08 16:39:16 -05:00
|
|
|
from appy.fields.action import Action
|
|
|
|
from appy.fields.boolean import Boolean
|
|
|
|
from appy.fields.computed import Computed
|
|
|
|
from appy.fields.date import Date
|
|
|
|
from appy.fields.file import File
|
|
|
|
from appy.fields.float import Float
|
|
|
|
from appy.fields.info import Info
|
|
|
|
from appy.fields.integer import Integer
|
|
|
|
from appy.fields.list import List
|
|
|
|
from appy.fields.pod import Pod
|
|
|
|
from appy.fields.ref import Ref, autoref
|
|
|
|
from appy.fields.string import String, Selection
|
2013-08-21 06:54:56 -05:00
|
|
|
from appy.fields.search import Search, UiSearch
|
|
|
|
from appy.fields.group import Group, Column
|
|
|
|
from appy.fields.page import Page
|
|
|
|
from appy.fields.phase import Phase
|
2013-09-18 05:06:07 -05:00
|
|
|
from appy.fields.workflow import *
|
2013-07-08 16:39:16 -05:00
|
|
|
from appy.gen.layout import Table
|
2013-09-18 05:06:07 -05:00
|
|
|
from appy.gen.utils import No
|
2010-08-05 11:23:17 -05:00
|
|
|
|
2014-03-05 09:48:54 -06:00
|
|
|
# Make the following classes available here: people may need to override some
|
|
|
|
# of their PXs (defined as static attributes).
|
2014-02-26 16:40:27 -06:00
|
|
|
from appy.gen.wrappers import AbstractWrapper as BaseObject
|
|
|
|
from appy.gen.wrappers.ToolWrapper import ToolWrapper as BaseTool
|
|
|
|
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
2010-09-02 09:16:08 -05:00
|
|
|
class Model: pass
|
|
|
|
class Tool(Model):
|
2014-03-05 09:48:54 -06:00
|
|
|
'''Subclass me to extend or modify the Tool class.'''
|
2010-09-02 09:16:08 -05:00
|
|
|
class User(Model):
|
2014-03-05 09:48:54 -06:00
|
|
|
'''Subclass me to extend or modify the User class.'''
|
2009-06-29 07:06:01 -05:00
|
|
|
|
2013-07-24 08:53:19 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
class LdapConfig:
|
2013-09-06 09:19:56 -05:00
|
|
|
'''Parameters for authenticating users to an LDAP server.'''
|
|
|
|
ldapAttributes = { 'loginAttribute':None, 'emailAttribute':'email',
|
|
|
|
'fullNameAttribute':'title',
|
|
|
|
'firstNameAttribute':'firstName',
|
|
|
|
'lastNameAttribute':'name' }
|
|
|
|
|
2013-09-05 03:42:19 -05:00
|
|
|
def __init__(self):
|
|
|
|
self.server = '' # Name of the LDAP server
|
|
|
|
self.port = None # Port for this server.
|
|
|
|
# Login and password of the technical power user that the Appy
|
|
|
|
# application will use to connect to the LDAP.
|
|
|
|
self.adminLogin = ''
|
|
|
|
self.adminPassword = ''
|
|
|
|
# LDAP attribute to use as login for authenticating users.
|
|
|
|
self.loginAttribute = 'dn' # Can also be "mail", "sAMAccountName", "cn"
|
2013-09-06 09:19:56 -05:00
|
|
|
# LDAP attributes for storing email
|
|
|
|
self.emailAttribute = None
|
|
|
|
# LDAP attribute for storing full name (first + last name)
|
|
|
|
self.fullNameAttribute = None
|
|
|
|
# Alternately, LDAP attributes for storing 1st & last names separately.
|
|
|
|
self.firstNameAttribute = None
|
|
|
|
self.lastNameAttribute = None
|
|
|
|
# LDAP classes defining the users stored in the LDAP.
|
|
|
|
self.userClasses = ('top', 'person')
|
|
|
|
self.baseDn = '' # Base DN where to find users in the LDAP.
|
|
|
|
self.scope = 'SUBTREE' # Scope of the search within self.baseDn
|
2013-09-05 03:42:19 -05:00
|
|
|
|
|
|
|
def getServerUri(self):
|
|
|
|
'''Returns the complete URI for accessing the LDAP, ie
|
|
|
|
"ldap://some.ldap.server:389".'''
|
|
|
|
port = self.port or 389
|
|
|
|
return 'ldap://%s:%d' % (self.server, port)
|
2013-07-24 08:53:19 -05:00
|
|
|
|
2013-09-06 09:19:56 -05:00
|
|
|
def getUserFilterValues(self, login):
|
|
|
|
'''Gets the filter values required to perform a query for finding user
|
|
|
|
corresponding to p_login in the LDAP.'''
|
|
|
|
res = [(self.loginAttribute, login)]
|
|
|
|
for userClass in self.userClasses:
|
|
|
|
res.append( ('objectClass', userClass) )
|
|
|
|
return res
|
|
|
|
|
|
|
|
def getUserAttributes(self):
|
|
|
|
'''Gets the attributes we want to get from the LDAP for characterizing
|
|
|
|
a user.'''
|
2013-09-09 16:14:50 -05:00
|
|
|
res = []
|
2013-09-06 09:19:56 -05:00
|
|
|
for name in self.ldapAttributes.iterkeys():
|
|
|
|
if getattr(self, name):
|
|
|
|
res.append(getattr(self, name))
|
|
|
|
return res
|
|
|
|
|
|
|
|
def getUserParams(self, ldapData):
|
|
|
|
'''Formats the user-related p_ldapData retrieved from the ldap, as a
|
|
|
|
dict of params usable for creating or updating the corresponding
|
|
|
|
Appy user.'''
|
|
|
|
res = {}
|
|
|
|
for name, appyName in self.ldapAttributes.iteritems():
|
|
|
|
if not appyName: continue
|
|
|
|
# Get the name of the attribute as known in the LDAP.
|
|
|
|
ldapName = getattr(self, name)
|
|
|
|
if not ldapName: continue
|
|
|
|
if ldapData.has_key(ldapName) and ldapData[ldapName]:
|
2013-09-09 16:14:50 -05:00
|
|
|
value = ldapData[ldapName]
|
|
|
|
if isinstance(value, list): value = value[0]
|
|
|
|
res[appyName] = value
|
2013-09-06 09:19:56 -05:00
|
|
|
return res
|
|
|
|
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
class Config:
|
|
|
|
'''If you want to specify some configuration parameters for appy.gen and
|
2013-07-24 08:53:19 -05:00
|
|
|
your application, please create a class named "Config" in the __init__.py
|
|
|
|
file of your application and override some of the attributes defined
|
|
|
|
here, ie:
|
|
|
|
|
|
|
|
import appy.gen
|
|
|
|
class Config(appy.gen.Config):
|
|
|
|
langages = ('en', 'fr')
|
|
|
|
'''
|
2014-01-20 09:30:14 -06:00
|
|
|
# What skin to use for the web interface? Appy has 2 skins: the default
|
|
|
|
# one (with a fixed width) and the "wide" skin (takes the whole page width).
|
|
|
|
skin = None # None means: the default one. Could be "wide".
|
2013-07-24 08:53:19 -05:00
|
|
|
# For every language code that you specify in this list, appy.gen will
|
|
|
|
# produce and maintain translation files.
|
|
|
|
languages = ['en']
|
|
|
|
# If languageSelector is True, on every page, a language selector will
|
|
|
|
# allow to switch between languages defined in self.languages. Else,
|
|
|
|
# the browser-defined language will be used for choosing the language
|
|
|
|
# of returned pages.
|
|
|
|
languageSelector = False
|
|
|
|
# People having one of these roles will be able to create instances
|
|
|
|
# of classes defined in your application.
|
2013-08-23 11:57:27 -05:00
|
|
|
defaultCreators = ['Manager']
|
2014-03-03 11:54:21 -06:00
|
|
|
# The "root" classes are those that will get their menu in the user
|
|
|
|
# interface. Put their names in the list below.
|
|
|
|
rootClasses = []
|
2013-07-24 08:53:19 -05:00
|
|
|
# Number of translations for every page on a Translation object
|
|
|
|
translationsPerPage = 30
|
|
|
|
# Language that will be used as a basis for translating to other
|
|
|
|
# languages.
|
|
|
|
sourceLanguage = 'en'
|
|
|
|
# Activate or not the button on home page for asking a new password
|
|
|
|
activateForgotPassword = True
|
|
|
|
# Enable session timeout?
|
|
|
|
enableSessionTimeout = False
|
|
|
|
# If the following field is True, the login/password widget will be
|
|
|
|
# discreet. This is for sites where authentication is not foreseen for
|
|
|
|
# the majority of visitors (just for some administrators).
|
|
|
|
discreetLogin = False
|
|
|
|
# When using Ogone, place an instance of appy.gen.ogone.OgoneConfig in
|
|
|
|
# the field below.
|
|
|
|
ogone = None
|
|
|
|
# When using Google analytics, specify here the Analytics ID
|
|
|
|
googleAnalyticsId = None
|
|
|
|
# Create a group for every global role?
|
|
|
|
groupsForGlobalRoles = False
|
|
|
|
# When using a LDAP for authenticating users, place an instance of class
|
|
|
|
# LdapConfig above in the field below.
|
|
|
|
ldap = None
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|