Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
boke0 committed Mar 5, 2021
1 parent 8f9fbe3 commit 4d52696
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
27 changes: 13 additions & 14 deletions izanami/controller.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from mitama.app import Controller
from mitama.app.http import Response
from mitama.models import User, Group, Role, Node, is_admin
from mitama.models import User, Group, InnerRole, Node, is_admin
from .model import Repo, Merge, InnerPermission
from .forms import MergeCreateForm, SettingsForm
from .forms import MergeCreateForm, SettingsForm, HookCreateForm
from . import gitHttpBackend

import git
import os
import glob
import shutil
import yaml
import traceback
from io import StringIO
from unidiff import PatchSet

Expand All @@ -32,7 +33,7 @@ def create(self, request):
body = request.post()
repo = Repo()
repo.name = body['name']
repo.owner = Node(body['owner'])
repo.owner = Node.retrieve(body['owner'])
repo.create()
if not (self.app.project_dir / 'git_template').is_dir:
git.Repo.init(
Expand All @@ -47,7 +48,7 @@ def create(self, request):
return Response.redirect(self.app.convert_url('/'+repo.name))
except Exception as err:
error = str(err)
print(error)
traceback.print_exc(err)
return Response.render(template, {
'post': body,
'error': error,
Expand Down Expand Up @@ -198,7 +199,6 @@ def handle(self, request):
repo = Repo.retrieve(name = request.params['repo'])
hooks = list()
for hook in glob.glob(str(self.app.project_dir / 'repos/{}.git/hooks'.format(repo.name)) + '/*'):
print(hook)
hooks.append(os.path.basename(hook))
return Response.render(template, {
'repo': repo,
Expand All @@ -224,7 +224,7 @@ def create(self, request):
form = HookCreateForm(request.post())
with open(self.app.project_dir / 'repos/{}.git/hooks/{}'.format(repo.name, form['name']), 'w') as f:
f.write(form['code'])
return Response.redirect(self.app.convert_url('/{}/hooks/{}'.format(repo.name, form['name'])))
return Response.redirect(self.app.convert_url('/{}/hook/{}'.format(repo.name, form['name'])))
return Response.render(template, {
'repo': repo,
'error': error
Expand All @@ -237,13 +237,13 @@ def update(self, request):
error = ''
if request.method == 'POST':
form = HookCreateForm(request.post())
os.move(
shutil.move(
self.app.project_dir / 'repos/{}.git/hooks/{}'.format(repo.name, request.params['hook']),
self.app.project_dir / 'repos/{}.git/hooks/{}'.format(repo.name, form['name'])
)
with open(self.app.project_dir / 'repos/{}.git/hooks/{}'.format(repo.name, form['name']), 'w') as f:
f.write(form['code'])
return Response.redirect(self.app.convert_url('/{}/hooks/{}'.format(repo.name, form['name'])))
return Response.redirect(self.app.convert_url('/{}/hook/{}'.format(repo.name, form['name'])))
with open(self.app.project_dir / 'repos/{}.git/hooks/{}'.format(repo.name, request.params['hook'])) as f:
code = f.read()
return Response.render(template, {
Expand Down Expand Up @@ -350,17 +350,16 @@ def handle(self, request):
if request.method == "POST":
try:
form = SettingsForm(request.post())
for role_screen_name, role_permissions in form['role'].items():
role = Role.retrieve(screen_name = role_screen_name)
for permission in [InnerPermission.retrieve(screen_name = permission) for permission in role_permissions]:
permission.roles.append(role)
permission.update()
for permission_screen_name, permission_roles in form['permission'].items():
permission = InnerPermission.retrieve(screen_name = permission_screen_name)
permission.roles = [InnerRole.retrieve(screen_name = role) for role in permission_roles]
permission.update()
error = "変更を保存しました"
except Exception as err:
error = str(err)
template = self.view.get_template('settings.html')
return Response.render(template, {
"roles": Role.list(),
"roles": InnerRole.list(),
"permissions": InnerPermission.list(),
"error": error
})
Expand Down
6 changes: 4 additions & 2 deletions izanami/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class MergeCreateForm(Form):
compare = Field(label='マージ対象', required=True)

class SettingsForm(Form):
role = DictField(listed=True)

permission = DictField(listed=True)

class HookCreateForm(Form):
name = Field(label="フック名", required=True)
code = Field(label="コード")
4 changes: 2 additions & 2 deletions izanami/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#from .controller import RepoController, ProxyController, HookController
from .controller import RepoController, ProxyController, HookController, MergeController, SettingController
from .model import Repo, Merge, Permission
from .model import Repo, Merge, InnerPermission


class App(App):
Expand Down Expand Up @@ -49,6 +49,6 @@ def init_app(self):
def view(self):
view = super().view
view.globals.update(
permission=Permission.is_accepted,
permission=InnerPermission.is_accepted,
)
return view
6 changes: 3 additions & 3 deletions izanami/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Database(BaseDatabase):

class Repo(db.Model):
name = Column(String(64), primary_key=True, unique=True)
owner = relation(Node)
owner = relationship(Node)
owner_id = Column(String(64), ForeignKey("mitama_node._id"))
@property
def entity(self):
Expand Down Expand Up @@ -82,11 +82,11 @@ def merge(self):
},
{
"name": "リポジトリの削除",
"screen_name": "remove_repository"
"screen_name": "delete_repository"
},
{
"name": "リポジトリの設定",
"screen_name": "remove_repository"
"screen_name": "update_repository"
}
])

Expand Down
5 changes: 2 additions & 3 deletions izanami/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ <h2 class='mb-4'>設定</h2>
<div class='form-check'>
<input
class='form-check-input'
id='role_{{role.screen_name}}_{{permission.screen_name}}'
type='checkbox'
name='role.{{role.screen_name}}'
value='{{ permission.screen_name }}'
name='permission.{{permission.screen_name}}'
value='{{ role.screen_name }}'
{% if role in permission.roles %}checked{% endif %}
/>
</div>
Expand Down
19 changes: 10 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4d52696

Please sign in to comment.