def post(self): acc = authenticated(self.request) if not acc or acc.status != "Active": return srverr(self, 403, "Your account must be active before you can accept membership.") pnm = rev.acc_review_modification_authorized(acc, self) if not pnm: #penid did not match a pen the caller controls return #error already reported coop, role = fetch_coop_and_role(self, pnm) if not coop: return #error already reported ipid = int(self.request.get('inviterpenid')) coopid = coop.key().id() invite = find_invite_for_coop(coopid, ipid, acc.invites) if not invite: return srverr(self, 404, "Invitation not found") updobjs = [] action = self.request.get('action') if action == "Accept": invpen = cached_get(ipid, pen.PenName) process_membership_action(coop, "accept", invpen, pnm, "NotFound", "Membership invitation accepted"); if not csv_contains(str(coopid), pnm.coops): pnm.coops = append_to_csv(str(coopid), pnm.coops) cached_put(pnm) pnm = pen.PenName.get_by_id(pnm.key().id()) updobjs = [ pnm, coop ] acc.invites = remove_invites_for_coop(coopid, acc.invites) acc.put() acc = MORAccount.get_by_id(acc.key().id()) returnJSON(self.response, updobjs)
def get(self): ctype = normalize_mctr_type(self) if not ctype: return parid = intz(self.request.get("parentid")) # sets to 0 if not found acc = None if not ctype == "Coop": acc = moracct.authenticated(self.request) if not acc: return srverr(self, "403", "Authentication failed") # Anyone following a theme has stats access, but profiles are private if ctype == "PenName": pnm = rev.acc_review_modification_authorized(acc, self) if not pnm or (pnm and pnm.key().id() != parid): return srverr(self, "403", "You may only view stats for your own profile") elif (ctype == "Site" and (not acc or acc.key().id() != 11005) and (not self.request.host_url.startswith('http://localhost'))): return srverr(self, "403", "Access stats through your profile or theme") cqk = ctype + "CtrQuery" + str(parid) res = memcache.get(cqk) counter = get_mctr(ctype, parid) if res: res = json.loads(res) # if last saved counter is not the current counter, and the # current counter is not temporary, then results are old if len(res) and res[-1]["day"] != counter.day and counter.modified: res = "" memcache.set(cqk, "") if res: counter = db.to_dict(counter) if len(res) and res[-1]["day"] == counter["day"]: res[-1] = counter else: res.append(counter) return moracct.writeJSONResponse(json.dumps(res, True), self.response) refp = ctype + "Counter" + str(parid) daysback = 70 # max 10 weeks back if not restricted by batch_size dtnow = datetime.datetime.utcnow() thresh = dt2ISO(dtnow - datetime.timedelta(daysback)) vq = None if ctype == "Site": vq = VizQuery(MembicCounter, "WHERE day > :1", thresh) else: vq = VizQuery(MembicCounter, "WHERE refp = :1 AND day > :2", refp, thresh) ctrs = vq.run(read_policy=db.EVENTUAL_CONSISTENCY, batch_size=1000) jsondat = moracct.qres2JSON(ctrs) memcache.set(cqk, jsondat) moracct.writeJSONResponse(jsondat, self.response)
def post(self): acc = moracct.authenticated(self.request) if not acc or acc.status != "Active": return srverr(self, 403, "Your account must be active to invite others.") pnm = rev.acc_review_modification_authorized(acc, self) if not pnm: #penid did not match a pen the caller controls return #error already reported coop, role = fetch_coop_and_role(self, pnm) if not coop: return #error already reported if role != "Founder" and role != "Moderator": return srverr(self, 403, "You must be a Founder or Moderator to invite others.") email = self.request.get('email') if not email: return srverr(self, 400, "No email specified") email = moracct.normalize_email(email) if not moracct.valid_email_address(email): return srverr(self, 400, "Invalid email address") invacc = None vq = VizQuery(moracct.MORAccount, "WHERE email = :1 LIMIT 1", email) accounts = vq.fetch(1, read_policy=db.EVENTUAL_CONSISTENCY, deadline=10) if len(accounts) > 0: invacc = accounts[0] else: pwd = moracct.random_alphanumeric(18) invacc = moracct.MORAccount(email=email, password=pwd) invacc.modified = nowISO() invacc.status = "Invited" invacc.mailbounce = "" invacc.invites = invacc.invites or "[]" invacc.invites = remove_invites_for_coop(coop.key().id(), invacc.invites) invtoken = moracct.random_alphanumeric(40) invacc.invites = add_invite_for_coop(coop, pnm, invtoken, invacc.invites) invacc.put(); #nocache invacc = moracct.MORAccount.get_by_id(invacc.key().id()) mail_invite_notice(self, pnm, coop, acc, invacc, invtoken) moracct.writeJSONResponse("[{\"email\":\"" + email + "\"}]", self.response)