Пример #1
0
def buildfilepath(appid, breadid=None):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    assert config['app_conf']['permanent_store'];
    filepath = os.path.join(config['app_conf']['permanent_store'], buildfilename(appid, breadid));

    return filepath;
Пример #2
0
    def index(self):
        h.logm("DBG",5,"ACTION "+ h.getcalled());
        h.logm("INF",5,"params "+ str(request.params));

        self.buildInformation();

        return render('/admingroup.mako');
Пример #3
0
    def groupDelete(self, id=None):
        h.logm("DBG",5,"ACTION "+ h.getcalled());
        if request.method != 'DELETE':
            h.logm("ERR",5,"EXCEPTION, method is " + request.method);
            return self.jsonErrorResponse(500, "adm/group action does only allow DELETE request method");
        if not id:
            h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method);
            return self.jsonErrorResponse(407, "adm/group/id, missing parameter id");

        groupid = str(id);
        h.logm("DBG",5,"request w/ groupid=" + groupid);

        db = self._py_object.app_globals.db;

        group = None;

        try:
            group = db.groups.find_one({'_id': ObjectId(groupid)});
        except:
            return self.jsonErrorResponse(404, "Invalid Mongo DB Group Id {'_id' : " + groupid + '}');
        else:
            if not group:
                return self.jsonErrorResponse(404, "Invalid group id " + groupid);

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

        db.groups.remove({'_id': ObjectId(groupid)});

        responseDict = { "oid" : str(group['_id']) };

        return self.jsonResponse(responseDict);
Пример #4
0
    def index(self):
        h.logm("DBG", 5, "ACTION " + h.getcalled())
        h.logm("INF", 5, "params " + str(request.params))

        self.buildInformation()

        return render('/admingroup.mako')
Пример #5
0
    def removeUser(self):
        h.logm("DBG", 5, "ACTION " + h.getcalled())
        h.logm("DBG", 5, "params " + str(request.params))

        db = self._py_object.app_globals.db

        userid = 0
        for (k, v) in request.params.iteritems():
            if v == '-':
                userid = k
                break

        db.groups.update({}, {"$pull": {
            "users": (ObjectId(userid))
        }})

        user = db.users.find_one({'_id': ObjectId(userid)})

        db.users.remove({'_id': ObjectId(userid)})

        session[
            'message_admingroup'] = 'Congratulations: REMOVED user [' + user[
                'name'] + ']!'

        session.save()

        self.buildInformation()
        return render('/admingroup.mako')
Пример #6
0
    def userDelete(self, id=None):
        h.logm("DBG",5,"ACTION "+ h.getcalled());
        if request.method != 'DELETE':
            h.logm("ERR",5,"EXCEPTION, method is " + request.method);
            return self.jsonErrorResponse(500, "adm/user action does only allow DELETE request method");
        if not id:
            h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method);
            return self.jsonErrorResponse(407, "adm/user/id, missing parameter id");

        userid = str(id);
        h.logm("DBG",5,"request w/ userid=" + userid);

        db = self._py_object.app_globals.db;

        user = None;

        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: "******"$pull" : {"users" : (ObjectId(userid))}});
        db.users.remove({'_id': ObjectId(userid)});

        responseDict = { "oid" : str(user['_id']) };

        return self.jsonResponse(responseDict);
Пример #7
0
def getIconFileIOS4(dirApp, zfile, path, plist):
    h.logm("DBG", 5, "ACTION " + h.getcalled())

    if not 'CFCommodityIconFiles' in plist:
        h.logm("ERR", 5, "no CFCommodityIconFiles in plist")
        return None

    commodityIconFiles = plist['CFCommodityIconFiles']

    for commodityIconName in commodityIconFiles:
        iconapp = dirApp + commodityIconName
        if iconapp in zfile.namelist():
            zfile.extract(iconapp, path=path)

            commodityIconFile = os.path.join(path, dirApp, commodityIconName)
            if os.path.exists(commodityIconFile):
                break
            else:
                h.logm(
                    "ERR", 5, "commodityIconFile " + commodityIconFile +
                    " does not exist in BREAD")
                commodityIconFile = None

    if not commodityIconFile:
        h.logm("ERR", 5, "commodityIconFile does not exist in BREAD")
    else:
        h.logm("INF", 5,
               "commodityIconFile in BREAD!, using " + commodityIconFile)

    return commodityIconFile
