コード例 #1
0
ファイル: roles.py プロジェクト: knowark/authark
    def build(self) -> None:
        super().build()
        self.modal = None

        frame = Frame(
            self, title='Role').title_style(Color.SUCCESS()).weight(3, 2)
        Label(frame, content='Name:').grid(0, 0)
        self.name = Entry(frame, content=self.role['name']).style(
            border=[0]).grid(0, 1).weight(col=2)
        Label(frame, content='Description:').grid(1, 0)
        self.description = Entry(
            frame, content=self.role['description']).style(
            border=[0]).grid(1, 1).weight(col=2)
        Label(frame, content='ID:').grid(2, 0)
        Label(frame, content=f'{self.role["id"]}').grid(2, 1)

        menu = Frame(self, title='Menu').grid(col=1)
        Button(menu, content='Policies',
               command=self.on_policies).style(border=[0])
        Button(menu, content='Users',
               command=self.on_users).grid(1).style(
                   Color.SUCCESS(), border=[0])

        actions = Frame(
            self, title='Actions').title_style(
                Color.WARNING()).grid(1).span(col=2)
        Button(actions, content='Delete', command=self.on_delete
               ).style(Color.DANGER()).grid(0, 1)
        Spacer(actions).grid(0, 2).weight(col=2)
        Button(actions, content='Save', command=self.on_save
               ).style(Color.SUCCESS()).grid(0, 3)
        Button(actions, content='Cancel', command=self.on_cancel
               ).style(Color.WARNING()).grid(0, 4)
コード例 #2
0
ファイル: policies.py プロジェクト: knowark/authark
    def build(self) -> None:
        super().build()
        self.modal = None

        frame = Frame(self,
                      title='Policy').title_style(Color.SUCCESS()).weight(
                          4, 2)
        Label(frame, content='Resource:').grid(0, 0)
        self.resource = Entry(frame, content=self.policy['resource']).style(
            border=[0]).grid(0, 1).weight(col=2)
        Label(frame, content='Privilege:').grid(1, 0)
        self.privilege = Entry(frame, content=self.policy['privilege']).style(
            border=[0]).grid(1, 1).weight(col=2)
        Label(frame, content='Active:').grid(2, 0)
        self.active = Entry(frame, content=str(
            self.policy['active'])).style(border=[0]).grid(2, 1).weight(col=2)
        Label(frame, content='ID:').grid(3, 0)
        Label(frame, content=f'{self.policy["id"]}').grid(3, 1)

        menu = Frame(self, title='Menu').grid(col=1)
        Button(menu, content='Restrictions',
               command=self.on_restrictions).style(border=[0])
        Spacer(menu).grid(1)

        actions = Frame(self, title='Actions').title_style(
            Color.WARNING()).grid(1).span(col=2)
        Button(actions, content='Delete',
               command=self.on_delete).style(Color.DANGER()).grid(0, 1)
        Spacer(actions).grid(0, 2).weight(col=2)
        Button(actions, content='Save',
               command=self.on_save).style(Color.SUCCESS()).grid(0, 3)
        Button(actions, content='Cancel',
               command=self.on_cancel).style(Color.WARNING()).grid(0, 4)
コード例 #3
0
ファイル: roles.py プロジェクト: knowark/authark
    def build(self) -> None:
        super().build()
        self.modal = None

        available_frame = Frame(self, title='Available').weight(
            5, 4).grid(0, 0)
        self.available_search = Entry(
            available_frame, command=self.on_available_search).listen(
                'keydown', self.on_available_search, True).weight(
                    col=2).grid(0, 0)
        self.available_total = Label(
            available_frame, content='Total: 0').grid(0, 1)
        self.available = Listbox(
            available_frame, command=self.on_select).weight(
                9).span(col=2).grid(1)

        switchers = Frame(self).title_style(
            Color.SUCCESS()).style(border=[]).weight(5).grid(0, 1)

        Button(switchers, content='\U000025B6', command=self.on_choose).style(
            Color.SUCCESS(), border=[], template='{}').grid(0)
        Button(switchers, content='\U000025C0', command=self.on_clear).style(
            Color.SUCCESS(), border=[], template='{}').grid(1)
        Button(switchers, content='\U000023E9',
               command=self.on_choose_all).style(
            Color.SUCCESS(), border=[], template='{}').grid(2)
        Button(switchers, content='\U000023EA',
               command=self.on_clear_all).style(
            Color.SUCCESS(), border=[], template='{}').grid(3)

        chosen_frame = Frame(self, title='Chosen').weight(
            5, 4).grid(0, 2)
        self.chosen_search = Entry(chosen_frame).listen(
            'keydown', self.on_chosen_search, True).weight(col=2).grid(0, 0)
        self.chosen_total = Label(
            chosen_frame, content='Total: 0').grid(0, 1)
        self.chosen = Listbox(
            chosen_frame, command=self.on_select).weight(
                9).span(col=2).grid(1)

        actions = Frame(
            self, title='Actions').title_style(
                Color.WARNING()).grid(1).span(col=3)
        Label(actions, content=f'Role: {self.role["name"]}').grid(0, 2)
        Spacer(actions).grid(0, 3).weight(col=1)
        Button(actions, content='Save', command=self.on_save
               ).style(Color.SUCCESS()).grid(0, 4)
        Button(actions, content='Cancel', command=self.on_cancel
               ).style(Color.WARNING()).grid(0, 5)
