示例#1
0
    def edit(self, name, is_new=False):
        """ Edit a share. Loads the Share Edition Template.
        
        Keyword arguments:
        name -- the share name to load the information from
        is_new -- indicated if we are adding a share of editing
        
        """
        log.debug("Editing share " + name)
        log.debug("Is the Share New? " + str(is_new))
        
        backend = globals()["ShareBackend" + c.samba_lp.get("share backend").title()](c.samba_lp, {})

        if c.samba_lp.get("share backend") in self.__supported_backends:
            if backend.share_name_exists(name) == False and not is_new:
                log.warning("Share " + name + " doesn't exist in the chosen backend")
                
                message = _("Can't edit a Share that doesn't exist")
                SwatMessages.add(message, "warning")
                
                redirect_to(controller='share', action='index')
            else:
                c.p = ParamConfiguration('share-parameters')
                
                if is_new:
                    c.share = SambaShare()
                else:
                    c.share = backend.get_share_by_name(name)

                return render('/default/derived/edit-share.mako')
        else:
            message = _("Your chosen backend is not yet supported")
            SwatMessages.add(message, "critical")
            
            redirect_to(controller='share', action='index')
示例#2
0
文件: share.py 项目: Schu23/GSoC-SWAT
    def index(self):
        """ Point of entry. Loads the Share List Template """
        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_shares", "")
        c.share_list = []

        if c.samba_lp.get("share backend") in self.__supported_backends:
            backend = globals()["ShareBackend" +
                                c.samba_lp.get("share backend").title()](
                                    c.samba_lp, {})

            if len(c.filter_name) > 0:
                c.share_list = filter_list(backend.get_share_list(),
                                           c.filter_name)
                c.breadcrumb.add(
                    _("Filtered By") + " " + c.filter_name,
                    request.environ['pylons.routes_dict']['controller'],
                    request.environ['pylons.routes_dict']['action'])
            else:
                c.share_list = backend.get_share_list()
        else:
            message = _("Your chosen backend is not yet supported")
            SwatMessages.add(message, "critical")

        return render('/default/derived/share.mako')
示例#3
0
    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)
示例#4
0
文件: account.py 项目: jelmer/swat2
 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))
示例#5
0
文件: share.py 项目: Schu23/GSoC-SWAT
    def cancel(self, name=''):
        """ Cancel the current editing/addition of the current Share """
        task = request.params.get("task", "edit")

        if task == "add":
            message = _("Cancelled New Share. No Share was added!")
        elif task == "edit":
            message = _("Cancelled Share editing. No changes were saved!")

        SwatMessages.add(message, "warning")
        redirect_to(controller='share', action='index')
示例#6
0
 def cancel(self, name=''):
     """ Cancel the current editing/addition of the current Share """
     task = request.params.get("task", "edit")
     
     if task == "add":
         message = _("Cancelled New Share. No Share was added!")
     elif task == "edit":
         message = _("Cancelled Share editing. No changes were saved!")
     
     SwatMessages.add(message, "warning")
     redirect_to(controller='share', action='index')
示例#7
0
    def index(self):
        from authkit.permissions import NotAuthenticatedError

        if not request.environ.has_key('REMOTE_USER'):
            SwatMessages.add(
                _("You must be authenticated to perform that action"),
                "critical")
            abort(401)
# raise NotAuthenticatedError('Not Authenticated')

#identity = request.environ.get('repoze.who.identity')

#if identity is None:
#  SwatMessages.add(_("You must be authenticated to perform that action"), "critical")
#  abort(401)
        """ The default Dashboard. The entry point for SWAT """
        return render('/default/derived/dashboard.mako')
