Beispiel #1
0
def post_space_handler(environ, start_response):
    """
    entry point for posting a new space name to TiddlyWeb
    """
    space_name = environ['tiddlyweb.query']['name'][0]

    space = Space(environ)

    try:
        space.create_space(space_name, environ['tiddlyweb.config']['space'])
    except (RecipeExistsError, BagExistsError):
        raise HTTP409('Space already Exists: %s' % space_name)

    host = environ['tiddlyweb.config']['server_host']
    if 'port' in host:
        port = ':%s' % host['port']
    else:
        port = ''

    recipe = Recipe('%s_public' % space_name)
    new_space_uri = '%s/tiddlers.wiki' % recipe_url(environ, recipe)

    start_response('201 Created', [
        ('Location', new_space_uri),
        ('Content-type', 'text/plain')])
    return new_space_uri
def create_room_elements(room_name):
    room_space = Space({'tiddlyweb.store': store})
    
    this_room = ROOM.replace('ROOMNAME', room_name)
    
    this_room = json.loads(this_room)
    
    room_space.create_space(this_room)
def addproject(args):
    """make a project space. <project_name>"""
    if len(args) != 1:
        print >> sys.stderr, ('usage: twanager addproject <project_name>')
    
    #replace PROJECT_NAME with the actual name of the project
    this_project = PROJECT.replace('PROJECT_NAME', args[0])
    this_project = json.loads(this_project)
    
    #create the space
    project_space = Space({'tiddlyweb.store': get_store(config)})
    project_space.create_space(this_project)
def addproject(args):
    """make a project space. <project_name>"""
    if len(args) != 1:
        print >> sys.stderr, ('usage: twanager addproject <project_name>')

    #replace PROJECT_NAME with the actual name of the project
    this_project = PROJECT.replace('PROJECT_NAME', args[0])
    this_project = json.loads(this_project)

    #create the space
    project_space = Space({'tiddlyweb.store': get_store(config)})
    project_space.create_space(this_project)
Beispiel #5
0
    def extract(self, environ, start_response):
        """
        Extract the cookie, if there, from the headers
        and attempt to validate its contents.
        """
        try:
            user_cookie = environ['HTTP_COOKIE']
            logging.debug('simple_cookie looking at cookie string: %s',
                          user_cookie)
            cookie = Cookie.SimpleCookie()
            cookie.load(user_cookie)
            cookie_value = cookie['tiddlyweb_user'].value
            secret = environ['tiddlyweb.config']['secret']
            usersign, cookie_secret = cookie_value.rsplit(':', 1)
            store = environ['tiddlyweb.store']

            if cookie_secret == sha('%s%s' % (usersign, secret)).hexdigest():
                user = User(usersign)
                try:
                    user = store.get(user)
                except (StoreMethodNotImplemented, NoUserError):
                    pass

                #check that the user has the requisite bags
                #if they don't, create them
                public_bag = '%s_public' % user.usersign
                private_bag = '%s_private' % user.usersign
                space = {
                    'bags': {
                        public_bag: {
                            'policy': {
                                "read": [],
                                "create": [user.usersign],
                                "manage": [user.usersign, "R:ADMIN"],
                                "accept": [],
                                "write": [user.usersign],
                                "owner": user.usersign,
                                "delete": [user.usersign, "R:ADMIN"]
                            }
                        },
                        private_bag: {
                            'policy': {
                                "read": [user.usersign],
                                "create": [user.usersign],
                                "manage": [user.usersign, "R:ADMIN"],
                                "accept": [],
                                "write": [user.usersign],
                                "owner": user.usersign,
                                "delete": [user.usersign]
                            }
                        }
                    },
                    'recipes': {
                        '%s' % user.usersign: {
                            'recipe': [['system', ''], [public_bag, ''],
                                       [private_bag, '']],
                            'policy': {
                                "read": [user.usersign],
                                "create": [user.usersign],
                                "manage": [user.usersign, "R:ADMIN"],
                                "accept": [],
                                "write": [user.usersign],
                                "owner": user.usersign,
                                "delete": [user.usersign]
                            }
                        }
                    }
                }
                user_space = Space(environ)
                user_space.create_space(space)

                return {"name": user.usersign, "roles": user.list_roles()}
        except Cookie.CookieError, exc:
            raise HTTP400('malformed cookie: %s' % exc)