def create(self, request): template = self.view.get_template("repo/create.html") nodes = [*Group.list(), *User.list()] try: if request.method == 'POST': body = request.post() repo = Repo() repo.name = body['name'] repo.owner = Node.retrieve(body['owner']) repo.create() if not (self.app.project_dir / 'git_template').is_dir: git.Repo.init(self.app.project_dir / 'git_template', bare=True) git.Repo.init(self.app.project_dir / ('repos/' + repo.name + '.git'), bare=True, template=self.app.project_dir / 'git_template') return Response.redirect(self.app.convert_url('/' + repo.name)) except Exception as err: error = str(err) traceback.print_exc(err) return Response.render(template, { 'post': body, 'error': error, 'nodes': nodes }) return Response.render(template, {'post': dict(), 'nodes': nodes})
def list(self, req): template = self.view.get_template("user/list.html") users = User.list() return Response.render( template, { "users": users, }, )
def update(self, req): template = self.view.get_template("group/update.html") group = Group.retrieve(screen_name=req.params["id"]) groups = list() for g in Group.list(): if not (group.is_ancestor(g) or group.is_descendant(g) or g == group): groups.append(g) users = list() error = "" message = "" for u in User.list(): if not group.is_in(u): users.append(u) if req.method == "POST": try: form = GroupUpdateForm(req.post()) icon = resize_icon( form["icon"]) if form["icon"] is not None else group.icon group.screen_name = form["screen_name"] group.name = form["name"] group.parent = Group.retrieve( form["parent"]) if form["parent"] is not None else None for role in form["roles"]: group.roles.append(Role.retrieve(screen_name=role)) group.icon = icon group.users = [User.retrieve(user) for user in form['users']] if form['new_user'] is not None: group.users.append(User.retrieve(form['new_user'])) for user, roles in form['inner_roles'].items(): rel = UserGroup.retrieve(group=group, user=User.retrieve(user)) rel.roles = [InnerRole.retrieve(role) for role in roles] group.update() message = "変更を保存しました" except ValidationError as err: error = str(err) roles = Role.list() inner_roles = InnerRole.list() return Response.render( template, { "message": message, "error": error, "group": group, "all_groups": groups, "all_users": users, "screen_name": group.screen_name, "name": group.name, "icon": group.icon, "roles": roles, "inner_roles": inner_roles }, )
def setup(self, request): template = self.view.get_template("setup.html") if len(User.list()) > 0: return Response.redirect(self.app.convert_url("/login")) if request.method == "POST": try: form = SetupForm(request.post()) try: owner = Role() owner.name = "Owner" owner.create() manager = Role() manager.name = "Manager" manager.create() normal = Role() normal.name = "Normal" normal.create() inner_owner = InnerRole() inner_owner.name = "Owner" inner_owner.create() inner_manager = InnerRole() inner_manager.name = "Manager" inner_manager.create() inner_normal = InnerRole() inner_normal.name = "Normal" inner_normal.create() except Exception: pass Permission.accept("admin", owner) Permission.accept("create_user", owner) Permission.accept("update_user", owner) Permission.accept("delete_user", owner) Permission.accept("create_group", owner) Permission.accept("update_group", owner) Permission.accept("delete_group", owner) Permission.accept("create_user", manager) Permission.accept("update_user", manager) Permission.accept("create_group", manager) Permission.accept("update_group", manager) InnerPermission.accept("admin", inner_owner) InnerPermission.accept("add_user", inner_owner) InnerPermission.accept("remove_user", inner_owner) InnerPermission.accept("add_group", inner_owner) InnerPermission.accept("remove_group", inner_owner) InnerPermission.accept("add_user", inner_manager) InnerPermission.accept("remove_user", inner_owner) InnerPermission.accept("add_group", inner_manager) InnerPermission.accept("remove_group", inner_owner) user = UserInvite() user.email = form["email"] user.roles = owner._id user.create() user.mail( "Mitamaへようこそ", "下記リンクから、Mitamaに参加しましょう\n{}".format( self.app.convert_fullurl(request, "/signup?token=" + user.token))) template = self.view.get_template("confirm.html") return Response.render(template) except ValidationError as err: return Response.render(template, {"error": str(err)}) return Response.render(template)
def list(self, request): users = User.list() return Response.json([user.to_dict for user in users])
def handle(self, request): template = self.view.get_template("welcome.html") return Response.render(template, {"users": User.list()})