from asciimatics.widgets import Layout, Text, CheckBox, Label from ...utils import defer, http_post from ..CeoFrame import CeoFrame from ceod.transactions.groups import AddMemberToGroupTransaction class AddMemberToGroupView(CeoFrame): def __init__(self, screen, width, height, model): super().__init__( screen, height, width, model, 'AddMemberToGroup', 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._username = Text('Username:', 'uid') layout.add_widget(self._username) layout.add_widget(Label('')) self._checkbox = CheckBox('subscribe to auxiliary mailing lists') self._checkbox.value = True layout.add_widget(self._checkbox) self.add_buttons( back_btn=True, next_scene='Confirm', on_next=self._next) self.fix() def _next(self): cn = self._cn.value uid = self._username.value self._model.confirm_lines = [ f'Are you sure you want to add {uid} to {cn}?', ] operations = AddMemberToGroupTransaction.operations url = f'/api/groups/{cn}/members/{uid}' # TODO: deduplicate this logic from the CLI if not self._checkbox.value: url += '?subscribe_to_lists=false' operations.remove('subscribe_user_to_auxiliary_mailing_lists') self._model.deferred_req = defer(http_post, url) self._model.operations = operations