Commit 239a5cad authored by Antoine Millet's avatar Antoine Millet
Browse files

Added close/declose functions.

parent f17954bd
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ class CCConf(object):
    CONF_TEMPLATE = {'password': None,
                     'role': None,
                     'tags': {},
                     'rights': []}
                     'rights': [],
                     'enabled': True}

    RE_SALTPW = re.compile(r'{(?P<method>[A-Z]+)}(?P<password>.+)')

@@ -189,8 +190,8 @@ class CCConf(object):
        conf = self._get_conf(login)
        passwd_conf = conf['password']

        # Check if account logging is disabled:
        if passwd_conf is None:
        # Check if account password is disabled or if account is disabled:
        if passwd_conf is None or not conf.get('enabled'):
            return None

        is_valid = False
@@ -323,6 +324,30 @@ class CCConf(object):
        rights.insert(index, rule)
        self._set_conf(login, conf)

    @_writer
    def set_enabled(self, login, enable=True):
        '''
        Disable or enable the provided account.

        :param login: the login of the account to disable.
        '''
        
        conf = self._get_conf(login)
        conf['enabled'] = enable
        self._set_conf(login, conf)

    @_writer
    def disable(self, login):
        '''
        Disable an existing account without deleting it.

        :param login: the login of the account to disable.
        '''
        
        conf = self._get_conf(login)
        conf['enabled'] = False
        self._set_conf(login, conf)

    @_writer
    def remove_right(self, login, index):
        '''
+26 −0
Original line number Diff line number Diff line
@@ -167,6 +167,32 @@ class ClientHandler(OnlineCCHandler):
        for obj in objects:
            self._server.conf.remove_account(obj['a'])

    @listed
    def close(self, conn, query):
        '''
        Close an account without deleting it.
        '''
        
        objects = self._server.list(query)
        for obj in objects:
            if 'a' not in obj:
                raise BadObjectError('All objects must have the "a" tag.')
        for obj in objects:
            self._server.conf.set_enabled(obj['a'], enable=False)

    @listed
    def declose(self, conn, query):
        '''
        Re-open an closed account.
        '''
        
        objects = self._server.list(query)
        for obj in objects:
            if 'a' not in obj:
                raise BadObjectError('All objects must have the "a" tag.')
        for obj in objects:
            self._server.conf.set_enabled(obj['a'], enable=True)

    @listed
    def rights(self, conn, query):
        '''