Exemplo n.º 1
0
    def __init__(self):
        """ Initialization """
        me = request.environ['pylons.routes_dict']['controller']
        action = request.environ['pylons.routes_dict']['action']

        log.debug("Controller: " + me)
        log.debug("Action: " + action)

        if (request.environ['pylons.routes_dict'].has_key("subaction")):
            action = request.environ['pylons.routes_dict']['subaction'] + action

        c.config = ControllerConfiguration(me, action)

        c.breadcrumb = BreadcrumbTrail(c.config)
        c.breadcrumb.build()

        c.samba_lp = param.LoadParm()
        c.samba_lp.load_default()

        self.__manager = SAMPipeManager(c.samba_lp)

        domains = self.__manager.fetch_and_get_domain_names()
        self.__manager.set_current_domain(0)
        self.__manager.fetch_users_and_groups()

        # FIXME just so that options may work
        c.current_page = int(request.params.get("page", 1))
        c.per_page = int(request.params.get("per_page", 10))
        c.filter_name = request.params.get("filter_value", "")
        c.filter_status = int(request.params.get("filter_status", -1))
Exemplo n.º 2
0
 def __init__(self):
     """ Initialization """
     me = request.environ['pylons.routes_dict']['controller']
     action = request.environ['pylons.routes_dict']['action']
     
     log.debug("Controller: " + me)
     log.debug("Action: " + action)
     
     if(request.environ['pylons.routes_dict'].has_key("subaction")):
         action = request.environ['pylons.routes_dict']['subaction'] + action
     
     c.config = ControllerConfiguration(me, action)
     
     c.breadcrumb = BreadcrumbTrail(c.config)
     c.breadcrumb.build()
         
     c.samba_lp = param.LoadParm()
     c.samba_lp.load_default()
     
     self.__manager = SAMPipeManager(c.samba_lp)
     
     domains = self.__manager.fetch_and_get_domain_names()
     self.__manager.set_current_domain(0)
     self.__manager.fetch_users_and_groups()
     
     # FIXME just so that options may work
     c.current_page = int(request.params.get("page", 1))
     c.per_page =  int(request.params.get("per_page", 10))
     c.filter_name = request.params.get("filter_value", "")
     c.filter_status = int(request.params.get("filter_status", -1))
