Skip to content

Commit 375781a

Browse files
authored
Add an option to disable the review process (#532)
2 parents f4f635f + 4b2bcda commit 375781a

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

docs/developer/users.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ There is no special privilege for user A, and this also means that e.g., user B
3131

3232
!!! info
3333
The upload and review process is described from a user perspective in ["Uploading"](../using/upload.md).
34+
The review process may be disabled by setting the `--disable-reviews` flag when starting the server.
3435

3536
An asset uploaded by a user is by default in `draft` state.
3637
The user may request the asset to be `published` by submitting it for review through the REST API.

src/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from database.model.platform.platform_names import PlatformName
2626
from database.session import EngineSingleton, DbSession
2727
from database.setup import create_database, database_exists
28+
from triggers import disable_review_process, enable_review_process
2829
from error_handling import http_exception_handler
2930
from routers import (
3031
resource_routers,
@@ -61,6 +62,12 @@ def _parse_args() -> argparse.Namespace:
6162
action=argparse.BooleanOptionalAction,
6263
help="Use `--reload` for FastAPI.",
6364
)
65+
parser.add_argument(
66+
"--disable-reviews",
67+
action="store_true",
68+
help="Use --disable-reviews to disable the review process for new assets."
69+
"This does not affect the state of assets already created or under review.",
70+
)
6471
return parser.parse_args()
6572

6673

@@ -198,6 +205,12 @@ def build_database(args):
198205
triggers = create_delete_triggers(AIoDConcept)
199206
for trigger in triggers:
200207
session.execute(trigger)
208+
209+
if args.disable_reviews:
210+
disable_review_process(session)
211+
else:
212+
enable_review_process(session)
213+
201214
existing_platforms = session.scalars(select(Platform)).all()
202215
missing_platforms = set(PlatformName) - {p.name for p in existing_platforms}
203216
if any(missing_platforms):

src/triggers.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from sqlalchemy import DDL
2+
from sqlmodel import Session
3+
4+
BYPASS_REVIEW_TRIGGER_NAME: str = "PUBLISH_ON_CREATE"
5+
6+
7+
def disable_review_process(session: Session) -> None:
8+
"""Sets new entries to automatically be published, circumventing the review process."""
9+
session.execute(
10+
DDL(f"""
11+
CREATE TRIGGER IF NOT EXISTS {BYPASS_REVIEW_TRIGGER_NAME}
12+
BEFORE INSERT ON aiod_entry
13+
FOR EACH ROW
14+
BEGIN
15+
SET NEW.status = 'PUBLISHED';
16+
END;
17+
""")
18+
)
19+
20+
21+
def enable_review_process(session: Session) -> None:
22+
"""Drops the trigger created by `disable_review_process`"""
23+
session.execute(DDL(f"DROP TRIGGER IF EXISTS {BYPASS_REVIEW_TRIGGER_NAME};"))

0 commit comments

Comments
 (0)