Browse Source

Add batch action to unassign tests on a project

Alan Lam 1 year ago
parent
commit
3b38ea74cc
3 changed files with 30 additions and 9 deletions
  1. 17 9
      controllers/project.php
  2. 12 0
      engine/test.php
  3. 1 0
      views/project.php

+ 17 - 9
controllers/project.php

@@ -29,14 +29,14 @@ $target_project_id = http::value("target_project_id");
 $test_ids_json = http::value("test_ids_json", "string");
 
 if($action) {
-	switch($action) {
-		case "move-tests":
 
-			$test_ids = json_decode($test_ids_json);
-			if(!is_array($test_ids)) {
-				$test_ids = [];
-			}
+	$test_ids = json_decode($test_ids_json);
+	if(!is_array($test_ids)) {
+		$test_ids = [];
+	}
 
+	switch($action) {
+		case "move-tests":
 			$target_project = Project::get($target_project_id);
 			if(!$target_project) {
 				throw new RuntimeException("Target project not found.");
@@ -81,14 +81,22 @@ if($action) {
 			Core::addAlert("success", __("Tests moved successfully."));
 			break;
 
+		case "unassign":
+			$tests = Test::query(["id" => $test_ids, "project_id" => $id, "status" => Test::STATUS_ASSIGNED]);
+			foreach($tests as $test) {
+				$test->unassign();
+			}
+
+
+			Core::addAlert("success", __("Tests unassigned successfully."));
+
+			break;
+
 		default:
 			throw new RuntimeException(__("Invalid action."));
 	}
 }
 
-
-
-
 $completed_percentage = $project->getCompletedPercentage();
 
 $locations = $customer->getLocations();

+ 12 - 0
engine/test.php

@@ -627,6 +627,18 @@ class Test extends Model {
 		return $this->commit();
 	}
 
+	/**
+	 * @return bool
+	 * @throws Exception
+	 */
+	public function unassign(): bool {
+		$this->tester_id = null;
+		$this->dts_assigned = null;
+		$this->dts_rejected = null;
+
+		return $this->commit();
+	}
+
 	/**
 	 * @return Test|null
 	 * @throws Exception

+ 1 - 0
views/project.php

@@ -279,6 +279,7 @@ if($auto_select_location_id) {
 								<select class="form-control" name="action" id="batch-action" required>
 									<option value=""><?=htmlspecialchars(__("Select Action"))?></option>
 									<option value="move-tests">Move Selected Tests To Another Project</option>
+									<option value="unassign">Unassign</option>
 								</select>
 							</div>