Пример #8
0
def createdir(groupid):
    h.logm("DBG",5,"ACTION "+ h.getcalled());
    assert config['app_conf']['permanent_store'];
    dirpath = os.path.join(config['app_conf']['permanent_store'], groupid);
    if not os.path.exists(filepath):
        os.mkdir(dirpath);
    return dirpath;
Пример #9
0
def getIconFileIOS4(dirApp, zfile, path, plist):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    if not 'CFCommodityIconFiles' in plist:
        h.logm("ERR",5,"no CFCommodityIconFiles in plist");
        return None;

    commodityIconFiles = plist['CFCommodityIconFiles'];

    for commodityIconName in commodityIconFiles:
        iconapp = dirApp + commodityIconName
        if iconapp in zfile.namelist():
            zfile.extract(iconapp, path=path);

            commodityIconFile = os.path.join(path, dirApp, commodityIconName);
            if os.path.exists(commodityIconFile):
                break;
            else:
                h.logm("ERR",5,"commodityIconFile "+ commodityIconFile + " does not exist in BREAD");
                commodityIconFile = None;

    if not commodityIconFile:
        h.logm("ERR",5,"commodityIconFile does not exist in BREAD");
    else:
        h.logm("INF",5,"commodityIconFile in BREAD!, using " + commodityIconFile);

    return commodityIconFile;
Пример #10
0
 def groupApplication(self, id, id2):
     h.logm("DBG",5,"ACTION "+ h.getcalled());
     if request.method == 'POST':
         return self.groupAddApplication(id,id2);
     elif request.method == 'DELETE':
         return self.groupDeleteApplication(id,id2);
     else:
         return self.jsonErrorResponse(500, "adm/groupApplication/{id}/{id2} action only allows POST/DELETE request method. Request: " + request.method);
Пример #11
0
 def application(self, id=None):
     h.logm("DBG",5,"ACTION "+ h.getcalled());
     if request.method == 'GET':
         return self.applicationGet(id);
     elif request.method == 'DELETE':
         return self.applicationDelete(id);
     else:
         h.logm("ERR",5,"EXCEPTION, method is " + request.method);
         return self.jsonErrorResponse(500, "adm/application action only allows GET/DELETE request method");
Пример #12
0
def buildfilename(appid, breadid=None):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    if breadid:
        filename = appid + "_" + breadid;
    else:
        filename = appid;

    return filename;
Пример #13
0
    def index(self):
        h.logm("DBG",5,"ACTION "+ h.getcalled());

        db = self._py_object.app_globals.db;
        c.users = db.users.find();

        c.message = '';
        c.email = '';
        c.logged = True;
        return render('/signup.mako')
Пример #14
0
def getfilepath(appid, breadid=None):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    filepath = buildfilepath(appid, breadid);

    if not os.path.exists(filepath):
        h.logm("DBG",5, 'file ' + filepath + ' does not exist');
        return None;

    return filepath;
Пример #15
0
def getfileUsingResponse(appid, breadid, response):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    filename = getfilepath(appid, breadid);

    with open(filename, 'rb') as fileptr:
        shutil.copyfileobj(fileptr, response)

    h.logm("INF",5, 'filename %s' % filename);
    fileptr.close()
Пример #16
0
    def index(self):
        h.logm("DBG", 5, "ACTION " + h.getcalled())

        db = self._py_object.app_globals.db
        c.users = db.users.find()

        c.message = ''
        c.email = ''
        c.logged = True
        return render('/signup.mako')
