-
Notifications
You must be signed in to change notification settings - Fork 0
create CLI command #5
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: dev/8.1.x
Are you sure you want to change the base?
Changes from 10 commits
2edc98e
85350dd
66f6568
fb6454f
35d2c5a
a946b5a
f61def5
76e091e
2de33ee
cdb9308
f7defd7
aa3c056
c47dccd
d56d60f
dafb8c9
e9e464f
9da0153
dd9a168
2b8cc7c
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from django.contrib.auth import get_user_model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from django.core.management.base import BaseCommand, CommandError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from arches.app.utils.bulkupload import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_has_provisional_edits, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| approve_all_provisional_edits_for_user, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Command(BaseCommand): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Approves all provisional edits for a specified user. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Provide the user IDs with the --user_ids argument to approve all their provisional edits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def add_arguments(self, parser): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-u", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--user_ids", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nargs="+", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="One or more user IDs to approve edits for (separate by space)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+46
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. 🛠️ Refactor suggestion Make --user_ids required and add --dry-run / --yes flags (team-preferred UX) Per the team’s preference for bulk approval commands, add a dry-run preview and a confirmation bypass flag. Also mark --user_ids as required to remove manual validation. def add_arguments(self, parser):
parser.add_argument(
"-u",
"--user_ids",
type=int,
nargs="+",
+ required=True,
+ metavar="USER_ID",
help="One or more user IDs to approve edits for (separate by space)",
)
+ parser.add_argument(
+ "--dry-run",
+ action="store_true",
+ help="Preview which users have provisional edits; no changes are made.",
+ )
+ parser.add_argument(
+ "-y",
+ "--yes",
+ action="store_true",
+ help="Approve without interactive confirmation.",
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def handle(self, *args, **options): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_ids = options.get("user_ids") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not user_ids: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise CommandError("You must provide at least one user_id argument.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| User = get_user_model() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for user_id in user_ids: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
razekmh marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user = User.objects.get(pk=user_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except User.DoesNotExist: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.stdout.write( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.style.ERROR(f"User with ID {user_id} does not exist.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not user_has_provisional_edits(user_id): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.stdout.write( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.style.SUCCESS( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
razekmh marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"No provisional edits found for user ID {user_id}." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| approve_all_provisional_edits_for_user(user_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
razekmh marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| approve_all_provisional_edits_for_user(user_id) | |
| try: | |
| approve_all_provisional_edits_for_user(user_id) | |
| except Exception as e: | |
| self.stdout.write( | |
| self.style.ERROR( | |
| f"Failed to approve provisional edits for user ID {user_id}: {e}" | |
| ) | |
| ) | |
| continue |
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.
I agree with the idea but I do not think Arches has a standard way to show the errors.
Uh oh!
There was an error while loading. Please reload this page.