-
Notifications
You must be signed in to change notification settings - Fork 445
[tabcmd] refactor: extract CSVImport._decompose_site_role, inverse of _evaluate_site_role #1812
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
base: jac/csv-import-fixes-and-find-by-name
Are you sure you want to change the base?
Changes from all commits
157019f
7d4522d
ac84fd3
ee2fb8c
af21f2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -527,7 +527,7 @@ def create_from_file(self, filepath: str) -> tuple[list[UserItem], list[tuple[Us | |
| warnings.warn("This method is deprecated, use bulk_add instead", DeprecationWarning) | ||
| created = [] | ||
| failed = [] | ||
| if not filepath.find("csv"): | ||
| if "csv" not in filepath: | ||
| raise ValueError("Only csv files are accepted") | ||
|
Comment on lines
+530
to
531
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Legitimate bug, but confined to |
||
|
|
||
| with open(filepath) as csv_file: | ||
|
|
@@ -536,11 +536,9 @@ def create_from_file(self, filepath: str) -> tuple[list[UserItem], list[tuple[Us | |
| while line and line != "": | ||
| user: UserItem = UserItem.CSVImport.create_user_from_line(line) | ||
| try: | ||
| print(user) | ||
| result = self.add(user) | ||
| created.append(result) | ||
| except ServerResponseError as serverError: | ||
| print("failed") | ||
| failed.append((user, serverError)) | ||
| line = csv_file.readline() | ||
| return created, failed | ||
|
|
@@ -751,6 +749,7 @@ def create_users_csv(users: Iterable[UserItem]) -> bytes: | |
| - Admin Level | ||
| - Publish capability | ||
| - Auth setting | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
@@ -765,22 +764,7 @@ def create_users_csv(users: Iterable[UserItem]) -> bytes: | |
| with io.StringIO() as output: | ||
| writer = csv.writer(output, quoting=csv.QUOTE_MINIMAL) | ||
| for user in users: | ||
| site_role = user.site_role or "Unlicensed" | ||
| if site_role == "ServerAdministrator": | ||
| license = "Creator" | ||
| admin_level = "System" | ||
| elif site_role.startswith("SiteAdministrator"): | ||
| admin_level = "Site" | ||
| license = site_role.replace("SiteAdministrator", "") | ||
| else: | ||
| license = site_role | ||
| admin_level = "" | ||
|
|
||
| if any(x in site_role for x in ("Creator", "Admin", "Publish")): | ||
| publish = 1 | ||
| else: | ||
| publish = 0 | ||
|
|
||
| license, admin_level, publish = UserItem.CSVImport._decompose_site_role(user.site_role or "Unlicensed") | ||
| writer.writerow( | ||
| ( | ||
| f"{user.domain_name}\\{user.name}" if user.domain_name else user.name, | ||
|
|
@@ -790,6 +774,7 @@ def create_users_csv(users: Iterable[UserItem]) -> bytes: | |
| admin_level, | ||
| publish, | ||
| user.email, | ||
| user.auth_setting or "", | ||
| ) | ||
| ) | ||
| output.seek(0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in an earlier commit on this branch;
_decompose_site_roleis atclass CSVImportscope (line 553 as of HEAD) and callable asUserItem.CSVImport._decompose_site_role(...)— confirmed at runtime.