From 169adaa6fa80ab66180abb01777f1cb85bebd247 Mon Sep 17 00:00:00 2001 From: Samuel Carswell Date: Mon, 11 May 2026 08:41:33 +1000 Subject: [PATCH 1/3] AB#8166 `group field` -> `org field` --- austrakka/components/group/__init__.py | 2 - austrakka/components/group/field/__init__.py | 47 ---------------- austrakka/components/group/field/funcs.py | 57 -------------------- austrakka/components/org/__init__.py | 3 ++ austrakka/components/org/field/__init__.py | 47 ++++++++++++++++ austrakka/components/org/field/funcs.py | 44 +++++++++++++++ austrakka/utils/helpers/output.py | 4 +- 7 files changed, 96 insertions(+), 108 deletions(-) delete mode 100644 austrakka/components/group/field/__init__.py delete mode 100644 austrakka/components/group/field/funcs.py create mode 100644 austrakka/components/org/field/__init__.py create mode 100644 austrakka/components/org/field/funcs.py diff --git a/austrakka/components/group/__init__.py b/austrakka/components/group/__init__.py index 01cda44e..477e437d 100644 --- a/austrakka/components/group/__init__.py +++ b/austrakka/components/group/__init__.py @@ -1,7 +1,6 @@ # pylint: disable=expression-not-assigned import click -from austrakka.components.group.field import field from austrakka.components.group.funcs import add_group from austrakka.components.group.funcs import list_group from austrakka.components.group.funcs import update_group @@ -19,7 +18,6 @@ def group(ctx): ctx.context = ctx.parent.context -group.add_command(field) if show_admin_cmds() else None group.add_command(role) if show_admin_cmds() else None diff --git a/austrakka/components/group/field/__init__.py b/austrakka/components/group/field/__init__.py deleted file mode 100644 index ffb77612..00000000 --- a/austrakka/components/group/field/__init__.py +++ /dev/null @@ -1,47 +0,0 @@ -from typing import List -import click - -from austrakka.utils.output import table_format_option -from austrakka.utils.cmd_filter import hide_admin_cmds -from austrakka.utils.options import * -from .funcs import \ - add_field_group, \ - remove_field_group, \ - list_field_group - - -@click.group() -@click.pass_context -def field(ctx): - """Commands related to group fields access""" - ctx.context = ctx.parent.context - - -@field.command('add', hidden=hide_admin_cmds()) -@click.argument('name', type=str) -@opt_field_name() -def group_add_field(name, field_names): - ''' - Allow fields to show for the given group. - ''' - add_field_group(name, field_names) - - -@field.command('remove', hidden=hide_admin_cmds()) -@click.argument('name', type=str) -@opt_field_name() -def group_remove_field(name, field_names): - ''' - Deny fields from showing for the given group. - ''' - remove_field_group(name, field_names) - - -@field.command('list', hidden=hide_admin_cmds()) -@click.argument('name', type=str) -@table_format_option() -def group_list_field(name: str, out_format: str): - ''' - List of fields allowed to show for the given group. - ''' - list_field_group(name, out_format) diff --git a/austrakka/components/group/field/funcs.py b/austrakka/components/group/field/funcs.py deleted file mode 100644 index c9c08b4f..00000000 --- a/austrakka/components/group/field/funcs.py +++ /dev/null @@ -1,57 +0,0 @@ -from typing import List - -from austrakka.utils.api import api_get -from austrakka.utils.api import api_patch -from austrakka.utils.misc import logger_wraps -from austrakka.utils.output import print_dataframe, read_pd -from austrakka.utils.paths import GROUP_PATH - - -@logger_wraps() -def add_field_group(name: str, field_names: List[str]): - - field_name_objs = [] - for field_name in field_names: - field_name_objs.append({ - "ColumnName": field_name - }) - - return api_patch( - path=f'{GROUP_PATH}/allow-fields/{name}', - data={ - "columnNames": field_name_objs - } - ) - - -@logger_wraps() -def remove_field_group(name: str, field_names: List[str]): - - field_name_objs = [] - for field_name in field_names: - field_name_objs.append({ - "ColumnName": field_name - }) - - return api_patch( - path=f'{GROUP_PATH}/deny-fields/{name}', - data={ - "columnNames": field_name_objs - } - ) - - -@logger_wraps() -def list_field_group(name: str, out_format: str): - - response = api_get( - path=f'{GROUP_PATH}/allowed-fields/{name}', - ) - - data = response['data'] if ('data' in response) else response - result = read_pd(data, out_format) - - print_dataframe( - result, - out_format, - ) diff --git a/austrakka/components/org/__init__.py b/austrakka/components/org/__init__.py index 0680b55a..66da870c 100644 --- a/austrakka/components/org/__init__.py +++ b/austrakka/components/org/__init__.py @@ -10,6 +10,8 @@ from austrakka.utils.privilege import ORG_RESOURCE from austrakka.components.iam.privilege import privilege_subcommands from austrakka.components.log import log_subcommands +from austrakka.components.org.field import field +from austrakka.utils.cmd_filter import show_admin_cmds from .funcs import list_orgs from .funcs import add_org from .funcs import update_org @@ -23,6 +25,7 @@ def org(ctx): org.add_command(privilege_subcommands(ORG_RESOURCE)) org.add_command(log_subcommands(ORG_RESOURCE)) +org.add_command(field) if show_admin_cmds() else None @org.command('list', help="List organisations") @table_format_option() diff --git a/austrakka/components/org/field/__init__.py b/austrakka/components/org/field/__init__.py new file mode 100644 index 00000000..a67dbf83 --- /dev/null +++ b/austrakka/components/org/field/__init__.py @@ -0,0 +1,47 @@ +import click + +from austrakka.utils.output import table_format_option +from austrakka.utils.cmd_filter import hide_admin_cmds +from austrakka.utils.options import * +from .funcs import \ + add_field, \ + remove_field, \ + list_field + + +@click.group() +@click.pass_context +def field(ctx): + """Commands related to group fields access""" + ctx.context = ctx.parent.context + + +@field.command('add', hidden=hide_admin_cmds()) +@opt_identifier(help="Org identifier") +@opt_field_name() +def group_add_field(identifier, field_names): + ''' + Allow fields to show for the given org. + ''' + add_field(identifier, field_names) + + +@field.command('remove', hidden=hide_admin_cmds()) +@opt_identifier(help="Org identifier") +@opt_field_name() +def group_remove_field(identifier, field_names): + ''' + Deny fields from showing for the given org. + ''' + remove_field(identifier, field_names) + + +@field.command('list', hidden=hide_admin_cmds()) +@opt_identifier(help="Org identifier") +@table_format_option() +@opt_view_type() +def group_list_field(identifier: str, out_format: str, view_type: str): + ''' + List of fields allowed to show for the given org. + ''' + list_field(identifier, out_format, view_type) diff --git a/austrakka/components/org/field/funcs.py b/austrakka/components/org/field/funcs.py new file mode 100644 index 00000000..27af3477 --- /dev/null +++ b/austrakka/components/org/field/funcs.py @@ -0,0 +1,44 @@ +from typing import List + +from austrakka.utils.api import api_patch +from austrakka.utils.misc import logger_wraps +from austrakka.utils.output import get_viewtype_columns +from austrakka.utils.paths import ORG_V2_PATH +from austrakka.utils.helpers.output import call_get_and_print + + +@logger_wraps() +def add_field(identifier: str, field_names: List[str]): + return api_patch( + path=f'{ORG_V2_PATH}/{identifier}/Fields/Add', + data={ + "fields": field_names + } + ) + + +@logger_wraps() +def remove_field(identifier: str, field_names: List[str]): + return api_patch( + path=f'{ORG_V2_PATH}/{identifier}/Fields/Remove', + data={ + "fields": field_names + } + ) + + +@logger_wraps() +def list_field(identifier: str, out_format: str, view_type: str): + compact_fields = [ + "columnName", + "metaDataColumnTypeName", + "description", + "primitiveType", + "isActive", + ] + columns = get_viewtype_columns(view_type, compact_fields, []) + call_get_and_print( + f'{ORG_V2_PATH}/{identifier}/Fields', + out_format, + restricted_cols=columns, + ) diff --git a/austrakka/utils/helpers/output.py b/austrakka/utils/helpers/output.py index 933cc51d..31933ebc 100644 --- a/austrakka/utils/helpers/output.py +++ b/austrakka/utils/helpers/output.py @@ -1,4 +1,4 @@ -from typing import Dict +from typing import Dict, Union, List from loguru import logger from austrakka.utils.api import api_get @@ -10,7 +10,7 @@ def call_get_and_print( path: str, out_format: str, params: Dict = None, - restricted_cols: list[str] = None, + restricted_cols: Union[List[str], None] = None, datetime_cols: list[str] = None ): params = {} if params is None else params From d6a6e40650b6ad258976e15a2816e1d1ace269bc Mon Sep 17 00:00:00 2001 From: Samuel Carswell Date: Mon, 11 May 2026 08:47:13 +1000 Subject: [PATCH 2/3] AB#8166 linting --- austrakka/components/org/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/austrakka/components/org/__init__.py b/austrakka/components/org/__init__.py index 66da870c..18c684f1 100644 --- a/austrakka/components/org/__init__.py +++ b/austrakka/components/org/__init__.py @@ -1,3 +1,4 @@ +# pylint: disable=expression-not-assigned import click from austrakka.utils.output import table_format_option From 4047d9d0b2c9f30a5bf39f376a104c6796539aa2 Mon Sep 17 00:00:00 2001 From: Samuel Carswell Date: Wed, 27 May 2026 09:01:43 +1000 Subject: [PATCH 3/3] AB#8166 PR feedback --- austrakka/components/org/field/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/austrakka/components/org/field/__init__.py b/austrakka/components/org/field/__init__.py index a67dbf83..810f6e90 100644 --- a/austrakka/components/org/field/__init__.py +++ b/austrakka/components/org/field/__init__.py @@ -12,7 +12,7 @@ @click.group() @click.pass_context def field(ctx): - """Commands related to group fields access""" + """Commands related to org fields""" ctx.context = ctx.parent.context @@ -21,7 +21,7 @@ def field(ctx): @opt_field_name() def group_add_field(identifier, field_names): ''' - Allow fields to show for the given org. + Add fields to the data view for the given org ''' add_field(identifier, field_names) @@ -31,7 +31,7 @@ def group_add_field(identifier, field_names): @opt_field_name() def group_remove_field(identifier, field_names): ''' - Deny fields from showing for the given org. + Remove fields from the data view for the given org ''' remove_field(identifier, field_names) @@ -42,6 +42,6 @@ def group_remove_field(identifier, field_names): @opt_view_type() def group_list_field(identifier: str, out_format: str, view_type: str): ''' - List of fields allowed to show for the given org. + List of fields in data view for the given org ''' list_field(identifier, out_format, view_type)