Пример #17
0
 def groupApplication(self, id, id2):
     h.logm("DBG", 5, "ACTION " + h.getcalled())
     if request.method == 'POST':
         return self.groupAddApplication(id, id2)
     elif request.method == 'DELETE':
         return self.groupDeleteApplication(id, id2)
     else:
         return self.jsonErrorResponse(
             500,
             "adm/groupApplication/{id}/{id2} action only allows POST/DELETE request method. Request: "
             + request.method)
Пример #18
0
 def group(self, id=None, action2=None, id2=None):
     h.logm("DBG",5,"ACTION "+ h.getcalled());
     if request.method == 'POST':
         return self.groupPost();
     elif request.method == 'PUT':
         return self.groupPut(id);
     elif request.method == 'DELETE':
         return self.groupDelete(id);
     else:
         h.logm("ERR",5,"EXCEPTION, method is " + request.method);
         return self.jsonErrorResponse(500, "adm/group action does only allow POST/PUT/DELETE request methods");
Пример #19
0
 def application(self, id=None):
     h.logm("DBG", 5, "ACTION " + h.getcalled())
     if request.method == 'GET':
         return self.applicationGet(id)
     elif request.method == 'DELETE':
         return self.applicationDelete(id)
     else:
         h.logm("ERR", 5, "EXCEPTION, method is " + request.method)
         return self.jsonErrorResponse(
             500,
             "adm/application action only allows GET/DELETE request method")
Пример #20
0
    def users(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/users does only allow GET request method");

        db = self._py_object.app_globals.db;
        users = db.users.find();
        responseArray = [];
        for user in users:
            responseArray.append(User(user).encode());

        return self.jsonResponse(responseArray);
Пример #21
0
def createfile(filepointer, appid, breadid = None):
    h.logm("DBG",5,"ACTION "+ h.getcalled());
    
    filepath = buildfilepath(appid, breadid);
    h.logm("DBG",5,"filepath "+ filepath);

    permanent_file = open(filepath, 'wb');
    filepointer.file.seek(0);
    shutil.copyfileobj(filepointer.file, permanent_file);
    filepointer.file.close();
    permanent_file.close();

    return (filepath, os.path.getsize(filepath));
Пример #22
0
    def applications(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/applications does only allow GET request method");

        db = self._py_object.app_globals.db;
        applications = db.applications.find();
        responseArray = [];
        for application in applications:
            responseArray.append(Application(application).encodeWithBreadEntries());

        return self.jsonResponse(responseArray);
Пример #23
0
    def createGroup(self):
        db = self._py_object.app_globals.db

        schema = Validator.CreateGroupValidator()
        try:
            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()
Пример #24
0
    def createGroup(self):
        db = self._py_object.app_globals.db;

        schema = Validator.CreateGroupValidator();
        try:
            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();
Пример #25
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);
Пример #26
0
    def removeGroup(self):
        h.logm("DBG", 5, "ACTION " + h.getcalled())

        params = request.params
        h.logm("DBG", 5, "params " + str(params))

        schema = Validator.FormRemoveGroupValidator()
        try:
            form_result = schema.to_python(request.params)

        except formencode.Invalid, error:
            c.message = h.literal(htmlfill.escapenl_formatter(error))
            session['message'] = c.message
            session.save()
Пример #27
0
    def removeGroup(self):
        h.logm("DBG",5,"ACTION "+ h.getcalled());
        
        params = request.params;
        h.logm("DBG",5,"params "+ str(params));

        schema = Validator.FormRemoveGroupValidator();
        try:
            form_result = schema.to_python(request.params);

        except formencode.Invalid, error:
            c.message = h.literal(htmlfill.escapenl_formatter(error));
            session['message'] = c.message;
            session.save();
Пример #28
0
    def users(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/users does only allow GET request method")

        db = self._py_object.app_globals.db
        users = db.users.find()
        responseArray = []
        for user in users:
            responseArray.append(User(user).encode())

        return self.jsonResponse(responseArray)
Пример #29
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)
Пример #30
0
 def group(self, id=None, action2=None, id2=None):
     h.logm("DBG", 5, "ACTION " + h.getcalled())
     if request.method == 'POST':
         return self.groupPost()
     elif request.method == 'PUT':
         return self.groupPut(id)
     elif request.method == 'DELETE':
         return self.groupDelete(id)
     else:
         h.logm("ERR", 5, "EXCEPTION, method is " + request.method)
         return self.jsonErrorResponse(
             500,
             "adm/group action does only allow POST/PUT/DELETE request methods"
         )
Пример #31
0
    def applications(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/applications does only allow GET request method")

        db = self._py_object.app_globals.db
        applications = db.applications.find()
        responseArray = []
        for application in applications:
            responseArray.append(
                Application(application).encodeWithBreadEntries())

        return self.jsonResponse(responseArray)
Пример #32
0
    def applicationDelete(self, id=None):
        h.logm("DBG", 5, "ACTION " + h.getcalled())
        if request.method != 'DELETE':
            h.logm("ERR", 5, "EXCEPTION, method is " + request.method)
            return self.jsonErrorResponse(
                500,
                "adm/application action does only allow DELETE request method")
        if not id:
            h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method)
            return self.jsonErrorResponse(
                407, "adm/application/id, missing parameter id")

        applicationid = str(id)
        h.logm("DBG", 5, "request w/ applicationid=" + applicationid)

        db = self._py_object.app_globals.db

        application = None

        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))

        if 'breadEntries' in application:
            for breadEntry in application['breadEntries']:
                sfh.deletebread(str(applicationid), str(breadEntry['id']))

        db.groups.update(
            {}, {"$pull": {
                "applications": (ObjectId(applicationid))
            }})
        db.applications.remove({'_id': ObjectId(applicationid)})

        responseDict = {
            "oid": str(application['_id'])
        }

        return self.jsonResponse(responseDict)
