Skip to content

Commit

Permalink
Enabled multiple qualifications for a woker's single unit
Browse files Browse the repository at this point in the history
  • Loading branch information
meta-paul committed Oct 16, 2024
1 parent 7f02673 commit 319f9eb
Show file tree
Hide file tree
Showing 22 changed files with 588 additions and 147 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions docs/web/docs/guides/how_to_use/review_app/server_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,34 @@ Permanently block a worker.

---

### `POST /api/workers/{id}/qualifications/grant`

Grant multiple qualifications to a worker with units.

**URL parameters**:
- `id` - id of a worker

**Request**:
```json
{
"unit_ids": [<int>, ...], // Required
"qualification_grants": [ // Required
{
"qualification_id": <int>,
"value": <int>,
},
...
],
}
```

**Response**:
```json
{}
```

---

### `GET /api/workers/{id}/qualifications`

Get list of all granted qualifications for a worker.
Expand Down
56 changes: 39 additions & 17 deletions mephisto/abstractions/databases/local_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,25 +1562,47 @@ def _update_worker_review(
f"`worker_review` was not created for this `unit_id={unit_id}`"
)

latest_worker_review_id = results[-1]["id"]
latest_worker_review = results[-1]
latest_worker_review_id = latest_worker_review["id"]

c.execute(
"""
UPDATE worker_review
SET
updated_qualification_id = ?,
updated_qualification_value = ?,
revoked_qualification_id = ?
WHERE id = ?;
""",
(
nonesafe_int(qualification_id) if not revoke else None,
value,
nonesafe_int(qualification_id) if revoke else None,
nonesafe_int(latest_worker_review_id),
),
has_entry_with_qualification = (
latest_worker_review["updated_qualification_id"]
or latest_worker_review["revoked_qualification_id"]
)
conn.commit()

if not has_entry_with_qualification:
# Update just created entry when unit was approved
c.execute(
"""
UPDATE worker_review
SET
updated_qualification_id = ?,
updated_qualification_value = ?,
revoked_qualification_id = ?
WHERE id = ?;
""",
(
nonesafe_int(qualification_id) if not revoke else None,
value,
nonesafe_int(qualification_id) if revoke else None,
nonesafe_int(latest_worker_review_id),
),
)
conn.commit()
else:
# If we try to update entry for the same unit,
# but it was already assigned to another qualifications,
# create a new entry with the same data, but with another qualification and value
self._new_worker_review(
worker_id=worker_id,
status=latest_worker_review["status"],
task_id=latest_worker_review["task_id"],
unit_id=unit_id,
qualification_id=qualification_id,
value=value,
review_note=latest_worker_review["review_note"],
bonus=latest_worker_review["bonus"],
)

# File/blob manipulation methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
"""
List of changes:
1. Add `description` field into `qualifications` table
2. Make unit-related fields nullable in table `worker_review`
3. Rename `unit_review` table into `worker_review`
2. Rename `unit_review` table into `worker_review` and
make unit-related fields nullable in table `unit_review`
"""


MODIFY_QUALIFICATIONS = """
/* 1. Add `description` field into `qualifications` table */
ALTER TABLE qualifications ADD COLUMN description CHAR(500);
/* 2. Make unit-related fields nullable in table `worker_review` */
/* Disable FK constraints */
PRAGMA foreign_keys = off;
CREATE TABLE IF NOT EXISTS _worker_review (
/* 2. Rename `unit_review` table into `worker_review` and
make unit-related fields nullable in table `unit_review` */
CREATE TABLE IF NOT EXISTS worker_review (
id INTEGER PRIMARY KEY,
unit_id INTEGER,
worker_id INTEGER NOT NULL,
Expand All @@ -40,13 +41,10 @@
FOREIGN KEY (worker_id) REFERENCES workers (worker_id),
FOREIGN KEY (task_id) REFERENCES tasks (task_id)
);
INSERT INTO _worker_review SELECT * FROM unit_review;
INSERT INTO worker_review SELECT * FROM unit_review;
DROP INDEX IF EXISTS unit_review_by_unit_index;
DROP TABLE IF EXISTS unit_review;
/* 3. Rename `unit_review` table into `worker_review` */
ALTER TABLE _worker_review RENAME TO worker_review;
/* Enable FK constraints back */
PRAGMA foreign_keys = on;
"""
2 changes: 1 addition & 1 deletion mephisto/abstractions/providers/inhouse/inhouse_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def approve_work(
worker_id=self.unit.worker_id,
status=AgentState.STATUS_APPROVED,
review_note=review_note,
bonus=str(bonus),
bonus=bonus and str(bonus),
)

def soft_reject_work(self, review_note: Optional[str] = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion mephisto/abstractions/providers/prolific/prolific_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def approve_work(
worker_id=unit.worker_id,
status=AgentState.STATUS_APPROVED,
review_note=review_note,
bonus=str(bonus),
bonus=bonus and str(bonus),
)

def soft_reject_work(self, review_note: Optional[str] = None) -> None:
Expand Down
4 changes: 4 additions & 0 deletions mephisto/review_app/client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<meta name="theme-color" content="#000000" />
<meta name="description" content="Mephisto Review App" />
<title>Review</title>
<link
rel="stylesheet"
href="https://maxst.icons8.com/vue-static/landings/line-awesome/line-awesome/1.3.0/css/line-awesome.min.css"
/>
</head>
<body>
<noscript>You need to enable JavaScript to run this Review App.</noscript>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ReviewType } from "consts/review";
import * as React from "react";
import { Button, Form, Modal } from "react-bootstrap";
import ModalForm from "../ModalForm/ModalForm";
import ReviewModalForm from "../ReviewModalForm/ReviewModalForm";
import "./ReviewModal.css";

const ReviewTypeButtonClassMapping = {
Expand Down Expand Up @@ -43,7 +43,7 @@ function ReviewModal(props: ReviewModalProps) {
</Modal.Header>

<Modal.Body>
<ModalForm
<ReviewModalForm
data={props.data}
setData={props.setData}
setErrors={props.setErrors}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) Meta Platforms and its affiliates.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.review-form > * input,
.review-form > * select,
.review-form > * textarea {
border: 1px solid black;
}

.review-form .second-line,
.review-form .third-line,
.review-form .assign-quallification,
.review-form .explanation,
.review-form .selected-qualification,
.review-form .separator,
.review-form .new-qualification {
margin-top: 10px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
padding-left: 25px;
}

.review-form .explanation {
margin-top: 5px;
font-size: 12px;
font-style: italic;
opacity: 0.5;
}

.review-form .selected-qualification {
display: flex;
align-items: center;
}

.review-form .selected-qualification .inline-column .selected-value {
display: flex;
align-items: center;
}

.review-form .separator {
margin-top: 0;
}

.review-form .new-qualification {
margin-top: 0;
}

.review-form .row .inline-column {
display: flex;
flex-direction: row;
gap: 4px;
justify-content: space-between;
}

.review-form .row .inline-column .select-qualification,
.review-form .row .inline-column .remove-qualification {
display: flex;
padding: var(--bs-btn-padding-y) var(--bs-btn-padding-y);
font-size: 20px;
}

.new-qualification-name-button {
width: 100%;
}
Loading

0 comments on commit 319f9eb

Please sign in to comment.