示例#8
0
    def index(self):
        from authkit.permissions import NotAuthenticatedError
        
        if not request.environ.has_key('REMOTE_USER'):
            SwatMessages.add(_("You must be authenticated to perform that action"), "critical")
            abort(401)
	   # raise NotAuthenticatedError('Not Authenticated')

        
        
        #identity = request.environ.get('repoze.who.identity')
        
        #if identity is None:
          #  SwatMessages.add(_("You must be authenticated to perform that action"), "critical")
          #  abort(401)
        
        """ The default Dashboard. The entry point for SWAT """
        return render('/default/derived/dashboard.mako')
示例#9
0
文件: share.py 项目: Schu23/GSoC-SWAT
    def save(self):
        """ Save a Share. We enter here either from the "edit" or "add" """
        action = request.environ['pylons.routes_dict']['action']
        task = request.params.get("task", "edit")

        share_name = request.params.get("name", "").strip()
        share_old_name = request.params.get("old_name", "").strip()

        is_new = False
        stored = False

        has_error = False

        if task == "add":
            is_new = True

        log.debug("Task is: " + task)
        log.debug("Is the share we are saving new? " + str(is_new))

        if len(share_name) > 0:
            if c.samba_lp.get("share backend") in self.__supported_backends:
                backend = globals()[self.__backend](c.samba_lp, request.params)
                stored = backend.store(share_name, is_new, share_old_name)

                if stored:
                    message = _("Share Information was Saved")
                    SwatMessages.add(message)
                else:
                    SwatMessages.add(backend.get_error_message(), \
                                     backend.get_error_type())
            else:
                message = _("Your chosen backend is not yet supported")
                SwatMessages.add(message, "critical")
                has_error = True
        else:
            message = _("The share name is empty. You cannot save this share")
            SwatMessages.add(message, "critical")
            has_error = True

        if has_error or not stored:
            if is_new and len(share_name) == 0:
                redirect_to(controller='share', action='add')
            elif len(share_old_name) == 0:
                redirect_to(controller='share', action='index')
            else:
                redirect_to(controller='share', action='edit', \
                            name=share_old_name)
        elif action == "save" and stored:
            redirect_to(controller='share', action='index')
        elif action == "apply" and stored:
            redirect_to(controller='share', action='edit', name=share_name)
        else:
            redirect_to(controller='share', action='add')
示例#10
0
    def save(self):
        """ Save a Share. We enter here either from the "edit" or "add" """
        action = request.environ['pylons.routes_dict']['action']
        task = request.params.get("task", "edit")
        
        share_name = request.params.get("name", "").strip()
        share_old_name = request.params.get("old_name", "").strip()
        
        is_new = False
        stored = False
        
        has_error = False
                
        if task == "add":
            is_new = True
        
        log.debug("Task is: " + task)    
        log.debug("Is the share we are saving new? " + str(is_new))
        
        if len(share_name) > 0:
            if c.samba_lp.get("share backend") in self.__supported_backends:
                    backend = globals()[self.__backend](c.samba_lp, request.params)
                    stored = backend.store(share_name, is_new, share_old_name)
                    
                    if stored:
                        message = _("Share Information was Saved")
                        SwatMessages.add(message)
                    else:
                        SwatMessages.add(backend.get_error_message(), \
                                         backend.get_error_type())
            else:
                message = _("Your chosen backend is not yet supported")
                SwatMessages.add(message, "critical")
                has_error = True
        else:
            message = _("The share name is empty. You cannot save this share");
            SwatMessages.add(message, "critical")
            has_error = True

        if has_error or not stored:
            if is_new and len(share_name) == 0:
                redirect_to(controller='share', action='add')
            elif len(share_old_name) == 0:
                redirect_to(controller='share', action='index')
            else:
                redirect_to(controller='share', action='edit', \
                            name=share_old_name)
        elif action == "save" and stored:
            redirect_to(controller='share', action='index')
        elif action == "apply" and stored:
            redirect_to(controller='share', action='edit', name=share_name)
        else:
            redirect_to(controller='share', action='add')
