示例#1
0
    def groups(self):
        h.logm("DBG", 5, "ACTION " + h.getcalled())
        if request.method != 'GET':
            h.logm("ERR", 5, "EXCEPTION, method is " + request.method)
            return self.jsonErrorResponse(
                500, "adm/groups does only allow GET request method")

        db = self._py_object.app_globals.db
        groups = db.groups.find()
        responseArray = []
        for group in groups:
            responseArray.append(Group(group).encode())

        return self.jsonResponse(responseArray)
示例#2
0
    def groupPost(self):
        h.logm("DBG",5,"ACTION "+ h.getcalled());
        if request.method != 'POST':
            h.logm("ERR",5,"EXCEPTION, method is " + request.method);
            return self.jsonErrorResponse(500, "adm/group action does only allow POST request method");

        h.logm("DBG",5,"request.POST body: " + request.body);

        groupSchema = json.loads(request.body);
        group = Group(groupSchema);

        db = self._py_object.app_globals.db;
        if db.groups.find_one({'name': group.name}):
            h.logm("INF",5,"group already exist: " + str(group.encode()));
            return self.jsonErrorResponse(405, "group already exist: " + str(group.encode()));


        h.logm("INF",5,"trying to create group: " + str(group.encode()));

        if 'users' in groupSchema:
            h.logm("INF",5,"Looking for users: " + str(groupSchema['users']));
            for userid in groupSchema['users']:
                try:
                    user = db.users.find_one({'_id': ObjectId(userid)});
                except:
                    return self.jsonErrorResponse(404, "Invalid Mongo DB User Id {'_id' : " + userid + '}');
                else:
                    if not user:
                        return self.jsonErrorResponse(404, "Invalid user id " + userid);

                    h.logm("INF",5,"found user: "******"INF",5,"Looking for applications: " + str(groupSchema['applications']));
            for applicationid in groupSchema['applications']:
                try:
                    application = db.applications.find_one({'_id': ObjectId(applicationid)});
                except:
                    return self.jsonErrorResponse(404, "Invalid Mongo DB Application Id {'_id' : " + applicationid + '}');
                else:
                    if not application:
                        return self.jsonErrorResponse(404, "Invalid application id " + applicationid);

                h.logm("INF",5,"found application: " + str(application));

        groupid = db.groups.save(group.encode()); 

        if groupid == 0:
            return self.jsonErrorResponse(500, "Cannot create group: " + str(group.encode()));

        # if bucket not exist
        if not sfh.existbucket(groupid):
            h.logm("INF",5,"creating bucket for group: " + str(group.encode()));

            if not sfh.createbucket(groupid):
                return self.jsonErrorResponse(500, "Cannot create bucket" + str(group.encode()));

        else:
            h.logm("INF",5,"bucket already exist for group: " + str(group.encode()));

        responseDict = { "oid" : str(groupid) };

        return self.jsonResponse(responseDict);
示例#3
0
            form_result = schema.to_python(request.params);
            h.logm("DBG",5,"f r "+ str(request.params));

        except formencode.Invalid, error:
            h.logm("ERR",5,"f r "+ str(request.params));
            c.message = h.literal(htmlfill.escapenl_formatter(error));
            session['message'] = c.message;
            session.save();

        else:

            params = request.params;
            groupDict = {};
            groupDict['name'] = params['create_group_name'];
            # need to create the object group first
            group = Group(groupDict);

            if 'create_group_user_name' in params and params['create_group_user_name'] != 'None':
                user = db.users.find_one({'name': params['create_group_user_name']});
                group.users.append(user['_id']);

            if 'create_group_application_name' in params and params['create_group_application_name'] != 'None':
                application = db.applications.find_one({'name': params['create_group_application_name']});
                group.applications.append(application['_id']);

            if db.groups.find_one({'name': group.name}):
                h.logm("INF",5,"group already exist: " + str(group.encode()));
                c.message = 'group ' + group.name + ' already exist!';
                session['message'] = c.message;
                session.save();
                self.buildInformation();
示例#4
0
    def groupPost(self):
        h.logm("DBG", 5, "ACTION " + h.getcalled())
        if request.method != 'POST':
            h.logm("ERR", 5, "EXCEPTION, method is " + request.method)
            return self.jsonErrorResponse(
                500, "adm/group action does only allow POST request method")

        h.logm("DBG", 5, "request.POST body: " + request.body)

        groupSchema = json.loads(request.body)
        group = Group(groupSchema)

        db = self._py_object.app_globals.db
        if db.groups.find_one({'name': group.name}):
            h.logm("INF", 5, "group already exist: " + str(group.encode()))
            return self.jsonErrorResponse(
                405, "group already exist: " + str(group.encode()))

        h.logm("INF", 5, "trying to create group: " + str(group.encode()))

        if 'users' in groupSchema:
            h.logm("INF", 5, "Looking for users: " + str(groupSchema['users']))
            for userid in groupSchema['users']:
                try:
                    user = db.users.find_one({'_id': ObjectId(userid)})
                except:
                    return self.jsonErrorResponse(
                        404,
                        "Invalid Mongo DB User Id {'_id' : " + userid + '}')
                else:
                    if not user:
                        return self.jsonErrorResponse(
                            404, "Invalid user id " + userid)

                    h.logm("INF", 5, "found user: "******"INF", 5, "Looking for applications: " +
                str(groupSchema['applications']))
            for applicationid in groupSchema['applications']:
                try:
                    application = db.applications.find_one(
                        {'_id': ObjectId(applicationid)})
                except:
                    return self.jsonErrorResponse(
                        404, "Invalid Mongo DB Application Id {'_id' : " +
                        applicationid + '}')
                else:
                    if not application:
                        return self.jsonErrorResponse(
                            404, "Invalid application id " + applicationid)

                h.logm("INF", 5, "found application: " + str(application))

        groupid = db.groups.save(group.encode())

        if groupid == 0:
            return self.jsonErrorResponse(
                500, "Cannot create group: " + str(group.encode()))

        # if bucket not exist
        if not sfh.existbucket(groupid):
            h.logm("INF", 5,
                   "creating bucket for group: " + str(group.encode()))

            if not sfh.createbucket(groupid):
                return self.jsonErrorResponse(
                    500, "Cannot create bucket" + str(group.encode()))

        else:
            h.logm("INF", 5,
                   "bucket already exist for group: " + str(group.encode()))

        responseDict = {
            "oid": str(groupid)
        }

        return self.jsonResponse(responseDict)
示例#5
0
            form_result = schema.to_python(request.params)
            h.logm("DBG", 5, "f r " + str(request.params))

        except formencode.Invalid, error:
            h.logm("ERR", 5, "f r " + str(request.params))
            c.message = h.literal(htmlfill.escapenl_formatter(error))
            session['message'] = c.message
            session.save()

        else:

            params = request.params
            groupDict = {}
            groupDict['name'] = params['create_group_name']
            # need to create the object group first
            group = Group(groupDict)

            if 'create_group_user_name' in params and params[
                    'create_group_user_name'] != 'None':
                user = db.users.find_one(
                    {'name': params['create_group_user_name']})
                group.users.append(user['_id'])

            if 'create_group_application_name' in params and params[
                    'create_group_application_name'] != 'None':
                application = db.applications.find_one(
                    {'name': params['create_group_application_name']})
                group.applications.append(application['_id'])

            if db.groups.find_one({'name': group.name}):
                h.logm("INF", 5, "group already exist: " + str(group.encode()))