Exemplo n.º 3
0
class AccountController(BaseController):
    """ Account Management Controller """
    def __init__(self):
        """ Initialization """
        me = request.environ['pylons.routes_dict']['controller']
        action = request.environ['pylons.routes_dict']['action']
        
        log.debug("Controller: " + me)
        log.debug("Action: " + action)
        
        if(request.environ['pylons.routes_dict'].has_key("subaction")):
            action = request.environ['pylons.routes_dict']['subaction'] + action
        
        c.config = ControllerConfiguration(me, action)
        
        c.breadcrumb = BreadcrumbTrail(c.config)
        c.breadcrumb.build()
            
        c.samba_lp = param.LoadParm()
        c.samba_lp.load_default()
        
        self.__manager = SAMPipeManager(c.samba_lp)
        
        domains = self.__manager.fetch_and_get_domain_names()
        self.__manager.set_current_domain(0)
        self.__manager.fetch_users_and_groups()
        
        # FIXME just so that options may work
        c.current_page = int(request.params.get("page", 1))
        c.per_page =  int(request.params.get("per_page", 10))
        c.filter_name = request.params.get("filter_value", "")
        c.filter_status = int(request.params.get("filter_status", -1))
        
    def index(self):
        c.user_list = self.__manager.user_list
        c.group_list = self.__manager.group_list
        
        c.list_users = True
        c.list_groups = True
        
        return render('/default/derived/account-dashboard.mako')
    
    def user(self, subaction="index", id=-1):
        id = int(id)        
        user_manager = UserManager(self.__manager)
        template = "/default/derived/account.mako"
        is_new = False
        
        c.user_list = self.__manager.user_list
        c.list_users = True
        c.list_groups = False
        
        if len(c.filter_name) > 0:
            c.user_list = self.__filter_users(c.user_list, c.filter_name)
        
        if c.filter_status != -1:
            if c.filter_status == 1:
                c.user_list = self.__manager.filter_enabled_disabled(True)
            elif c.filter_status == 0:
                c.user_list = self.__manager.filter_enabled_disabled(False)
                
        
        if id == -1:
            is_new = True

        ##
        ## Edit a User
        ##
        if subaction == "edit" or subaction == "add":
            c.p = ParamConfiguration('user-account-parameters')
            c.user = user_manager.edit(id, is_new)

            if c.user is not None:
                template = "/default/derived/edit-user-account.mako"
            else:
                type = "critical"
                cause = _("Unkown Reason")
                
                if group_manager.has_message():
                    cause = group_manager.get_message()
                
                message = _("Unable to get User to edit - %s" % (cause))
                SwatMessages.add(message, type)
        ##
        ## Save the changes made to a User
        ##
        elif subaction == "save" or subaction == "apply":
            (new_id, saved) = user_manager.save(id, is_new)
            
            if saved:
                type = "cool"
                message = _("Sucessfuly saved the User with the ID %s" % (new_id))
            else:
                type = "critical"
                cause = _("Unkown Reason")
                
                if user_manager.has_message():
                    cause = user_manager.get_message()
                
                message = _("Error saving the User with the ID %s: %s" % (new_id, cause))
                
            SwatMessages.add(message, type)
            
            if subaction == "save_add":
                redirect(url_for("with_subaction", controller='account', action="user", subaction="add"))
            elif subaction == "save":
                redirect(url(controller='account', action='user'))
            elif subaction == "apply":
                redirect(url("account_action", action='user', subaction='edit', id=new_id))
            
        ## 
        ## Remove a Certain User or a List of Users
        ## 
        elif subaction == "remove":
            list_uid = variabledecode.variable_decode(request.params).get("uid", id)
            ok_list = []
            
            if not isinstance(list_uid, list):
                list_uid = [list_uid]

            for uid in list_uid:
                uid = int(uid)
                removed = user_manager.remove(uid)

                if removed:
                    ok_list.append(uid)
                    log.info("Deleted " + str(uid) + " :: success: " + str(removed))
                else:
                    SwatMessages.add(user_manager.get_message(), "critical")
                    
            if len(ok_list) > 0:
                joined = ", ".join(["%d" % v for v in ok_list])
                
                if len(ok_list) == 1:
                    message = _("The User with the ID %s was deleted sucessfuly" \
                                % (joined))
                else:    
                    message = _("The Users IDs [%s] were deleted sucessfuly" \
                                % (joined))
                
                SwatMessages.add(message)
                
            redirect(url(controller='account', action='user'))
            
        ##
        ## Disable a User or a List of Users
        ##
        elif subaction == "toggle":
            list_uid = variabledecode.variable_decode(request.params).get("uid", id)
            enabled_list = []
            disabled_list = []
            
            if not isinstance(list_uid, list):
                list_uid = [list_uid]
                
            for uid in list_uid:
                uid = int(uid)
                (toggled, new_status) = user_manager.toggle(uid)

                if toggled:
                    if new_status == True:
                        disabled_list.append(uid)
                    else:
                        enabled_list.append(uid)
                else:
                    SwatMessages.add(_("Error toggling User ID %d: %s" % (uid, user_manager.get_message())), "critical")
                
            if len(enabled_list) > 0:
                joined = ", ".join(["%d" % v for v in enabled_list]) 
                message = _("The following User IDs [%s] were ENABLED successfuly" % (joined))
                SwatMessages.add(message)
                
            if len(disabled_list) > 0:
                joined = ", ".join(["%d" % v for v in disabled_list]) 
                message = _("The following User IDs [%s] were DISABLED successfuly" % (joined))
                SwatMessages.add(message)
                
            redirect(url(controller='account', action='user'))

        return render(template)
    
    def group(self, subaction="index", id=-1):
        id = int(id)        
        group_manager = GroupManager(self.__manager)
        template = '/default/derived/account.mako'
        is_new = False
        
        c.group_list = self.__manager.group_list
        c.list_users = False
        c.list_groups = True
        
        if len(c.filter_name) > 0:
            c.group_list = self.__filter_groups(c.group_list, c.filter_name)
        
        if id == -1:
            is_new = True
        
        ##
        ## Edit a Group
        ##
        if subaction == "edit" or subaction == "add":
            c.p = ParamConfiguration('group-parameters')
            c.group = group_manager.edit(id, is_new)

            if c.group is not None:
                c.user_group_list = self.__manager.get_users_in_group(id)
                template = "/default/derived/edit-group.mako"
            else:
                type = "critical"
                cause = _("Unkown Reason")
                
                if group_manager.has_message():
                    cause = group_manager.get_message()
                    
                message = _("Unable to get Group to edit - %s" % (cause))
                SwatMessages.add(message, type)

        ##
        ## Save the changes made to a Group
        ##
        elif subaction == "save" or subaction == "apply" or subaction == "save_add":
            (new_id, saved) = group_manager.save(id, is_new)
            
            if saved:
                type = "cool"
                message = _("Sucessfuly saved the Group with the ID %s" % (id))
            else:
                type = "critical"
                cause = _("Unkown Reason")
                
                if group_manager.has_message():
                    cause = group_manager.get_message()
                
                message = _("Error saving the Group with the ID %s: %s" % (id, cause))
                
            SwatMessages.add(message, type)
            
            if subaction == "save_add":
                redirect(url_for("with_subaction", controller='account', action="group", subaction="add"))
            elif subaction == "save":
                redirect(url(controller='account', action='group'))
            elif subaction == "apply":
                redirect(url("account_action", action='group', subaction='edit', id=new_id))
            
        ## 
        ## Remove a Certain Group
        ## 
        elif subaction == "remove":
            removed = group_manager.remove(id)
            
            if removed:
                type = "cool"
                message = _("Sucessfuly deleted the Group with the ID %s" % (id))
            else:
                type = "critical"
                cause = _("Unkown Reason")
                
                if group_manager.has_message():
                    cause = group_manager.get_message()
                
                message = _("Error deleting the Group with the ID %s - %s" % (id, cause))
                
            SwatMessages.add(message, type)
            redirect(url(controller='account', action='user'))

        return render(template)
        
    def save(self):
        """ """
        id = request.params.get("id", -1)
        
        action = request.environ['pylons.routes_dict']['action']
        task = request.params.get("task", "").strip().lower()
        type = request.params.get("type", "").strip().lower()

        if type == "user":
            self.user(action, id)
        elif type == "group":
            self.group(action, id)
    
    def apply(self):
        """ """
        self.save()
        
    def save_add(self):
        self.save()

    def cancel(self):
        """ """
        type = request.params.get("type", "").strip().lower()
        
        message = _("Editing canceled. No changes were saved.")
        SwatMessages.add(message, "warning")
        
        redirect(url(controller='account', action=type))
        
    def show_groups(self):
        """ """
        already_selected = request.params.get('as', '')
        log.debug("These are selected: " + already_selected)
        
        if len(already_selected) > 0:
            already_selected = already_selected.split(',')
        
        return render_mako_def('/default/component/popups.mako', \
                               'group_list', \
                               already_selected=already_selected)
        
    def __filter_groups(self, items, regex='.*'):
        """ TODO Must Improve """
        import re
        temp = []
        
        for item in items:
            if re.search(regex, item.name, re.IGNORECASE) is not None:
                temp.append(item)
                
        return temp
    
    def __filter_users(self, items, regex='.*'):
        """ TODO Must Improve """
        import re
        temp = []
        
        for item in items:
            if re.search(regex, item.username, re.IGNORECASE) is not None:
                temp.append(item)
                
        return temp