示例#11
0
 def index(self):        
     """ Point of entry. Loads the Share List Template """
     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_shares", "")
     c.share_list = []
     
     if c.samba_lp.get("share backend") in self.__supported_backends:
         backend = globals()["ShareBackend" + c.samba_lp.get("share backend").title()](c.samba_lp, {})
 
         if len(c.filter_name) > 0:
             c.share_list = filter_list(backend.get_share_list(), c.filter_name)            
             c.breadcrumb.add(_("Filtered By") + " " + c.filter_name, request.environ['pylons.routes_dict']['controller'], request.environ['pylons.routes_dict']['action'])
         else:
             c.share_list = backend.get_share_list()
     else:
         message = _("Your chosen backend is not yet supported")
         SwatMessages.add(message, "critical")
     
     return render('/default/derived/share.mako')
示例#12
0
文件: share.py 项目: Schu23/GSoC-SWAT
    def homes(self):
        """ Toggles the homes Share """
        share_name = "homes"
        is_new = True

        if c.samba_lp.get("share backend") in self.__supported_backends:
            backend = globals()[self.__backend](c.samba_lp, request.params)
            active = False

            if not backend.share_name_exists(share_name):
                if backend.store(share_name, is_new):
                    active = True
            else:
                backend.delete(share_name)

            if active:
                SwatMessages.add(_("Homes Share Enabled"))
            else:
                SwatMessages.add(_("Homes Share Disabled"))
        else:
            message = _("Your chosen backend is not yet supported")
            SwatMessages.add(message, "critical")
            has_error = True

        redirect_to(controller='share', action='index')
示例#13
0
 def homes(self):
     """ Toggles the homes Share """
     share_name = "homes"
     is_new = True
     
     if c.samba_lp.get("share backend") in self.__supported_backends:
             backend = globals()[self.__backend](c.samba_lp, request.params)
             active = False
             
             if not backend.share_name_exists(share_name):
                 if backend.store(share_name, is_new):
                     active = True
             else:
                 backend.delete(share_name)    
             
             if active:
                 SwatMessages.add(_("Homes Share Enabled"))
             else:
                 SwatMessages.add(_("Homes Share Disabled"))
     else:
         message = _("Your chosen backend is not yet supported")
         SwatMessages.add(message, "critical")
         has_error = True
         
     redirect_to(controller='share', action='index')
示例#14
0
文件: share.py 项目: Schu23/GSoC-SWAT
    def toggle(self, name=''):
        """ Toggles a Share's state (enabled/disabled).
        
        At the moment it is disabled because I'm not sure how I can implement
        this sucessfuly.
        
        Keyword arguments:
        name -- the name of the share to be toggled
        
        """
        if c.samba_lp.get("share backend") in self.__supported_backends:
            backend = globals()[self.__backend](c.samba_lp, {'name': name})
            toggled = backend.toggle()

            if toggled:
                message = _("Share Toggled successfuly")
                SwatMessages.add(message)
            else:
                SwatMessages.add(backend.get_error_message(),
                                 backend.get_error_type())
        else:
            message = _("Your chosen backend is not yet supported")
            SwatMessages.add(message, "critical")

        redirect_to(controller='share', action='index')
示例#15
0
文件: share.py 项目: Schu23/GSoC-SWAT
    def edit(self, name, is_new=False):
        """ Edit a share. Loads the Share Edition Template.
        
        Keyword arguments:
        name -- the share name to load the information from
        is_new -- indicated if we are adding a share of editing
        
        """
        log.debug("Editing share " + name)
        log.debug("Is the Share New? " + str(is_new))

        backend = globals()["ShareBackend" +
                            c.samba_lp.get("share backend").title()](
                                c.samba_lp, {})

        if c.samba_lp.get("share backend") in self.__supported_backends:
            if backend.share_name_exists(name) == False and not is_new:
                log.warning("Share " + name +
                            " doesn't exist in the chosen backend")

                message = _("Can't edit a Share that doesn't exist")
                SwatMessages.add(message, "warning")

                redirect_to(controller='share', action='index')
            else:
                c.p = ParamConfiguration('share-parameters')

                if is_new:
                    c.share = SambaShare()
                else:
                    c.share = backend.get_share_by_name(name)

                return render('/default/derived/edit-share.mako')
        else:
            message = _("Your chosen backend is not yet supported")
            SwatMessages.add(message, "critical")

            redirect_to(controller='share', action='index')
