Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yda 5612 fix multiple role columns with suffix in group import #11

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## Unreleased

- yimportgroups: bugfix for situation where legacy format CSV files with role suffixes where not processed
correctly in case of multiple users with the same role (YDA-5612)
- yimportgroups: retain support for legacy format CSV files with role suffixes in Yoda 1.9 and higher.

## 2024-02-19 v1.0.0

First 1.x release
Expand Down
62 changes: 58 additions & 4 deletions unit-tests/test_importgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ def test_fully_filled_csv_line_1_9(self):
self.assertTupleEqual(expected, result)
self.assertIsNone(error_msg)

def test_fully_filled_csv_line_1_9_multi_role(self):
args = {"offline_check": True}
d = {
"category": ["test-automation"],
"subcategory": ["initial"],
"groupname": ["groupteama"],
"manager": ["m.manager@yoda.dev", "n.manager@yoda.dev"],
"member": ["p.member@yoda.dev", "q.member@yoda.dev"],
"viewer": ["m.viewer@yoda.dev", "n.viewer@yoda.dev"],
"expiration_date": ["2030-01-01"],
"schema_id": ["default-3"],
}
expected = (
"test-automation",
"initial",
"research-groupteama",
["m.manager@yoda.dev", "n.manager@yoda.dev"],
["p.member@yoda.dev", "q.member@yoda.dev"],
["m.viewer@yoda.dev", "n.viewer@yoda.dev"],
"default-3",
"2030-01-01",
)
result, error_msg = _process_csv_line(d, args, "1.9")
self.assertTupleEqual(expected, result)
self.assertIsNone(error_msg)


def test_fully_filled_csv_line_1_9_with_suffixes(self):
# Confirm support the old csv header format still (with ":nicknameofuser")
args = {"offline_check": True}
Expand Down Expand Up @@ -75,6 +102,37 @@ def test_fully_filled_csv_line_1_9_with_suffixes(self):
self.assertTupleEqual(expected, result)
self.assertIsNone(error_msg)

def test_fully_filled_csv_line_1_9_with_suffixes_multi_role(self):
# Confirm support the old csv header format still (with ":nicknameofuser")
args = {"offline_check": True}
d = {
"category": ["test-automation"],
"subcategory": ["initial"],
"groupname": ["groupteama"],
"manager:alice": ["m.manager@yoda.dev"],
"manager:andy": ["n.manager@yoda.dev"],
"member:bob": ["p.member@yoda.dev"],
"member:bella": ["q.member@yoda.dev"],
"viewer:eve": ["m.viewer@yoda.dev"],
"viewer:emma": ["n.viewer@yoda.dev"],
"expiration_date": ["2030-01-01"],
"schema_id": ["default-3"],
}
expected = (
"test-automation",
"initial",
"research-groupteama",
["m.manager@yoda.dev", "n.manager@yoda.dev"],
["p.member@yoda.dev", "q.member@yoda.dev"],
["m.viewer@yoda.dev", "n.viewer@yoda.dev"],
"default-3",
"2030-01-01",
)
result, error_msg = _process_csv_line(d, args, "1.9")
self.assertTupleEqual(expected, result)
self.assertIsNone(error_msg)


def test_missing_fields_1_9(self):
args = {"offline_check": True}
# No schema id or expiration date
Expand Down Expand Up @@ -168,10 +226,6 @@ def test_parse_csv_with_header_suffixes(self, mock_stderr):
args = {"offline_check": True}
parse_csv_file("files/header-with-suffixes.csv", args, "1.8")

# This header format not supported in 1.9 and higher
with self.assertRaises(SystemExit):
parse_csv_file("files/header-with-suffixes.csv", args, "1.9")

@patch('sys.stderr', new_callable=StringIO)
def test_parse_invalid_csv_file(self, mock_stderr):
# csv that has an unlabeled header
Expand Down
12 changes: 4 additions & 8 deletions yclienttools/importgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ def parse_csv_file(input_file, args, yoda_version):
if label.startswith('{}:'.format(opt_label)):
found_match = True

if found_match and yoda_version not in ('1.7', '1.8'):
_exit_with_error(
'This script does not support headers with suffixes in '
'Yoda version 1.9 and higher. Field with suffix: "{}"'.format(label))
elif not found_match:
if not found_match:
_exit_with_error(
'CSV header contains unknown field "{}"'.format(label))

Expand Down Expand Up @@ -159,11 +155,11 @@ def _process_csv_line(line, args, yoda_version):
return None, '"{}" is not a valid username.'.format(item_list[i])

if column_name.lower() == 'manager' or column_name.lower().startswith('manager:'):
managers = item_list
managers.extend(item_list)
elif column_name.lower() == 'member' or column_name.lower().startswith('member:'):
members = item_list
members.extend(item_list)
elif column_name.lower() == 'viewer' or column_name.lower().startswith('viewer:'):
viewers = item_list
viewers.extend(item_list)

# perform additional data validations
if len(managers) == 0:
Expand Down
Loading