コード例 #4
0
ファイル: users.py プロジェクト: knowark/authark
 def build(self) -> None:
     self.modal = None
     self.title = 'Users'
     self.style(Color.SUCCESS())
     Button(self, content='\U00002795 Create',
            command=self.on_create).grid(0, 0)
     Label(self, content='\U0001F50D Search:').grid(0, 1)
     self.search = Entry(self).grid(0, 2).style(
         border=[0]).weight(col=3)
     self.header = Listbox(
         self, data=['ID', 'Name', 'Email'],
         orientation='horizontal').grid(1).span(col=3)
     self.body = Listbox(
         self, command=self.on_body).grid(3).span(col=3).weight(9)
     self.search.listen('keydown', self.on_search, True)
コード例 #5
0
    def build(self) -> None:
        self.modal = None
        self.style(border=['*'] * 8)

        master = Frame(self, title='Master').grid(0).style(
            background_color=Color.LIGHT.reverse(),
            border_color=Color.PRIMARY.reverse())

        Label(master, content='Label:').grid(0,
                                             0).style(Color.DANGER.reverse(),
                                                      Color.DANGER.reverse())

        Button(master, content='Create',
               command=self.launch_modal).grid(0, 1).style(
                   Color.SUCCESS.reverse(), Color.SUCCESS.reverse())

        Frame(master, title='Details').title_style(Color.DANGER()).grid(
            1, 0).span(col=3).weight(3).style(
                background_color=Color.LIGHT.reverse())

        world = Frame(self, title='World').title_style(Color.WARNING()).grid(1)
        Entry(world)

        Content(self, title='Content').grid(0, 1).span(3).weight(col=3)

        self.listen('click', self.on_backdrop_click, True)
コード例 #6
0
    def build(self) -> None:
        self.left = Frame(self, title='Left').grid(0, 1)
        Button(self.left, content='Content UP',
               command=self.on_click).style(Color.INFO(),
                                            Color.DANGER.reverse(),
                                            border=[0],
                                            align='C').grid(0)
        Button(self.left, content='MIDDLE UP BUTTON',
               command=self.on_click).style(Color.WARNING(),
                                            border=[0],
                                            align='C').grid(1)
        Button(self.left, content='MIDDLE DOWN BUTTON',
               command=self.on_click).style(Color.DANGER(),
                                            border=[0],
                                            align='C').grid(2)

        Entry(
            self.left,
            content=
            ('Nulla mollis mollis ornare. Cras tempor, metus semper pulvinar '
             '\nmattis, metus urna hendrerit orci, eget gravida tellus '
             '\nipsum a ex. Donec hendrerit metus vitae hendrerit dictum. '
             '\nSed varius venenatis ligula in scelerisque. Donec luctus sem '
             '\nnon lorem venenatis, eget lobortis tortor tincidunt. Nunc '
             '\nquis venenatis diam. Ut ac aliquam mi, a tempus nunc. Nunc '
             '\nluctus vulputate dui malesuada cursus.')).style(
                 Color.LIGHT(), border=[0]).grid(3)

        self.right = Frame(self, title='Right').grid(0, 2)

        data = [{'name': 'first'}, {'name': 'second'}, {'name': 'third'}] * 3
        Listbox(self.right,
                data=data,
                limit=4,
                item_style=Style(border=[], align='C'))
コード例 #7
0
    def build(self) -> None:
        super().build()
        frame = Frame(self,
                      title='Tenant').weight(6).title_style(Color.LIGHT())
        Label(frame, content='ID:').grid(0, 0)
        self.id = Entry(frame,
                        content=' ').style(border=[0]).grid(0, 1).weight(col=2)
        Label(frame, content='Name:').grid(1, 0)
        self.name = Entry(frame,
                          content=' ').style(border=[0]).grid(1,
                                                              1).weight(col=2)

        actions = Frame(self, title='Actions').grid(1).title_style(
            Color.WARNING()).weight(3)
        Spacer(actions).grid(0, 2).weight(col=2)
        Button(actions, content='Save',
               command=self.on_save).style(Color.SUCCESS()).grid(0, 3)
        Button(actions, content='Cancel',
               command=self.on_cancel).style(Color.WARNING()).grid(0, 4)