示例#16
0
    def __authenticate(self):
        """ Performs the custom authentication. This method is required by
        repoze and we are sent here by it.
        
        Keyword arguments
        environ -- WSGI environment (request.environ)
        identify -- credentials entered by the user
        
        In case of sucess it returns the username of the user that attempted
        to login otherwise None
        
        TODO: Add i18n here
        BUG: Can't add i18n because for some reason the pylons imports don't
        work here. Maybe I'm using repoze.who wrong?
        
        """
        username = request.params.get("login", "").strip()
        password = request.params.get("password", "").strip()

        len_username = len(username)
        len_password = len(password)

        if len_username == 0:
            SwatMessages.add('Username cannot be empty', 'critical')
            return False

        if len_password == 0:
            SwatMessages.add('Password cannot be empty', 'critical')
            return False

        if self.__perform_authentication(username, password):
            SwatMessages.add('Authentication successful!')
            log.info("login attempt successful by " + username)
            request.environ['paste.auth_tkt.set_user'](username)

            return True

        log.warning("failed login attempt by " + username)
        SwatMessages.add('Authentication failed' + ' -- ' + self.__reason,
                         'critical')

        return False
示例#17
0
    def __authenticate(self):
        """ Performs the custom authentication. This method is required by
        repoze and we are sent here by it.
        
        Keyword arguments
        environ -- WSGI environment (request.environ)
        identify -- credentials entered by the user
        
        In case of sucess it returns the username of the user that attempted
        to login otherwise None
        
        TODO: Add i18n here
        BUG: Can't add i18n because for some reason the pylons imports don't
        work here. Maybe I'm using repoze.who wrong?
        
        """
        username = request.params.get("login", "").strip()
        password = request.params.get("password", "").strip()

        len_username = len(username)
        len_password = len(password)

        if len_username == 0:
            SwatMessages.add('Username cannot be empty', 'critical')
            return False
            
        if len_password == 0:
            SwatMessages.add('Password cannot be empty', 'critical')
            return False

        if self.__perform_authentication(username, password):
            SwatMessages.add('Authentication successful!')
            log.info("login attempt successful by " + username)
            request.environ['paste.auth_tkt.set_user'](username)
            
            return True
        
        log.warning("failed login attempt by " + username)
        SwatMessages.add('Authentication failed' + ' -- ' + self.__reason, 'critical')
        
        return False
示例#18
0
 def toggle(self, name=''):
     """ Toggles a Share's state (enabled/disabled).
     
     At the moment it is disabled because I'm not sure how I can implement
     this sucessfuly.
     
     Keyword arguments:
     name -- the name of the share to be toggled
     
     """
     if c.samba_lp.get("share backend") in self.__supported_backends:
         backend = globals()[self.__backend](c.samba_lp, {'name':name})
         toggled = backend.toggle()
         
         if toggled:
             message = _("Share Toggled successfuly")
             SwatMessages.add(message)
         else:
             SwatMessages.add(backend.get_error_message(), backend.get_error_type())
     else:
         message = _("Your chosen backend is not yet supported")
         SwatMessages.add(message, "critical")
     
     redirect_to(controller='share', action='index')
示例#19
0
    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)
示例#20
0
    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)
示例#21
0
文件: error.py 项目: jelmer/swat2
 def no_libs(self):
     SwatMessages.add(_("Python libraries not found"), "critical")
     return render("/default/derived/error/no-libs.mako")
