Exemple #1
0
    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
            },
        )
Exemple #2
0
 def remove_group(self, req):
     try:
         group = Group.retrieve(screen_name=req.params["id"])
         child = Group.retrieve(req.params["gid"])
         group.remove(child)
     except Exception as err:
         print(err)
         pass
     finally:
         return Response.redirect(
             self.app.convert_url("/groups/" + group.screen_name +
                                  "/settings"))
Exemple #3
0
 def retrieve(self, request):
     try:
         id = request.params["id"]
         if id.isdigit():
             group = Group.retrieve(int(id))
         else:
             group = Group.retrieve(screen_name=id)
         return Response.json(group.to_dict())
     except KeyError as err:
         error = err
         return Response.json({
             "error": err.__class__.__name__,
             "message": err.message,
             "args": err.args,
         })
Exemple #4
0
 def delete(self, request):
     try:
         id = request.params["id"]
         if id.isdigit():
             group = Group.retrieve(int(id))
         else:
             group = Group.retrieve(screen_name=id)
         group.delete()
         return Response.json({"_id": group._id})
     except Exception as err:
         error = err
         return Response.json({
             "error": err.__class__.__name__,
             "message": err.message,
             "args": err.args,
         })
Exemple #5
0
 def icon(self, request):
     try:
         id = request.params["id"]
         if id.isdigit():
             group = Group.retrieve(int(id))
         else:
             group = Group.retrieve(screen_name=id)
         f = magic.Magic(mime=True, uncompress=True)
         mime = f.from_buffer(group.icon)
         return Response(body=group.icon, content_type=mime)
     except KeyError as err:
         return Response.error({
             "error": err.__class__.__name__,
             "message": err.message,
             "args": err.args,
         })
Exemple #6
0
 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})
Exemple #7
0
    def process_result_value(self, value, dialect):
        from mitama.models import Group

        if value == None:
            return None
        else:
            group = Group.retrieve(value)
            return group
Exemple #8
0
 def retrieve(self, req):
     template = self.view.get_template("group/retrieve.html")
     group = Group.retrieve(screen_name=req.params["id"])
     return Response.render(
         template,
         {
             "group": group,
         },
     )
Exemple #9
0
 def list(self, req):
     template = self.view.get_template("group/list.html")
     groups = Group.tree()
     return Response.render(
         template,
         {
             "groups": groups,
         },
     )
Exemple #10
0
 def test_group(self):
     group = Group()
     group.name = "team1"
     group.screen_name = "team1"
     user1 = User()
     user1.name = "bob"
     user1.screen_name = "bob"
     user1.email = "*****@*****.**"
     user2 = User()
     user2.name = "charlie"
     user2.screen_name = "charlie"
     user2.email = "*****@*****.**"
     group.create()
     user1.create()
     user2.create()
     group.append(user1)
     self.assertTrue(group.is_in(user1))
     self.assertFalse(group.is_in(user2))
     pass
Exemple #11
0
 def update(self, request):
     try:
         post = request.post()
         id = request.params["id"]
         if id.isdigit():
             group = Group.retrieve(int(id))
         else:
             group = Group.retrieve(screen_name=id)
         if "screen_name" in post:
             group.screen_name = post["screen_name"]
         if "name" in post:
             group.name = post["name"]
         group.update()
         return Response.json(group.to_dict())
     except KeyError as err:
         error = err
         return Response.json({
             "error": err.__class__.__name__,
             "message": err.message,
             "args": err.args,
         })
Exemple #12
0
 def test_node(self):
     group = Group()
     group.name = "team1"
     group.screen_name = "team1"
     user1 = User()
     user1.name = "bob"
     user1.screen_name = "bob"
     group.create()
     user1.create()
     hoge = ModelC()
     hoge.node = group
     hoge.create()
     piyo = ModelC()
     piyo.node = user1
     piyo.create()
     foo = ModelC()
     foo.node = group._id
     foo.create()
     bar= ModelC()
     bar.node = user1._id
     bar.create()
     self.assertEqual(hoge.node, group)
     self.assertEqual(piyo.node, user1)
     self.assertEqual(foo.node, group)
     self.assertEqual(bar.node, user1)
     pass
Exemple #13
0
    def process_result_value(self, value, dialect):
        prefix = value.split("-")[0]
        if prefix == "user":
            from mitama.models import User

            node = User.retrieve(value)
        elif prefix == "group":
            from mitama.models import Group

            node = Group.retrieve(value)
        else:
            raise TypeError("Invalid ID format")
        return node
Exemple #14
0
 def append(self, req):
     form = req.post()
     try:
         group = Group.retrieve(screen_name=req.params["id"])
         nodes = list()
         if "user" in form:
             for uid in form.getlist("user"):
                 try:
                     nodes.append(User.retrieve(uid))
                 except Exception:
                     pass
         if "group" in form:
             for gid in form.getlist("group"):
                 try:
                     nodes.append(Group.retrieve(gid))
                 except Exception:
                     pass
         group.append_all(nodes)
     except Exception:
         pass
     finally:
         return Response.redirect(
             self.app.convert_url("/groups/" + group.screen_name +
                                  "/settings"))
Exemple #15
0
 def create(self, request):
     post = request.post()
     try:
         group = Group()
         group.screen_name = post["screen_name"]
         group.name = post["name"]
         group.create()
         return Response.json(group.to_dict())
     except KeyError as err:
         error = err
         return Response.json({
             "error": err.__class__.__name__,
             "message": err.message,
             "args": err.args,
         })
Exemple #16
0
 def list(self, request):
     groups = Group.list()
     return Response.json([group.to_dict() for group in groups])
Exemple #17
0
 def create(self, req):
     template = self.view.get_template("group/create.html")
     groups = Group.list()
     error = ""
     if req.method == "POST":
         try:
             form = GroupCreateForm(req.post())
             group = Group()
             group.name = form["name"]
             group.screen_name = form["screen_name"]
             group.icon = resize_icon(form["icon"])
             group.create()
             if form["parent"] is not None:
                 Group.retrieve(form["parent"]).append(group)
             group.append(req.user)
             return Response.redirect(self.app.convert_url("/groups"))
         except ValidationError as err:
             error = str(err)
     return Response.render(template, {
         "groups": groups,
         "icon": load_noimage_group(),
         "error": error
     })