Пример #33
0
    def addUserToGroup(self):

        h.logm("DBG", 5, "ACTION " + h.getcalled())

        schema = Validator.FormAddUserValidator()
        try:
            form_result = schema.to_python(request.params)
            h.logm("DBG", 5, "f r " + str(request.params))
            h.logm("DBG", 5, "TRY")

        except formencode.Invalid, error:
            h.logm("DBG", 5, "EXCEPT")
            h.logm("ERR", 5, "f r " + str(request.params))
            c.message = h.literal(htmlfill.escapenl_formatter(error))
            session['message'] = c.message
            session.save()
Пример #34
0
    def addUserToGroup(self):

        h.logm("DBG",5,"ACTION "+ h.getcalled());
        
        schema = Validator.FormAddUserValidator();
        try:
            form_result = schema.to_python(request.params);
            h.logm("DBG",5,"f r "+ str(request.params));
            h.logm("DBG",5,"TRY");

        except formencode.Invalid, error:
            h.logm("DBG",5,"EXCEPT");
            h.logm("ERR",5,"f r "+ str(request.params));
            c.message = h.literal(htmlfill.escapenl_formatter(error));
            session['message'] = c.message;
            session.save();
Пример #35
0
def createfilename(filename, appid, breadid = None):
    h.logm("DBG",5,"ACTION "+ h.getcalled());
    
    filepath = buildfilepath(appid, breadid);
    size = os.path.getsize(filename)

    permanent_file = open(filepath, 'wb');
    fileptr = open(filename, 'rb');
    if not fileptr:
        h.logm("DBG",5, 'cannot read file');
        return None;

    shutil.copyfileobj(fileptr, permanent_file);
    fileptr.close()
    permanent_file.close()
    return (filepath, size);
