def set_acls(self, owner_uuid, aclsd): """ allow each Module class to have a set_acls call, but catch here and then pass generic function the right UserRoleX klass. Still want to find way to generically follow sqla""" super(Module, self).set_acls(owner_uuid, aclsd, UserRoleModule) db_session.add(self) db_session.commit()
def delete_o(klass, ID, requesting_user_uri): """ """ fldr = get_by_id(klass, ID, requesting_user_uri) if not change_approval(fldr, None, requesting_user_uri, "DELETE"): abort(403) else: db_session.delete(fldr) db_session.commit()
def set_acls(self, owner_uuid, aclsd): """ allow each Folder / collection class to have a set_acls call, but catch here and then pass generic function the right UserRoleX klass. Still want to find way to generically follow sqla. convern - this is beginning to smell like java.""" super(Folder, self).set_acls(owner_uuid, aclsd, UserRoleFolder) db_session.add(self) db_session.commit()
def put_o(jsond, klass, ID, requesting_user_uri): """Given a user_id, and a json_str representing the "Updated" fields then update those fields for that user_id """ uobj = get_by_id(klass, ID, requesting_user_uri) if not change_approval(uobj, jsond, requesting_user_uri, "PUT"): abort(403) #.. todo:: parser = verify_schema_version(None) uobj.populate_self(jsond) db_session.add(uobj) db_session.commit() return uobj
def post_o(klass, incomingd, requesting_user_uri): """Given a dict representing the complete set of fields then create a new user and those fields I am getting a dictionary direct form Flask request object - want to handle that myself with parser. returns User object, for later saveing to DB""" u = klass(creator_uuid=requesting_user_uri) # parser = verify_schema_version(None) # incomingd = parser(json_str) u.populate_self(incomingd) if not change_approval(u, incomingd, requesting_user_uri, "POST"): abort(403) db_session.add(u) db_session.commit() return u
def __init__(self, id_=None, creator_uuid=None): """ """ self.mediaType = "application/vnd.org.cnx.module" if not self.validateid(id_): raise Rhaptos2Error("%s not valid id" % id_) if creator_uuid: self.adduserrole(UserRoleModule, {'user_uri': creator_uuid, 'role_type': 'aclrw'}) else: raise Rhaptos2Error("Modules need owner provided at init ") if id_: self.id_ = id_ else: self.id_ = "cnxmodule:" + str(uuid.uuid4()) self.dateCreatedUTC = self.get_utcnow() super(Base, self).__init__() db_session.commit()
def workspace_by_user(user_uri): """Its at times like these I just want to pass SQL in... """ qm = db_session.query(Module) qm = qm.join(Module.userroles) qm = qm.filter(UserRoleModule.user_uri == user_uri) rs1 = qm.all() qf = db_session.query(Folder) qf = qf.join(Folder.userroles) qf = qf.filter(UserRoleFolder.user_uri == user_uri) rs2 = qf.all() qc = db_session.query(Collection) qc = qc.join(Collection.userroles) qc = qc.filter(UserRoleCollection.user_uri == user_uri) rs3 = qc.all() rs1.extend(rs2) rs1.extend(rs3) db_session.commit() # hail mary... return rs1