示例#22
0
文件: share.py 项目: Schu23/GSoC-SWAT
    def copy(self, name=''):
        """ Clones the chosen Share
        
        Keyword arguments:
        name -- the name of the share to be duplicated
        
        """
        message = ""

        #
        # In case we select multiple shares, the name parameter will be empty
        # because Pylons stores [] http variables in a different way
        #
        if len(name) == 0:
            name = variabledecode.variable_decode(request.params).get("name")

        if name is not None and len(name) > 0:
            if not isinstance(name, list):
                name = [name]

            log.info(
                str(len(name)) +
                " share names passed to the server to be copied")

            if c.samba_lp.get("share backend") in self.__supported_backends:
                backend = globals()[self.__backend](c.samba_lp, {})
                ok_list = []

                #
                # May be annoying if many shares are selected because many error
                # messages may appear but it's possible that they are different.
                #
                for n in name:
                    copied = backend.copy(n)

                    if copied:
                        ok_list.append(n)
                        log.info("Copied " + n + " :: success: " + str(copied))
                    else:
                        SwatMessages.add(backend.get_error_message(), \
                                         backend.get_error_type())

                        log.warning(message)

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

                    #
                    # There is a way to do this in babel but I don't remember
                    # how to do it right now
                    #
                    if len(ok_list) == 1:
                        message = _("The Share %s was copied sucessfuly" \
                                    % (joined))
                    else:
                        message = _("The Shares %s were copied sucessfuly" \
                                    % (joined))

                    SwatMessages.add(message)
            else:
                message = _("Your chosen backend is not yet supported")
                SwatMessages.add(message, "critical")

            redirect_to(controller='share', action='index')
        else:
            SwatMessages.add(_("You did not choose a Share to copy"),
                             "critical")
            redirect_to(controller='share', action='index')
示例#23
0
    def copy(self, name=''):
        """ Clones the chosen Share
        
        Keyword arguments:
        name -- the name of the share to be duplicated
        
        """
        message = ""
        
        #
        # In case we select multiple shares, the name parameter will be empty
        # because Pylons stores [] http variables in a different way
        #
        if len(name) == 0:
            name = variabledecode.variable_decode(request.params).get("name")

        if name is not None and len(name) > 0:
            if not isinstance(name, list):
                name = [name]
            
            log.info(str(len(name)) + " share names passed to the server to be copied")
            
            if c.samba_lp.get("share backend") in self.__supported_backends:
                backend = globals()[self.__backend](c.samba_lp, {})
                ok_list = []
    
                #
                # May be annoying if many shares are selected because many error
                # messages may appear but it's possible that they are different.
                #
                for n in name:
                    copied = backend.copy(n)
                    
                    if copied:
                        ok_list.append(n)
                        log.info("Copied " + n + " :: success: " + str(copied))
                    else:
                        SwatMessages.add(backend.get_error_message(), \
                                         backend.get_error_type())
                        
                        log.warning(message)
                        
                if len(ok_list) > 0:
                    joined = ", ".join(["%s" % v for v in ok_list])
                    
                    #
                    # There is a way to do this in babel but I don't remember
                    # how to do it right now
                    #
                    if len(ok_list) == 1:
                        message = _("The Share %s was copied sucessfuly" \
                                    % (joined))
                    else:    
                        message = _("The Shares %s were copied sucessfuly" \
                                    % (joined))
                    
                    SwatMessages.add(message)
            else:
                message = _("Your chosen backend is not yet supported")
                SwatMessages.add(message, "critical")
                
            redirect_to(controller='share', action='index')
        else:
            SwatMessages.add(_("You did not choose a Share to copy"), "critical")
            redirect_to(controller='share', action='index')
示例#24
0
文件: error.py 项目: Schu23/GSoC-SWAT
 def no_libs(self):
     SwatMessages.add(_("Python libraries not found"), "critical")
     return render("/default/derived/error/no-libs.mako")
示例#25
0
文件: account.py 项目: jelmer/swat2
    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)
示例#26
0
文件: account.py 项目: jelmer/swat2
    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)