def can_access_world(self, world): if world is not None: if world.publish: return if get_current_user(): if world.creator == self.page_user.key: return raise web.notfound()
def GET(self, world, auth_key): cur_world = world_exists(world) try: user_pending = ndb.Key(urlsafe=auth_key).get() pending_mods = user_pending.get_pending_mods().get_result() for m in pending_mods: m.user_pending = None m.user = get_current_user().key m.put() user_pending.key.delete() except: return web.seeother("/") return web.seeother("/%s/texts" % world)
def POST(self, world): cur_world = world_exists(world) self.redirect_if_not_admin(cur_world) param = web.input() if hasattr(param, 'mod'): # Access rights form submitted edit_mod = ndb.Key("Moderator", int(param.userid)).get() if int(param.action) == 1: edit_mod.admin = True if int(param.action) == 2: edit_mod.admin = False if int(param.action) == 0: try: edit_mod.user_pending.delete() except AttributeError: # (no pending user) pass edit_mod.key.delete() else: edit_mod.put() raise web.seeother("/%s/mods" % world) f = self.moderator_form() form = CombinedForm([f], **self.formargs) if not f.validates(): mods_ftr = cur_world.get_moderators() access = cur_world.get_access_string(self.page_user) world_menu = self.get_or_put_menu(cur_world, access) world_menu['contributors'][0][2] = "active" f = self.moderator_form() form = CombinedForm([f], **self.formargs) cur_mods = mods_ftr.get_result() section = render().section_moderators(form, cur_mods) return render().admin(cur_world, section, world_menu, title="Moderators of %s on Palimpsest" % cur_world.title, post=self.epost) else: try_user = users.User(f.d.add_contrib) user_result = get_google_user_key(try_user).get_result() if len(user_result) > 0 and user_result[0] is not None: user = user_exists_bykey(user_result[0]) m = Moderator(world=cur_world.key, user=user.key, admin=False) msg = """You've been added as a contributor to %s. This means you can add texts and properties which are published straight away. You can also approve or reject publicly submitted texts and properties. Try it out: %s/%s/texts""" % (cur_world.title, web.ctx.host, cur_world.key.id()) else: email = str(f.d.add_contrib).lower() # TODO: Check UserPending doesn't already exist with that email u_p = UserPending(email=email) u_p.put() m = Moderator(world=cur_world.key, user_pending=u_p.key, admin=False) msg = """You've been added as a contributor to %s. This means you can add texts which bypass the moderation stage, and are published straight away. Try it out: %s/%s/auth/%s""" % (cur_world.title, web.ctx.host, cur_world.key.id(), str(u_p.key.id())) m.put() to_addr = f.d.add_contrib if not mail.is_email_valid(to_addr): return "Could not send: invalid email. Press back and try again." message = mail.EmailMessage() message.sender = get_current_user().user.email() message.to = to_addr message.subject = "Palimpsest: You have been added as a moderator of %s!" % cur_world.title message.body = msg message.send() return web.seeother('/%s/mods' % cur_world.key.id())
def can_edit_save(self, save): if save is not None: if get_current_user(): if save.user == self.page_user.key: return raise web.notfound()