コード例 #8
0
ファイル: users.py プロジェクト: knowark/authark
    def build(self) -> None:
        super().build()
        frame = Frame(
            self, title='User').title_style(Color.SUCCESS()).weight(6, 3)
        Label(frame, content='Name:').grid(0, 0)
        self.name = Entry(frame, content=self.user['name']).style(
            border=[0]).grid(0, 1).weight(col=2)
        Label(frame, content='Username:'******'username']).style(
            border=[0]).grid(1, 1).weight(col=2)
        Label(frame, content='Email:').grid(2, 0)
        self.email = Entry(frame, content=self.user['email']).style(
            border=[0]).grid(2, 1).weight(col=2)
        Label(frame, content='Password:'******'Attributes:').grid(4, 0)

        self.attributes = Entry(
            frame, content=json.dumps(
                self.user['attributes'], indent=4)).style(
            border=[0]).grid(4, 1).weight(4, 2)

        menu = Frame(self, title='Menu').grid(col=1)
        Button(menu, content='Roles', command=self.on_roles).style(border=[0])
        Button(menu, content='Credentials',
               command=self.on_credentials).style(border=[0]).grid(1)
        Spacer(menu).grid(2).weight(2)

        actions = Frame(self, title='Actions').title_style(
            Color.WARNING()).grid(1).span(col=2)
        Button(actions, content='Delete', command=self.on_delete
               ).style(Color.DANGER()).grid(0, 1)
        Spacer(actions).grid(0, 2).weight(col=2)
        Button(actions, content='Save', command=self.on_save
               ).style(Color.SUCCESS()).grid(0, 3)
        Button(actions, content='Cancel', command=self.on_cancel
               ).style(Color.WARNING()).grid(0, 4)
コード例 #9
0
    def build(self) -> None:
        super().build()
        self.modal = None

        frame = Frame(
            self, title='Restriction').title_style(
                Color.SUCCESS()).weight(4, 2)

        Label(frame, content='Sequence:').grid(0, 0)
        self.sequence = Entry(
            frame, content=str(self.restriction['sequence'])).style(
            border=[0]).grid(0, 1).weight(col=2)
        Label(frame, content='Name:').grid(1, 0)
        self.name = Entry(frame, content=self.restriction['name']).style(
            border=[0]).grid(1, 1).weight(col=2)
        Label(frame, content='Target:').grid(2, 0)
        self.target = Entry(
            frame, content=str(self.restriction['target'])).style(
            border=[0]).grid(2, 1).weight(col=2)
        Label(frame, content='Domain:').grid(3, 0)
        self.domain = Entry(
            frame, content=str(self.restriction['domain'])).style(
            border=[0]).grid(3, 1).weight(2, 2)
        Label(frame, content='ID:').grid(4, 0)
        Label(frame, content=f'{self.restriction["id"]}').grid(4, 1)

        actions = Frame(
            self, title='Actions').title_style(
                Color.WARNING()).grid(1).span(col=2)
        Button(actions, content='Delete', command=self.on_delete
               ).style(Color.DANGER()).grid(0, 1)
        Spacer(actions).grid(0, 2).weight(col=2)
        Button(actions, content='Save', command=self.on_save
               ).style(Color.SUCCESS()).grid(0, 3)
        Button(actions, content='Cancel', command=self.on_cancel
               ).style(Color.WARNING()).grid(0, 4)
コード例 #10
0
    def build(self) -> None:
        super().build()
        self.modal = None

        frame = Frame(self,
                      title='Dominion').title_style(Color.SUCCESS()).weight(
                          4, 2)
        Label(frame, content='Name:').grid(0, 0)
        self.name = Entry(frame, content=self.dominion['name']).style(
            border=[0]).grid(0, 1).weight(col=2)
        Spacer(frame).grid(2).span(col=2)

        actions = Frame(self, title='Actions').title_style(
            Color.WARNING()).grid(1).span(col=2)
        Button(actions, content='Delete',
               command=self.on_delete).style(Color.DANGER()).grid(0, 1)
        Spacer(actions).grid(0, 2).weight(col=2)
        Button(actions, content='Save',
               command=self.on_save).style(Color.SUCCESS()).grid(0, 3)
        Button(actions, content='Cancel',
               command=self.on_cancel).style(Color.WARNING()).grid(0, 4)
