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

Adds ability to clear onboarding for a worker #886

Merged
merged 4 commits into from
Aug 10, 2022
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def init_onboarding_config(
db, self.onboarding_failed_name
)

@classmethod
def clear_onboarding(self, worker: "Worker", qualification_name: str):
worker.revoke_qualification(qualification_name)
if qualification_name is not None:
worker.revoke_crowd_qualification(self.get_failed_qual(qualification_name))

def get_onboarding_data(self, worker_id: str) -> Dict[str, Any]:
"""
If the onboarding task on the frontend requires any specialized data, the blueprint
Expand Down
3 changes: 3 additions & 0 deletions mephisto/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import mephisto.scripts.local_db.remove_accepted_tip as remove_accepted_tip_local_db
import mephisto.scripts.local_db.review_feedback_for_task as review_feedback_local_db
import mephisto.scripts.local_db.load_data_to_mephisto_db as load_data_local_db
import mephisto.scripts.local_db.clear_worker_onboarding as clear_worker_onboarding_local_db
import mephisto.scripts.heroku.initialize_heroku as initialize_heroku
import mephisto.scripts.metrics.view_metrics as view_metrics
import mephisto.scripts.metrics.shutdown_metrics as shutdown_metrics
Expand Down Expand Up @@ -289,6 +290,7 @@ def print_non_markdown_list(items: List[str]):
"remove_tip",
"review_feedback",
"load_data",
"clear_worker_onboarding",
]
HEROKU_VALID_SCRIPTS_NAMES = ["initialize"]
METRICS_VALID_SCRIPTS_NAMES = ["view", "shutdown"]
Expand All @@ -307,6 +309,7 @@ def print_non_markdown_list(items: List[str]):
LOCAL_DB_VALID_SCRIPTS_NAMES[1]: remove_accepted_tip_local_db.main,
LOCAL_DB_VALID_SCRIPTS_NAMES[2]: review_feedback_local_db.main,
LOCAL_DB_VALID_SCRIPTS_NAMES[3]: load_data_local_db.main,
LOCAL_DB_VALID_SCRIPTS_NAMES[4]: clear_worker_onboarding_local_db.main,
},
},
"heroku": {
Expand Down
68 changes: 68 additions & 0 deletions mephisto/scripts/local_db/clear_worker_onboarding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from mephisto.abstractions.blueprints.mixins.onboarding_required import (
OnboardingRequired,
)
from mephisto.abstractions.databases.local_database import LocalMephistoDB
from mephisto.data_model.worker import Worker
from rich import print
from rich.prompt import Prompt

"""
In this script we are asking for a worker_id, but we are actually using it as a worker_name.
In the database a worker_id is a number like 1 or 2, while a worker_name is like "x_sandbox".
However, when looking at an url like: http://localhost:3000/?worker_id=x&assignment_id=45
the worker_id is "x".

As the user is more likely to think of the worker_id as "x" instead of 1, we
are calling the worker_name, the worker_id.

In the url example above, this script would first check if there are any workers with the name x.
If there is one, then that worker's onboarding qualification will be revoked. If there are
more than one worker with that name the script aborts.

If there are no workers with that name, it then tries the name "x_sandbox". The _sandbox
affix is commonly attached to worker names in the backend, so that is why "x_sandbox"
is also tried.
"""


def main():
db = LocalMephistoDB()
worker_id = str(Prompt.ask("What is the worker's id:", default="x"))

desired_worker = db.find_workers(worker_name=worker_id)

if len(desired_worker) == 0:
worker_id_with_sandbox = worker_id + "_sandbox"
sandbox_workers = db.find_workers(worker_name=worker_id_with_sandbox)

if len(sandbox_workers) == 0:
print("\n[red]There are no workers with that name[/red]\n")
quit()

elif len(sandbox_workers) > 1:
print("\n[red] There is more that one worker with that name[/red]\n")
quit()

clear_onboarding(sandbox_workers[0])
quit()

elif len(desired_worker > 1):
print("\n[red]There is more than one worker with that name[/red]\n")
quit()

clear_onboarding(desired_worker[0])


def clear_onboarding(desired_worker: Worker):
qualification_name = Prompt.ask(
"What is the qualification name:", default="test-react-static-qualification"
)

OnboardingRequired.clear_onboarding(
worker=desired_worker, qualification_name=qualification_name
)
print("\n[green]Cleared that onboarding qualification[/green]\n")


if __name__ == "__main__":
main()