Exemplo n.º 4
0
class AccountController(BaseController):
    """ Account Management Controller """
    def __init__(self):
        """ Initialization """
        me = request.environ['pylons.routes_dict']['controller']
        action = request.environ['pylons.routes_dict']['action']

        log.debug("Controller: " + me)
        log.debug("Action: " + action)

        if (request.environ['pylons.routes_dict'].has_key("subaction")):
            action = request.environ['pylons.routes_dict']['subaction'] + action

        c.config = ControllerConfiguration(me, action)

        c.breadcrumb = BreadcrumbTrail(c.config)
        c.breadcrumb.build()

        c.samba_lp = param.LoadParm()
        c.samba_lp.load_default()

        self.__manager = SAMPipeManager(c.samba_lp)

        domains = self.__manager.fetch_and_get_domain_names()
        self.__manager.set_current_domain(0)
        self.__manager.fetch_users_and_groups()

        # FIXME just so that options may work
        c.current_page = int(request.params.get("page", 1))
        c.per_page = int(request.params.get("per_page", 10))
        c.filter_name = request.params.get("filter_value", "")
        c.filter_status = int(request.params.get("filter_status", -1))

    def index(self):
        c.user_list = self.__manager.user_list
        c.group_list = self.__manager.group_list

        c.list_users = True
        c.list_groups = True

        return render('/default/derived/account-dashboard.mako')

    def user(self, subaction="index", id=-1):
        id = int(id)
        user_manager = UserManager(self.__manager)
        template = "/default/derived/account.mako"
        is_new = False

        c.user_list = self.__manager.user_list
        c.list_users = True
        c.list_groups = False

        if len(c.filter_name) > 0:
            c.user_list = self.__filter_users(c.user_list, c.filter_name)

        if c.filter_status != -1:
            if c.filter_status == 1:
                c.user_list = self.__manager.filter_enabled_disabled(True)
            elif c.filter_status == 0:
                c.user_list = self.__manager.filter_enabled_disabled(False)

        if id == -1:
            is_new = True

        ##
        ## Edit a User
        ##
        if subaction == "edit" or subaction == "add":
            c.p = ParamConfiguration('user-account-parameters')
            c.user = user_manager.edit(id, is_new)

            if c.user is not None:
                template = "/default/derived/edit-user-account.mako"
            else:
                type = "critical"
                cause = _("Unkown Reason")

                if group_manager.has_message():
                    cause = group_manager.get_message()

                message = _("Unable to get User to edit - %s" % (cause))
                SwatMessages.add(message, type)
        ##
        ## Save the changes made to a User
        ##
        elif subaction == "save" or subaction == "apply":
            (new_id, saved) = user_manager.save(id, is_new)

            if saved:
                type = "cool"
                message = _("Sucessfuly saved the User with the ID %s" %
                            (new_id))
            else:
                type = "critical"
                cause = _("Unkown Reason")

                if user_manager.has_message():
                    cause = user_manager.get_message()

                message = _("Error saving the User with the ID %s: %s" %
                            (new_id, cause))

            SwatMessages.add(message, type)

            if subaction == "save_add":
                redirect_to(
                    url_for("with_subaction",
                            controller='account',
                            action="user",
                            subaction="add"))
            elif subaction == "save":
                redirect_to(controller='account', action='user')
            elif subaction == "apply":
                redirect_to("account_action",
                            action='user',
                            subaction='edit',
                            id=new_id)

        ##
        ## Remove a Certain User or a List of Users
        ##
        elif subaction == "remove":
            list_uid = variabledecode.variable_decode(request.params).get(
                "uid", id)
            ok_list = []

            if not isinstance(list_uid, list):
                list_uid = [list_uid]

            for uid in list_uid:
                uid = int(uid)
                removed = user_manager.remove(uid)

                if removed:
                    ok_list.append(uid)
                    log.info("Deleted " + str(uid) + " :: success: " +
                             str(removed))
                else:
                    SwatMessages.add(user_manager.get_message(), "critical")

            if len(ok_list) > 0:
                joined = ", ".join(["%d" % v for v in ok_list])

                if len(ok_list) == 1:
                    message = _("The User with the ID %s was deleted sucessfuly" \
                                % (joined))
                else:
                    message = _("The Users IDs [%s] were deleted sucessfuly" \
                                % (joined))

                SwatMessages.add(message)

            redirect_to(controller='account', action='user')

        ##
        ## Disable a User or a List of Users
        ##
        elif subaction == "toggle":
            list_uid = variabledecode.variable_decode(request.params).get(
                "uid", id)
            enabled_list = []
            disabled_list = []

            if not isinstance(list_uid, list):
                list_uid = [list_uid]

            for uid in list_uid:
                uid = int(uid)
                (toggled, new_status) = user_manager.toggle(uid)

                if toggled:
                    if new_status == True:
                        disabled_list.append(uid)
                    else:
                        enabled_list.append(uid)
                else:
                    SwatMessages.add(
                        _("Error toggling User ID %d: %s" %
                          (uid, user_manager.get_message())), "critical")

            if len(enabled_list) > 0:
                joined = ", ".join(["%d" % v for v in enabled_list])
                message = _(
                    "The following User IDs [%s] were ENABLED successfuly" %
                    (joined))
                SwatMessages.add(message)

            if len(disabled_list) > 0:
                joined = ", ".join(["%d" % v for v in disabled_list])
                message = _(
                    "The following User IDs [%s] were DISABLED successfuly" %
                    (joined))
                SwatMessages.add(message)

            redirect_to(controller='account', action='user')

        return render(template)

    def group(self, subaction="index", id=-1):
        id = int(id)
        group_manager = GroupManager(self.__manager)
        template = '/default/derived/account.mako'
        is_new = False

        c.group_list = self.__manager.group_list
        c.list_users = False
        c.list_groups = True

        if len(c.filter_name) > 0:
            c.group_list = self.__filter_groups(c.group_list, c.filter_name)

        if id == -1:
            is_new = True

        ##
        ## Edit a Group
        ##
        if subaction == "edit" or subaction == "add":
            c.p = ParamConfiguration('group-parameters')
            c.group = group_manager.edit(id, is_new)

            if c.group is not None:
                c.user_group_list = self.__manager.get_users_in_group(id)
                template = "/default/derived/edit-group.mako"
            else:
                type = "critical"
                cause = _("Unkown Reason")

                if group_manager.has_message():
                    cause = group_manager.get_message()

                message = _("Unable to get Group to edit - %s" % (cause))
                SwatMessages.add(message, type)

        ##
        ## Save the changes made to a Group
        ##
        elif subaction == "save" or subaction == "apply" or subaction == "save_add":
            (new_id, saved) = group_manager.save(id, is_new)

            if saved:
                type = "cool"
                message = _("Sucessfuly saved the Group with the ID %s" % (id))
            else:
                type = "critical"
                cause = _("Unkown Reason")

                if group_manager.has_message():
                    cause = group_manager.get_message()

                message = _("Error saving the Group with the ID %s: %s" %
                            (id, cause))

            SwatMessages.add(message, type)

            if subaction == "save_add":
                redirect_to(
                    url_for("with_subaction",
                            controller='account',
                            action="group",
                            subaction="add"))
            elif subaction == "save":
                redirect_to(controller='account', action='group')
            elif subaction == "apply":
                redirect_to("account_action",
                            action='group',
                            subaction='edit',
                            id=new_id)

        ##
        ## Remove a Certain Group
        ##
        elif subaction == "remove":
            removed = group_manager.remove(id)

            if removed:
                type = "cool"
                message = _("Sucessfuly deleted the Group with the ID %s" %
                            (id))
            else:
                type = "critical"
                cause = _("Unkown Reason")

                if group_manager.has_message():
                    cause = group_manager.get_message()

                message = _("Error deleting the Group with the ID %s - %s" %
                            (id, cause))

            SwatMessages.add(message, type)
            redirect_to(controller='account', action='user')

        return render(template)

    def save(self):
        """ """
        id = request.params.get("id", -1)

        action = request.environ['pylons.routes_dict']['action']
        task = request.params.get("task", "").strip().lower()
        type = request.params.get("type", "").strip().lower()

        if type == "user":
            self.user(action, id)
        elif type == "group":
            self.group(action, id)

    def apply(self):
        """ """
        self.save()

    def save_add(self):
        self.save()

    def cancel(self):
        """ """
        type = request.params.get("type", "").strip().lower()

        message = _("Editing canceled. No changes were saved.")
        SwatMessages.add(message, "warning")

        redirect_to(controller='account', action=type)

    def show_groups(self):
        """ """
        already_selected = request.params.get('as', '')
        log.debug("These are selected: " + already_selected)

        if len(already_selected) > 0:
            already_selected = already_selected.split(',')

        return render_mako_def('/default/component/popups.mako', \
                               'group_list', \
                               already_selected=already_selected)

    def __filter_groups(self, items, regex='.*'):
        """ TODO Must Improve """
        import re
        temp = []

        for item in items:
            if re.search(regex, item.name, re.IGNORECASE) is not None:
                temp.append(item)

        return temp

    def __filter_users(self, items, regex='.*'):
        """ TODO Must Improve """
        import re
        temp = []

        for item in items:
            if re.search(regex, item.username, re.IGNORECASE) is not None:
                temp.append(item)

        return temp