示例#1
0
class _StoreAccessMixin:
    def initialize(self, store):
        self.store = store
        self._ctx = None

        session_id = self.request.headers.get('UserSession')
        no_session_in_headers = session_id is None or \
                                session_id == FROM_COOKIE
        if no_session_in_headers:
            session_id = self.get_cookie("UserSession")

        client_id = self.request.headers.get('ClientID')
        remote_ip = self.request.headers.get('X-Real-IP') or \
                    self.request.remote_ip
        self.ctx().params['remote_ip'] = remote_ip
        try:
            self.access = self.ctx().validate_session(session_id, client_id)
        except:
            log.debug(exception_message())
            self.access = GuestAccess(self.ctx())

    def ctx(self):
        if self._ctx is None:
            self._ctx = StoreContext(self.store)
            self._ctx.__enter__()
        return self._ctx

    def close_ctx(self):
        if self._ctx is not None:
            self._ctx.__exit__(None, None, None)
            self._ctx = None

    def on_finish(self):
        self.close_ctx()
示例#2
0
 def add_user(self, email, password=None, full_name=None):
     if password is None:  # pragma: no cover
         password = SaltedSha.from_secret(getpass.getpass())
         retype = getpass.getpass('Retype password:'******'Passwords does not match')
     else:
         password = SaltedSha(password)
     with StoreContext(self.store) as ctx:
         actions = PrivilegedAccess.system_access(ctx)
         actions.add_user(email, password, full_name=full_name)
示例#3
0
 def acl(self, user, acl=None):
     with StoreContext(self.store) as ctx:
         actions = PrivilegedAccess.system_access(ctx)
         if acl is not None:
             action = acl[-1]
             acl = Acl(acl[:-1])
         if acl is None or action == '+':
             user, permissions = actions.add_acl(user, acl)
         elif action == '-':
             user, permissions = actions.remove_acl(user, acl)
         else:
             raise AssertionError('unknown action: %s' % action)
         print("User: %s" % user.email)
         print("User.id: %s" % user.id)
         print('')
         print_pad(permissions, ('permission_type', 'cake'), getattr)
示例#4
0
 def pull(self, cake, dir):
     with StoreContext(self.store) as ctx:
         actions = PrivilegedAccess.system_access(ctx)
         pull(actions, ensure_cakepath(cake), dir)
示例#5
0
 def backup(self, dir):
     with StoreContext(self.store) as ctx:
         actions = PrivilegedAccess.system_access(ctx)
         scan_path = ScanPath(dir)
         print('DirId: %s\nCake:  %s' % backup(scan_path, actions))
示例#6
0
 def remove_user(self, user):
     with StoreContext(self.store) as ctx:
         actions = PrivilegedAccess.system_access(ctx)
         actions.remove_user(user)
示例#7
0
 def ctx(self):
     if self._ctx is None:
         self._ctx = StoreContext(self.store)
         self._ctx.__enter__()
     return self._ctx