コード例 #11
0
ファイル: roles.py プロジェクト: knowark/authark
class UsersSelectionModal(Modal):
    def setup(self, **context) -> 'RoleDetailsModal':
        self.injector = context['injector']
        self.authark_informer = self.injector['StandardInformer']
        self.management_manager = self.injector['ManagementManager']
        self.role = context['role']
        self.focused: Dict = {}
        self.available_domain: List = []
        self.chosen_domain: List = []
        return super().setup(**context) and self

    def build(self) -> None:
        super().build()
        self.modal = None

        available_frame = Frame(self, title='Available').weight(
            5, 4).grid(0, 0)
        self.available_search = Entry(
            available_frame, command=self.on_available_search).listen(
                'keydown', self.on_available_search, True).weight(
                    col=2).grid(0, 0)
        self.available_total = Label(
            available_frame, content='Total: 0').grid(0, 1)
        self.available = Listbox(
            available_frame, command=self.on_select).weight(
                9).span(col=2).grid(1)

        switchers = Frame(self).title_style(
            Color.SUCCESS()).style(border=[]).weight(5).grid(0, 1)

        Button(switchers, content='\U000025B6', command=self.on_choose).style(
            Color.SUCCESS(), border=[], template='{}').grid(0)
        Button(switchers, content='\U000025C0', command=self.on_clear).style(
            Color.SUCCESS(), border=[], template='{}').grid(1)
        Button(switchers, content='\U000023E9',
               command=self.on_choose_all).style(
            Color.SUCCESS(), border=[], template='{}').grid(2)
        Button(switchers, content='\U000023EA',
               command=self.on_clear_all).style(
            Color.SUCCESS(), border=[], template='{}').grid(3)

        chosen_frame = Frame(self, title='Chosen').weight(
            5, 4).grid(0, 2)
        self.chosen_search = Entry(chosen_frame).listen(
            'keydown', self.on_chosen_search, True).weight(col=2).grid(0, 0)
        self.chosen_total = Label(
            chosen_frame, content='Total: 0').grid(0, 1)
        self.chosen = Listbox(
            chosen_frame, command=self.on_select).weight(
                9).span(col=2).grid(1)

        actions = Frame(
            self, title='Actions').title_style(
                Color.WARNING()).grid(1).span(col=3)
        Label(actions, content=f'Role: {self.role["name"]}').grid(0, 2)
        Spacer(actions).grid(0, 3).weight(col=1)
        Button(actions, content='Save', command=self.on_save
               ).style(Color.SUCCESS()).grid(0, 4)
        Button(actions, content='Cancel', command=self.on_cancel
               ).style(Color.WARNING()).grid(0, 5)

    async def on_select(self, event: Event) -> None:
        item = getattr(event.target.parent, 'item', None)
        event.target.focus()
        self.focused = item if isinstance(item, dict) else {}

    async def on_available_search(self, event: Event) -> None:
        if event.key == '\n':
            event.stop = True
            text = self.available_search.text.strip()
            self.available.offset = 0
            self.available_domain = [] if not text else [
                '|',  ('name', 'ilike', f'%{text}%'),
                ('email', 'ilike', f'%{text}%')]
            await self.load()
            self.available_search.focus()

    async def on_chosen_search(self, event: Event) -> None:
        if event.key == '\n':
            event.stop = True
            text = self.chosen_search.text.strip()
            self.chosen.offset = 0
            self.chosen_domain = [] if not text else [
                '|',  ('name', 'ilike', f'%{text}%'),
                ('email', 'ilike', f'%{text}%')]
            await self.load()
            self.chosen_search.focus()

    async def load(self) -> None:
        current_user_ids = [ranking['user_id'] for ranking in
                            (await self.authark_informer.search({
                                "meta": {
                                    "model": "ranking",
                                    "domain": [
                                        ('role_id', '=', self.role['id'])]
                                }
                                }))['data']
                            ]
        available_users = (await self.authark_informer.search({
            "meta": {
                "model": "user",
                "domain": [
            '!', ('id', 'in', current_user_ids)] + self.available_domain
            }
        }))['data']
        chosen_users = (await self.authark_informer.search({
            "meta": {
                "model": "user",
                "domain": [
            ('id', 'in', current_user_ids)] + self.chosen_domain
            }
        }))['data']

        self.available.setup(data=available_users,
                             fields=['username', 'email'],
                             limit=20).connect()
        self.chosen.setup(data=chosen_users,
                          fields=['username', 'email'],
                          limit=20).connect()
        self._update_totals()

    async def on_choose(self, event: Event) -> None:
        self._switch(self.focused, self.available, self.chosen)
        self._update_totals()

    async def on_choose_all(self, event: Event) -> None:
        self.chosen.data = list(self.available.data + self.chosen.data)
        self.available.data = []
        self.chosen.connect()
        self.available.connect()
        self._update_totals()

    async def on_clear(self, event: Event) -> None:
        self._switch(self.focused, self.chosen, self.available)
        self._update_totals()

    async def on_clear_all(self, event: Event) -> None:
        self.available.data = list(self.available.data + self.chosen.data)
        self.chosen.data = []
        self.available.connect()
        self.chosen.connect()
        self._update_totals()

    def _update_totals(self) -> None:
        self.available_total.setup(
            content=f'Total: {len(self.available.data)}').render()
        self.chosen_total.setup(
            content=f'Total: {len(self.chosen.data)}').render()

    def _switch(self, item: Optional[Dict[str, Any]],
                source: Listbox, target: Listbox) -> None:
        if item and item in source.data:
            source.data.remove(item)
            source.connect()
        if item and item not in target.data:
            target.data.insert(0, item)
            target.connect()

    async def on_save(self, event: Event) -> None:
        removing_ranking_ids = [
            ranking['id'] for ranking in (await self.authark_informer.search({
                "meta": {
                    "model": "ranking",
                    "domain": [('role_id', '=', self.role['id']),
                            ('user_id', 'in', [user['id'] for user in
                                               self.available.data])]
                    }
                }))['data']
        ]
        await self.management_manager.deassign_role(removing_ranking_ids)
        adding_rankings = [{'role_id': self.role['id'], 'user_id': user['id']}
                           for user in self.chosen.data]
        await self.management_manager.assign_role({
            "meta": {},
            "data": adding_rankings
        })
        await self.done({'result': 'saved'})

    async def on_cancel(self, event: Event) -> None:
        await self.done({'result': 'cancelled'})