Пример #36
0
def getIconFile(dirApp, zfile, path, plist):
    h.logm("DBG",5,"ACTION "+ h.getcalled());
    iconFile = getIconFileIOS4(dirApp, zfile, path, plist);
    if iconFile:
        return iconFile;

    iconFile = getIconFileIOS3(dirApp, zfile, path, plist);
    if iconFile:
        return iconFile;

    iconFile = getIconFileIOS5(dirApp, zfile, path, plist);
    if iconFile:
        return iconFile;

    h.logm("ERR",5,"no IconFile in bread");
    return None;
Пример #37
0
def getIconFile(dirApp, zfile, path, plist):
    h.logm("DBG", 5, "ACTION " + h.getcalled())
    iconFile = getIconFileIOS4(dirApp, zfile, path, plist)
    if iconFile:
        return iconFile

    iconFile = getIconFileIOS3(dirApp, zfile, path, plist)
    if iconFile:
        return iconFile

    iconFile = getIconFileIOS5(dirApp, zfile, path, plist)
    if iconFile:
        return iconFile

    h.logm("ERR", 5, "no IconFile in bread")
    return None
Пример #38
0
def getIconFileIOS5(dirApp, zfile, path, plist):
    h.logm("DBG", 5, "ACTION " + h.getcalled())

    if not 'CFCommodityIcons' in plist:
        h.logm("ERR", 5, "no CFCommodityIcons in plist")
        return None

    commodityIconFileDict = plist['CFCommodityIcons']

    if 'CFCommodityPrimaryIcon' in commodityIconFileDict:
        commodityIconName = commodityIconFileDict['CFCommodityPrimaryIcon']

        iconapp = dirApp + commodityIconName
        if iconapp in zfile.namelist():
            zfile.extract(iconapp, path=path)

            commodityIconFile = os.path.join(path, dirApp, commodityIconName)

            if os.path.exists(commodityIconFile):
                return commodityIconFile
            else:
                commodityIconFile = None
    else:
        h.logm("ERR", 5, "no CFCommodityPrimaryIcon in plist")

    if 'UINewsstandIcon' in commodityIconFileDict:
        commodityIconName = commodityIconFileDict['UINewsstandIcon']

        iconapp = dirApp + commodityIconName
        if iconapp in zfile.namelist():
            zfile.extract(iconapp, path=path)

            commodityIconFile = os.path.join(path, commodityIconName)
            if os.path.exists(commodityIconFile):
                return commodityIconFile
            else:
                commodityIconFile = None
    else:
        h.logm("ERR", 5, "no UINewsstandIcon in plist")

    if not commodityIconFile:
        h.logm(
            "ERR", 5, "commodityIconFile (IOS5)" + commodityIconFile +
            " does not exist in BREAD")

    return None
Пример #39
0
def getIconFileIOS5(dirApp, zfile, path, plist):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    if not 'CFCommodityIcons' in plist:
        h.logm("ERR",5,"no CFCommodityIcons in plist");
        return None;

    commodityIconFileDict = plist['CFCommodityIcons'];

    if 'CFCommodityPrimaryIcon' in commodityIconFileDict:
        commodityIconName = commodityIconFileDict['CFCommodityPrimaryIcon']

        iconapp = dirApp + commodityIconName
        if iconapp in zfile.namelist():
            zfile.extract(iconapp, path=path);

            commodityIconFile = os.path.join(path, dirApp, commodityIconName);

            if os.path.exists(commodityIconFile):
                return commodityIconFile;
            else:
                commodityIconFile = None;
    else:
        h.logm("ERR",5,"no CFCommodityPrimaryIcon in plist");

    if 'UINewsstandIcon' in commodityIconFileDict:
        commodityIconName = commodityIconFileDict['UINewsstandIcon']

        iconapp = dirApp + commodityIconName
        if iconapp in zfile.namelist():
            zfile.extract(iconapp, path=path);

            commodityIconFile = os.path.join(path, commodityIconName);
            if os.path.exists(commodityIconFile):
                return commodityIconFile;
            else:
                commodityIconFile = None;
    else:
        h.logm("ERR",5,"no UINewsstandIcon in plist");

    if not commodityIconFile:
        h.logm("ERR",5,"commodityIconFile (IOS5)"+ commodityIconFile + " does not exist in BREAD");

    return None;
