45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
|
from asciimatics.widgets import Layout, Text, CheckBox, Label
|
||
|
|
||
|
from ...utils import defer, http_delete
|
||
|
from ..CeoFrame import CeoFrame
|
||
|
from ceod.transactions.groups import RemoveMemberFromGroupTransaction
|
||
|
|
||
|
|
||
|
class RemoveMemberFromGroupView(CeoFrame):
|
||
|
def __init__(self, screen, width, height, model):
|
||
|
super().__init__(
|
||
|
screen, height, width, model, 'RemoveMemberFromGroup',
|
||
|
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(
|
||
|
'unsubscribe from auxiliary mailing lists', name='unsubscribe')
|
||
|
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 remove {uid} from {cn}?',
|
||
|
]
|
||
|
operations = RemoveMemberFromGroupTransaction.operations
|
||
|
url = f'/api/groups/{cn}/members/{uid}'
|
||
|
# TODO: deduplicate this logic from the CLI
|
||
|
if not self._checkbox.value:
|
||
|
url += '?unsubscribe_from_lists=false'
|
||
|
operations.remove('unsubscribe_user_from_auxiliary_mailing_lists')
|
||
|
self._model.deferred_req = defer(http_delete, url)
|
||
|
self._model.operations = operations
|