コード例 #12
0
ファイル: users.py プロジェクト: knowark/authark
class UsersScreen(Frame):
    def setup(self, **context) -> 'UsersScreen':
        self.injector = context['injector']
        self.authark_informer = self.injector['StandardInformer']
        self.user = None
        self.domain: List[Any] = []
        return super().setup(**context) and self

    def build(self) -> None:
        self.modal = None
        self.title = 'Users'
        self.style(Color.SUCCESS())
        Button(self, content='\U00002795 Create',
               command=self.on_create).grid(0, 0)
        Label(self, content='\U0001F50D Search:').grid(0, 1)
        self.search = Entry(self).grid(0, 2).style(
            border=[0]).weight(col=3)
        self.header = Listbox(
            self, data=['ID', 'Name', 'Email'],
            orientation='horizontal').grid(1).span(col=3)
        self.body = Listbox(
            self, command=self.on_body).grid(3).span(col=3).weight(9)
        self.search.listen('keydown', self.on_search, True)

    async def load(self) -> None:
        users = (await self.authark_informer.search({
            "meta": {
                "model": "user",
                "domain": self.domain
            }
        }))['data']
        self.body.setup(
            data=users, fields=['id', 'name', 'email'], limit=20).connect()

    async def on_body(self, event: Event) -> None:
        self.user = getattr(event.target.parent, 'item', None)
        if self.user:
            self.modal = UserDetailsModal(
                self, injector=self.injector, user=self.user,
                done_command=self.on_modal_done,
                proportion={'height': 0.90, 'width': 0.90}).launch()

    async def on_search(self, event: Event) -> None:
        if event.key == '\n':
            event.stop = True
            self.body.offset = 0
            text = self.search.text.strip()
            self.domain = [] if not text else [
                '|',  ('name', 'ilike', f'%{text}%'),
                ('email', 'ilike', f'%{text}%')]
            await self.load()
            self.search.focus()

    async def on_create(self, event: Event) -> None:
        user = {'name': '', 'username': '', 'email': '', 'attributes': {}}
        self.modal = UserDetailsModal(
            self, injector=self.injector, user=user,
            done_command=self.on_modal_done,
            proportion={'height': 0.90, 'width': 0.90}).launch()

    async def on_modal_done(self, event: Event) -> None:
        self.remove(self.modal)
        self.modal = None
        if event.details['result'] == 'roles':
            self.modal = RankingsModal(
                self, injector=self.injector,
                user=self.user,
                done_command=self.on_modal_done).launch()
        elif event.details['result'] == 'credentials':
            self.modal = CredentialsModal(
                self, injector=self.injector,
                user=self.user,
                done_command=self.on_modal_done).launch()
        else:
            await self.load()
        self.render()
        self.body.focus()