Revisión 76
Añadido por Manu Mora Gordillo hace alrededor de 14 años
Groups.py | ||
---|---|---|
# 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 ControlAula. If not, see <http://www.gnu.org/licenses/>.
|
||
# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
|
||
#
|
||
##############################################################################
|
||
|
||
... | ... | |
import logging
|
||
from math import ceil
|
||
from operator import itemgetter
|
||
from Utils import Utils
|
||
|
||
class Groups(object):
|
||
|
||
def __init__(self):
|
||
pass
|
||
|
||
def __init__(self,ldap,type,name):
|
||
def __init__(self,ldap,type,name,users):
|
||
self.ldap = ldap
|
||
self.type = type
|
||
self.name = name
|
||
|
||
self.users = users
|
||
|
||
def validation(self,action):
|
||
|
||
if action == "add":
|
||
... | ... | |
|
||
if self.name == "":
|
||
return "name"
|
||
|
||
|
||
if self.users == "":
|
||
return "users"
|
||
|
||
return "OK"
|
||
|
||
def process(self,action):
|
||
... | ... | |
|
||
if action == "modify":
|
||
val = self.validation(action)
|
||
|
||
|
||
if val != "OK":
|
||
return val
|
||
else:
|
||
... | ... | |
def add(self):
|
||
maxID = str(self.getMaxID())
|
||
|
||
members = []
|
||
for m in self.users.split(','):
|
||
members.append("uid=" + m + ",ou=People,dc=instituto,dc=extremadura,dc=es")
|
||
|
||
attr = [
|
||
('objectclass', ['top','posixGroup','lisGroup','lisAclGroup']),
|
||
#('objectclass', ['top','posixGroup','lisGroup']),
|
||
('grouptype', [self.type] ),
|
||
('gidnumber', [maxID] ),
|
||
('cn', [self.name] ),
|
||
('description', [self.name+' department group']),
|
||
('memberuid', ['manuprofe']),
|
||
('member', ['uid=manuprofe,ou=People,dc=instituto,dc=extremadura,dc=es'])
|
||
('memberuid', self.users.split(',')),
|
||
('member', members)
|
||
]
|
||
|
||
self.ldap.add("cn="+self.name+",ou=Group", attr)
|
||
|
||
return "OK"
|
||
|
||
|
||
def modify(self):
|
||
print "llego"
|
||
mod_attrs = [
|
||
(ldap.MOD_ADD, 'description', 'Author of New Organon'),
|
||
(ldap.MOD_ADD, 'description', 'British empiricist')
|
||
(ldap.MOD_REPLACE, 'memberuid', 'Author of New Organon'),
|
||
(ldap.MOD_REPLACE, 'member', 'British empiricist')
|
||
]
|
||
self.ldap.modify_s('uid='+ uid +',ou=Group', mod_attrs)
|
||
|
||
#self.ldap.modify_s('uid='+ self.name +',ou=Group', mod_attrs)
|
||
|
||
currentUsers = self.getGroupUsers()
|
||
print currentUsers
|
||
|
||
|
||
def delete(self):
|
||
self.ldap.delete('cn='+ self.name +',ou=Group')
|
||
|
||
... | ... | |
maxID = numbers[len(numbers)-1] + 1
|
||
|
||
return maxID
|
||
|
||
|
||
def getGroupUsers(self):
|
||
result = self.ldap.search("ou=Group","cn="+self.name,["cn","memberUid"])
|
||
|
||
members = []
|
||
for m in result:
|
||
members.append(m[0][1]["memberUid"][0])
|
||
|
||
members.sort()
|
||
|
||
return members
|
Exportar a: Unified diff
Sigo con los grupos