Skip to content
Open
Changes from 10 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
54 changes: 54 additions & 0 deletions arches/management/commands/bulk_approve.py
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):
Comment thread
razekmh marked this conversation as resolved.
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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)",
)
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.",
)
🤖 Prompt for AI Agents
In arches/management/commands/bulk_approve.py around lines 17 to 25, update the
add_arguments method to make the --user_ids argument required by adding
required=True. Additionally, add two new optional flags: --dry-run as a boolean
flag to preview actions without making changes, and --yes as a boolean flag to
bypass confirmation prompts. This aligns with team UX preferences for bulk
approval commands.

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:
Comment thread
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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
if not user_has_provisional_edits(user_id):
self.stdout.write(
self.style.SUCCESS(
Comment thread
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)
Comment thread
razekmh marked this conversation as resolved.

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command should handle potential exceptions from approve_all_provisional_edits_for_user() to prevent the command from crashing and provide meaningful error messages to users.

Suggested change
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

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

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.

self.stdout.write(
self.style.SUCCESS(
f"All provisional edits for user ID {user_id} have been approved."
)
)