2013-01-14 22:22:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from tg import session
|
|
|
|
from tg.controllers import redirect
|
|
|
|
from tg.decorators import expose, validate
|
|
|
|
|
|
|
|
from brie.config import ldap_config
|
|
|
|
from brie.lib.ldap_helper import *
|
2013-09-09 15:17:22 +00:00
|
|
|
from brie.lib.aurore_helper import *
|
2013-01-14 22:22:41 +00:00
|
|
|
from brie.model.ldap import *
|
|
|
|
|
|
|
|
from brie.controllers import auth
|
|
|
|
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
|
|
|
|
|
|
|
|
from operator import itemgetter
|
|
|
|
|
|
|
|
|
|
|
|
class GroupAddMemberController(AuthenticatedRestController):
|
|
|
|
|
|
|
|
@expose()
|
|
|
|
def post(self, group_cn, user_dn):
|
2013-02-16 08:32:02 +00:00
|
|
|
groups_of_user = Groupes.get_by_user_dn(self.user, self.user.residence_dn, user_dn)
|
2013-01-14 22:22:41 +00:00
|
|
|
|
|
|
|
if group_cn in groups_of_user:
|
|
|
|
redirect("/administration/")
|
|
|
|
#end if
|
|
|
|
|
2013-02-16 08:32:02 +00:00
|
|
|
target_group = Groupes.get_by_cn(self.user, self.user.residence_dn, group_cn)
|
2013-01-14 22:22:41 +00:00
|
|
|
|
|
|
|
if target_group is None:
|
|
|
|
redirect("/administration/")
|
|
|
|
#end if
|
|
|
|
|
|
|
|
attr = Groupes.unique_member_attr(user_dn)
|
|
|
|
self.user.ldap_bind.add_attr(target_group.dn, attr)
|
|
|
|
|
|
|
|
redirect("/administration/")
|
|
|
|
#end def
|
|
|
|
|
|
|
|
#end class
|
|
|
|
|
|
|
|
class GroupController(AuthenticatedBaseController):
|
|
|
|
add_member = GroupAddMemberController()
|
|
|
|
|
|
|
|
@expose()
|
|
|
|
def delete_member(self, group_cn, user_dn):
|
2013-02-16 08:32:02 +00:00
|
|
|
groups_of_user = Groupes.get_by_user_dn(self.user, self.user.residence_dn, user_dn)
|
2013-01-14 22:22:41 +00:00
|
|
|
|
|
|
|
if group_cn in groups_of_user:
|
2013-02-16 08:32:02 +00:00
|
|
|
target_group = Groupes.get_by_cn(self.user, self.user.residence_dn, group_cn)
|
2013-01-14 22:22:41 +00:00
|
|
|
|
|
|
|
attr = Groupes.unique_member_attr(user_dn)
|
|
|
|
self.user.ldap_bind.delete_attr(target_group.dn, attr)
|
|
|
|
#end if
|
|
|
|
|
|
|
|
redirect("/administration/")
|
|
|
|
#end def
|
|
|
|
|
|
|
|
#end class
|
|
|
|
|
|
|
|
|
|
|
|
class AdministrationController(AuthenticatedBaseController):
|
|
|
|
groups = GroupController()
|
|
|
|
|
|
|
|
@expose("brie.templates.show.error")
|
|
|
|
def error_no_entry(self):
|
|
|
|
return { "error" : "Entrée non existante" }
|
|
|
|
|
|
|
|
@expose("brie.templates.administration.index")
|
|
|
|
def index(self):
|
2013-02-16 08:32:02 +00:00
|
|
|
groups = Groupes.get_all(self.user, self.user.residence_dn)
|
|
|
|
all_users = sorted(Member.get_all(self.user, self.user.residence_dn), key=lambda u: u.cn.first())
|
2013-01-14 22:22:41 +00:00
|
|
|
|
2013-09-09 15:17:22 +00:00
|
|
|
residence = None
|
|
|
|
if self.user is not None:
|
|
|
|
residence = Residences.get_name_by_dn(self.user, self.user.residence_dn)
|
|
|
|
#end if
|
|
|
|
|
|
|
|
return {
|
|
|
|
"user" : self.user,
|
|
|
|
"residence" : residence,
|
|
|
|
"groups_ldap" : groups,
|
|
|
|
"all_users" : all_users
|
|
|
|
}
|
2013-01-14 22:22:41 +00:00
|
|
|
#end def
|
|
|
|
#end class
|
|
|
|
|