Пример #40
0
def getIconFileIOS3(dirApp, zfile, path, plist):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    if not 'CFCommodityIconFile' in plist:
        return None;

    commodityIconName = plist['CFCommodityIconFile'];

    iconapp = dirApp + commodityIconName
    if iconapp in zfile.namelist():
        zfile.extract(iconapp, path=path);

        commodityIconFile = os.path.join(path, dirApp, commodityIconName);
        if os.path.exists(commodityIconFile):
            return commodityIconFile;
        
    h.logm("ERR",5,"commodityIconFile (IOS3)"+ commodityIconFile + " does not exist in BREAD");

    return None;
Пример #41
0
def getIconFileIOS3(dirApp, zfile, path, plist):
    h.logm("DBG", 5, "ACTION " + h.getcalled())

    if not 'CFCommodityIconFile' in plist:
        return None

    commodityIconName = plist['CFCommodityIconFile']

    iconapp = dirApp + commodityIconName
    if iconapp in zfile.namelist():
        zfile.extract(iconapp, path=path)

        commodityIconFile = os.path.join(path, dirApp, commodityIconName)
        if os.path.exists(commodityIconFile):
            return commodityIconFile

    h.logm(
        "ERR", 5, "commodityIconFile (IOS3)" + commodityIconFile +
        " does not exist in BREAD")

    return None
Пример #42
0
    def applicationGet(self, id=None):
        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/applications does only allow GET request method")
        if not id:
            h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method)
            return self.jsonErrorResponse(
                407, "adm/application/id missing parameter id")

        applicationid = str(id)

        db = self._py_object.app_globals.db
        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)

        return self.jsonResponse(
            Application(application).encodeWithBreadEntries())
Пример #43
0
    def userDelete(self, id=None):
        h.logm("DBG", 5, "ACTION " + h.getcalled())
        if request.method != 'DELETE':
            h.logm("ERR", 5, "EXCEPTION, method is " + request.method)
            return self.jsonErrorResponse(
                500, "adm/user action does only allow DELETE request method")
        if not id:
            h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method)
            return self.jsonErrorResponse(407,
                                          "adm/user/id, missing parameter id")

        userid = str(id)
        h.logm("DBG", 5, "request w/ userid=" + userid)

        db = self._py_object.app_globals.db

        user = None

        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: "******"$pull": {
            "users": (ObjectId(userid))
        }})
        db.users.remove({'_id': ObjectId(userid)})

        responseDict = {
            "oid": str(user['_id'])
        }

        return self.jsonResponse(responseDict)
Пример #44
0
    def groupDelete(self, id=None):
        h.logm("DBG", 5, "ACTION " + h.getcalled())
        if request.method != 'DELETE':
            h.logm("ERR", 5, "EXCEPTION, method is " + request.method)
            return self.jsonErrorResponse(
                500, "adm/group action does only allow DELETE request method")
        if not id:
            h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method)
            return self.jsonErrorResponse(
                407, "adm/group/id, missing parameter id")

        groupid = str(id)
        h.logm("DBG", 5, "request w/ groupid=" + groupid)

        db = self._py_object.app_globals.db

        group = None

        try:
            group = db.groups.find_one({'_id': ObjectId(groupid)})
        except:
            return self.jsonErrorResponse(
                404, "Invalid Mongo DB Group Id {'_id' : " + groupid + '}')
        else:
            if not group:
                return self.jsonErrorResponse(404,
                                              "Invalid group id " + groupid)

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

        db.groups.remove({'_id': ObjectId(groupid)})

        responseDict = {
            "oid": str(group['_id'])
        }

        return self.jsonResponse(responseDict)
