def read(request): """Render the page for a group.""" if not request.feature('groups'): raise exc.HTTPNotFound() hashid = request.matchdict["hashid"] slug = request.matchdict.get("slug") group_id = hashids.decode(request, 'h.groups', hashid) group = models.Group.get_by_id(group_id) if group is None: raise exc.HTTPNotFound() if slug is None or slug != group.slug: return exc.HTTPMovedPermanently( location=logic.url_for_group(request, group)) if not request.authenticated_userid: return _login_to_join(request, group) else: user = accounts_models.User.get_by_userid( request.domain, request.authenticated_userid) if group in user.groups: return _read_group(request, group) else: return _join(request, group)
def read(request): """Render the page for a group.""" if not request.feature('groups'): raise exc.HTTPNotFound() hashid = request.matchdict["hashid"] slug = request.matchdict.get("slug") group_id = hashids.decode(request, 'h.groups', hashid) group = models.Group.get_by_id(group_id) if group is None: raise exc.HTTPNotFound() if slug is None or slug != group.slug: return exc.HTTPMovedPermanently( location=logic.url_for_group(request, group)) if not request.authenticated_userid: return _login_to_join(request, group) else: user = accounts_models.User.get_by_userid(request.domain, request.authenticated_userid) if group in user.groups: return _read_group(request, group) else: return _join(request, group)
def join(request): if not request.feature('groups'): raise exc.HTTPNotFound() hashid = request.matchdict["hashid"] group_id = hashids.decode(request, "h.groups", hashid) group = models.Group.get_by_id(group_id) if group is None: raise exc.HTTPNotFound() user = accounts_models.User.get_by_userid( request.domain, request.authenticated_userid) group.members.append(user) request.session.flash(_( "You've joined the {name} group.").format(name=group.name), 'success') return exc.HTTPSeeOther(logic.url_for_group(request, group))
def join(request): if not request.feature('groups'): raise exc.HTTPNotFound() hashid = request.matchdict["hashid"] group_id = hashids.decode(request, "h.groups", hashid) group = models.Group.get_by_id(group_id) if group is None: raise exc.HTTPNotFound() user = accounts_models.User.get_by_userid(request.domain, request.authenticated_userid) group.members.append(user) request.session.flash( _("You've joined the {name} group.").format(name=group.name), 'success') return exc.HTTPSeeOther(logic.url_for_group(request, group))
def test_hashids_decode(): assert hashids.decode("foo", "1V91V4") == (1,) assert hashids.decode("bar", "E8Rz8D") == (1,) assert hashids.decode("foo", "Lgq4nK") == (123,) assert hashids.decode("foo", "zvuvt2") == (1, 2, 3)