def get(self): acc = appuser.verifyToken(self) if not acc: return # Check for "recent_points" is mcache and that JSON if found # Query for all points modified > LASTBUILDMODIFIED # Cache the results and return. Email notify admin if > 20k appuser.srverr(self, 500, "Not implemented yet")
def get(self): # PENDING: verify caller is an org contributor if not appuser.verify_secure_comms(self): return acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") ptid = self.request.get('pointid') if not ptid: return appuser.srverr(self, 400, "pointid required for lookup") pt = Point.get_by_id(int(ptid)) if not pt: return appuser.srverr(self, 404, "Point " + ptid + " not found") appuser.return_json(self, [pt])
def get(self): ptid = self.request.get('pointid') if not ptid: return appuser.srverr(self, 400, "pointid needed for lookup") pt = Point.get_by_id(int(ptid)) if not pt: return appuser.srverr(self, 404, "Point " + ptid + " not found") if not pt.pic: return appuser.srverr(self, 404, "Point " + ptid + " has no pic") img = images.Image(pt.pic) img.resize(width=160, height=160) img = img.execute_transforms(output_encoding=images.PNG) self.response.headers['Content-Type'] = "image/png" self.response.out.write(img)
def get(self): acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") if acc.orgid != 1 or acc.lev != 2: return appuser.srverr(self, 403, "Admin access only.") pts = Point.all() for pt in pts: pt.groups = "" pt.regions = "" pt.categories = "" pt.tags = "" cats = [] if "N" in pt.codes: cats.append("Native American") if "B" in pt.codes: cats.append("African American") if "L" in pt.codes: cats.append("Latino/as") if "A" in pt.codes: cats.append("Asian American") if "M" in pt.codes: cats.append("Middle East/North Africa") if "R" in pt.codes: cats.append("Multiracial") pt.qtype = "" if "U" in pt.codes: pt.qtype = "U" if "F" in pt.codes: pt.qtype = "F" if "D" in pt.codes: pt.qtype = "D" pt.groups = ",".join(cats) pt.put() # individual points are not cached self.response.out.write("BatchProcessPoints completed.")
def get(self): acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") if acc.orgid != 1 or acc.lev != 2: return appuser.srverr(self, 403, "Admin access only.") vq = appuser.VizQuery(service.AppService, "WHERE name=:1", "pubpts") svcs = vq.fetch(1, read_policy=db.EVENTUAL_CONSISTENCY, deadline=20) if not len(svcs): # create the entry as a placeholder svc = service.AppService(name="pubpts", ckey="", csec="", data="") svc.put() res = [] # result accumulator if len(svcs) > 0 and len(svcs[0].data) > 100: for ptid in svcs[0].data.split(","): pt = Point.get_by_id(int(ptid)) if is_deleted_point(pt): continue res.append(pt) else: # no point ids to process, fetch everything pts = Point.all() for pt in pts: if is_deleted_point(pt): continue res.append(pt) appuser.return_json(self, res)
def get(self): acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") if acc.orgid != 1 or acc.lev != 2: return appuser.srverr(self, 403, "Admin access only.") text = recent_completions("2018-01-01T00:00:00Z") self.response.headers['Content-Type'] = 'text/plain' self.response.out.write(text)
def get(self): acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") if acc.orgid != 1 or acc.lev != 2: return appuser.srverr(self, 403, "Admin access only.") ptid = self.request.get('pointid') pt = Point.get_by_id(int(ptid)) pt.pic = None pt.put() self.response.out.write("Pic set to None for Point " + ptid)
def post(self): if not appuser.verify_secure_comms(self): return acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") if not acc.orgid or acc.lev != 2: return appuser.srverr(self, 403, "Not an Administrator") params = appuser.read_params(self, ["membermail"]) mem = appuser.account_from_email(params["membermail"]) if not mem: return appuser.srverr(self, 404, "User not found") if mem.orgid: if mem.orgid == acc.orgid: return appuser.srverr(self, 400, "Already a member") else: return appuser.srverr(self, 403, "Member of other Org") mem.orgid = acc.orgid mem.lev = 0 appuser.cached_put(mem.email, mem) appuser.return_json(self, [public_member_record(mem)])
def post(self): if not appuser.verify_secure_comms(self): return acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") params = appuser.read_params(self, ["orgid", "userid", "lev"]) if not params["orgid"] or int(params["orgid"]) != acc.orgid: return appuser.srverr(self, 403, "Not your Organization") orgid = int(params["orgid"]) userid = int(params["userid"]) lev = int(params["lev"]) if acc.key().id() != userid and acc.lev != 2: return appuser.srverr(self, 403, "Not an Administrator") if acc.key().id() == userid and lev > acc.lev: return appuser.srverr(self, 403, "Can't promote yourself") user = appuser.AppUser.get_by_id(userid) if lev < 0: user.orgid = 0 user.lev = 0 else: user.lev = lev appuser.cached_put(user.email, user) appuser.return_json(self, [])
def update_or_create_timeline(handler, acc, params): timeline = None now = appuser.nowISO() instid = params["instid"] or 0 cname = canonize(params["name"]) vq = appuser.VizQuery(Timeline, "WHERE cname=:1 LIMIT 1", cname) tls = vq.fetch(1, read_policy=db.EVENTUAL_CONSISTENCY, deadline=20) if len(tls) > 0: if int(instid) != tls[0].key().id(): return appuser.srverr(handler, 406, "Name already used") timeline = tls[0] if instid and not timeline: timeline = Timeline.get_by_id(int(instid)) if not timeline: return appuser.srverr(handler, 404, "No Timeline " + instid) if not may_edit_timeline(handler, acc, timeline): return if not timeline: # not found, create new timeline = Timeline(name=params["name"], created=now) timeline.name = params["name"] timeline.cname = canonize(timeline.name) timeline.slug = params["slug"] or "" timeline.title = params["title"] or "" timeline.subtitle = params["subtitle"] or "" timeline.featured = params["featured"] or "" timeline.lang = params["lang"] or "en-US" timeline.comment = params["comment"] or "" timeline.about = params["about"] or "" timeline.ctype = params["ctype"] timeline.cids = params["cids"] or "" timeline.svs = params["svs"] or "" timeline.preb = rebuild_prebuilt_timeline_points(timeline) timeline.orgid = timeline.orgid or acc.orgid timeline.modified = now appuser.cached_put(None, timeline) return timeline
def get(self): if not appuser.verify_secure_comms(self): return acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") if acc.orgid != 1 or acc.lev != 2: return appuser.srverr(self, 403, "System admin access only.") pn = "Placeholder" vq = appuser.VizQuery(Organization, "WHERE name=:1 LIMIT 1", pn) orgs = vq.fetch(1, read_policy=db.EVENTUAL_CONSISTENCY, deadline=20) if len(orgs) > 0: org = orgs[0] else: org = Organization(name=pn) org.put() appuser.return_json(self, [org])
def get(self): if not appuser.verify_secure_comms(self): return acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") params = appuser.read_params(self, ["orgid"]) if not params["orgid"] or int(params["orgid"]) != acc.orgid: return appuser.srverr(self, 403, "Not your Organization") vq = appuser.VizQuery(appuser.AppUser, "WHERE orgid=:1", int(params["orgid"])) res = vq.fetch(500, read_policy=db.EVENTUAL_CONSISTENCY, deadline=20) oms = [] for user in res: # only public info and org info, no email etc.. oms.append(public_member_record(user)) logging.info("Org " + params["orgid"] + " has " + str(len(oms)) + " members") appuser.return_json(self, oms)
def post(self): if not appuser.verify_secure_comms(self): return acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") fields = [ "orgid", "name", "code", "contacturl", "projecturl", "groups", "regions", "categories", "tags" ] params = appuser.read_params(self, fields) orgid = int(params["orgid"]) org = Organization.get_by_id(orgid) if acc.orgid != orgid or acc.lev != 2: return appuser.srverr(self, 403, "Not Organization Administrator") org = update_organization(org, params) if org: appuser.return_json(self, [org])
def get(self): tlid = self.request.get("tlid") slug = "" if tlid: tl = fetch_timeline_by_id(tlid) else: slug = self.request.get("slug") if not slug: slug = "default" slug = slug.lower() # just in case someone camel cases a url.. tl = fetch_timeline_by_slug(slug) if not tl and slug == "default": tl = make_bootstrap_demo() if not tl: return appuser.srverr(self, 404, "No Timeline " + tlid) uidp = self.request.get("uidp") if uidp: daycount.note_timeline_fetch(self, tl, uidp) tls = contained_timelines(tl) appuser.return_json(self, tls)
def post(self): acc = appuser.authenticated(self.request) if not acc: return srverr(self, 401, "Authentication failed") params = appuser.read_params(self, ["tlid", "tlname", "tltitle", "tlsubtitle"]); tlid = params["tlid"] started = json.loads(acc.started) proginst = [pi for pi in started if pi["tlid"] == tlid] if not len(proginst): return appuser.srverr(self, 400, "Timeline " + tlid + " (" + params["tlname"] + ") not found") proginst = proginst[0] tstamp = appuser.nowISO() comp = TLComp(userid=acc.key().id(), tlid=int(tlid), username=acc.name, tlname=params["tlname"], data=json.dumps(proginst), created=tstamp) comp.put() # Update the account and return the updated version started = [pi for pi in started if pi["tlid"] != tlid] completed = json.loads(acc.completed) compinst = [ci for ci in completed if ci["tlid"] == tlid] if len(compinst): compinst = compinst[0] if "count" not in compinst: # completed before count introduced compinst["count"] = 1 # at least one completion, start there compinst["name"] = params["tlname"] # update name in case changed else: compinst = {"tlid":tlid, "name":params["tlname"], "count":0, "first":tstamp} compinst["latest"] = tstamp compinst["count"] += 1 compinst["title"] = params["tltitle"] compinst["subtitle"] = params["tlsubtitle"] compinst["stats"] = completion_stats(proginst) completed = [ci for ci in completed if ci["tlid"] != tlid] completed.append(compinst) acc.started = json.dumps(started) acc.completed = json.dumps(completed) cached_put(acc.email, acc) appuser.return_json(self, [acc, {"token":appuser.token_for_user(acc)}])