diff --git a/ceo/tui/Model.py b/ceo/tui/Model.py index 29e081f..741e179 100644 --- a/ceo/tui/Model.py +++ b/ceo/tui/Model.py @@ -48,6 +48,9 @@ class Model: 'cn': '', 'description': '', }, + 'GetGroup': { + 'cn': '', + }, } self.viewdata = deepcopy(self._initial_viewdata) # data which is shared between multiple views diff --git a/ceo/tui/ResultView.py b/ceo/tui/ResultView.py index e118a56..f9ac12f 100644 --- a/ceo/tui/ResultView.py +++ b/ceo/tui/ResultView.py @@ -30,7 +30,10 @@ class ResultView(CeoFrame): def _add_pair(self, key: str, val: str): layout = Layout([10, 1, 10]) self.add_layout(layout) - layout.add_widget(Label(key + ':', align='>'), 0) + if key: + layout.add_widget(Label(key + ':', align='>'), 0) + else: + layout.add_widget(Label(''), 0) layout.add_widget(Label(val, align='<'), 2) # override this method in child classes if desired diff --git a/ceo/tui/groups/GetGroupResultView.py b/ceo/tui/groups/GetGroupResultView.py new file mode 100644 index 0000000..b35333f --- /dev/null +++ b/ceo/tui/groups/GetGroupResultView.py @@ -0,0 +1,18 @@ +import requests + +from ..ResultView import ResultView + + +class GetGroupResultView(ResultView): + def show_result(self, resp: requests.Response): + d = resp.json() + if 'description' in d: + desc = d['description'] + ' (' + d['cn'] + ')' + else: + desc = d['cn'] + self._add_text('Members of ' + desc, center=True) + self._add_text() + for member in d['members']: + self._add_text( + member['cn'] + ' (' + member['uid'] + ')', + center=True) diff --git a/ceo/tui/groups/GetGroupView.py b/ceo/tui/groups/GetGroupView.py new file mode 100644 index 0000000..f7e0af4 --- /dev/null +++ b/ceo/tui/groups/GetGroupView.py @@ -0,0 +1,31 @@ +from asciimatics.widgets import Layout, Text + +from ...utils import http_get +from ..CeoFrame import CeoFrame + + +class GetGroupView(CeoFrame): + def __init__(self, screen, width, height, model): + super().__init__( + screen, height, width, model, 'GetGroup', + save_data=True, + ) + layout = Layout([100], fill_frame=True) + self.add_layout(layout) + self._cn = Text("Group name", "cn") + layout.add_widget(self._cn) + + self.add_flash_message_layout() + self.add_buttons( + back_btn=True, + next_scene='GetGroupResult', on_next=self._next) + self.fix() + + def _next(self): + cn = self._cn.value + self._model.viewdata['GetGroup']['cn'] = cn + self.flash_message('Looking up group...', force_update=True) + try: + self._model.resp = http_get(f'/api/groups/{cn}') + finally: + self.clear_flash_message() diff --git a/ceo/tui/start.py b/ceo/tui/start.py index 2bbfd6f..f3b3d33 100644 --- a/ceo/tui/start.py +++ b/ceo/tui/start.py @@ -12,6 +12,8 @@ from .ResultView import ResultView from .TransactionView import TransactionView from .WelcomeView import WelcomeView from .groups.AddGroupView import AddGroupView +from .groups.GetGroupView import GetGroupView +from .groups.GetGroupResultView import GetGroupResultView from .members.AddUserView import AddUserView from .members.ChangeLoginShellView import ChangeLoginShellView from .members.GetUserView import GetUserView @@ -57,6 +59,8 @@ def screen_wrapper(screen, last_scene, model): ('ChangeLoginShell', ChangeLoginShellView(screen, width, height, model)), ('SetForwardingAddresses', SetForwardingAddressesView(screen, width, height, model)), ('AddGroup', AddGroupView(screen, width, height, model)), + ('GetGroup', GetGroupView(screen, width, height, model)), + ('GetGroupResult', GetGroupResultView(screen, width, height, model)), ] scenes = [ Scene([view], -1, name=name) for name, view in views