Пример #45
0
    def applicationDelete(self, id=None):
        h.logm("DBG",5,"ACTION "+ h.getcalled());
        if request.method != 'DELETE':
            h.logm("ERR",5,"EXCEPTION, method is " + request.method);
            return self.jsonErrorResponse(500, "adm/application action does only allow DELETE request method");
        if not id:
            h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method);
            return self.jsonErrorResponse(407, "adm/application/id, missing parameter id");

        applicationid = str(id);
        h.logm("DBG",5,"request w/ applicationid=" + applicationid);

        db = self._py_object.app_globals.db;

        application = None;

        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));

        if 'breadEntries' in application:
            for breadEntry in application['breadEntries']:
                sfh.deletebread(str(applicationid), str(breadEntry['id']));

        db.groups.update({}, {"$pull" : {"applications" : (ObjectId(applicationid))}});
        db.applications.remove({'_id': ObjectId(applicationid)});

        responseDict = { "oid" : str(application['_id']) };

        return self.jsonResponse(responseDict);
Пример #46
0
    def removeUser(self):
        h.logm("DBG",5,"ACTION "+ h.getcalled());
        h.logm("DBG",5,"params "+ str(request.params));
        
        db = self._py_object.app_globals.db;

        userid = 0;
        for (k, v) in request.params.iteritems():
            if v == '-':
                userid = k;
                break;
                
        db.groups.update({}, {"$pull" : {"users" : (ObjectId(userid))}});

        user = db.users.find_one({'_id': ObjectId(userid)});

        db.users.remove({'_id': ObjectId(userid)});

        session['message_admingroup'] = 'Congratulations: REMOVED user [' +  user['name'] + ']!';

        session.save();

        self.buildInformation();
        return render('/admingroup.mako');
Пример #47
0
def getfile_(appid, breadid=None):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    filename = getfilepath(appid, breadid);

    h.logm("INF",5, 'filename %s' % filename);
    headers = [('Content-Disposition', 'attachment; filename=\"' + filename + '\"'),
        ('Content-Type', 'application/octet-stream'),
        ('Content-Length', str(os.path.getsize(filename)))];

    h.logm("INF",5, 'headers ' + str(headers));
#    return FileApp(filename, headers=headers);
    return FileApp(filename, headers=headers)
Пример #48
0
    def submit(self):
        h.logm("DBG", 5, "ACTION " + h.getcalled())

        db = self._py_object.app_globals.db
        c.users = db.users.find()
        c.email = ''
        c.logged = True
        c.message = ''
        schema = SignupValidator()
        try:
            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))
            return render('/signup.mako')
Пример #49
0
def getfile(appid, breadid=None):
    h.logm("DBG",5,"ACTION "+ h.getcalled());

    filename = getfilepath(appid, breadid);

    content_type = mimetypes.guess_type(filename);

    fileptr = open(filename, 'rb');
    if not fileptr:
        h.logm("DBG",5, 'cannot read file');
        return None;

    data = fileptr.read()
    h.logm("INF",5, 'filename %s data len %d' % (filename, len(data)));

    fileptr.close()

    return data;
Пример #50
0
    def submit(self):
        h.logm("DBG",5,"ACTION "+ h.getcalled());

        db = self._py_object.app_globals.db;
        c.users = db.users.find();
        c.email = '';
        c.logged = True;
        c.message = '';
        schema = SignupValidator();
        try:
            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));
            return render('/signup.mako');
Пример #51
0
    def applicationGet(self, id=None):
        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/applications does only allow GET request method");
        if not id:
            h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method);
            return self.jsonErrorResponse(407, "adm/application/id missing parameter id");

        applicationid = str(id);

        db = self._py_object.app_globals.db;
        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);

        return self.jsonResponse(Application(application).encodeWithBreadEntries());