Skip to content

Commit

Permalink
Merge branch 'dev' into feature/file-count-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
s3inlc authored Feb 24, 2024
2 parents 5c60dd5 + be80815 commit 2c8e947
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
16 changes: 16 additions & 0 deletions ci/apiv2/hashtopolis.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,25 @@ def import_cracked_hashes(self, hashlist, source_data, separator):
response = self._helper_request("importCrackedHashes", payload)
return response['data']


def recount_file_lines(self, file):
payload = {
'fileId': file.id,
}
response = self._helper_request("recountFileLines", payload)
return File(**response['data'])

def unassign_agent(self, agent):
payload = {
'agentId': agent.id,
}
response = self._helper_request("unassignAgent", payload)
return response['data']

def assign_agent(self, agent, task):
payload = {
'agentId': agent.id,
'taskId': task.id,
}
response = self._helper_request("assignAgent", payload)
return response['data']
21 changes: 20 additions & 1 deletion ci/apiv2/test_agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from hashtopolis import Agent
from test_task import TaskTest
from hashtopolis import Agent, Helper
from hashtopolis import HashtopolisError

from utils import BaseTest
Expand Down Expand Up @@ -28,3 +29,21 @@ def test_expandables(self):
model_obj = self.create_test_object()
expandables = ['accessGroups', 'agentstats']
self._test_expandables(model_obj, expandables)

def test_assign_unassign_agent(self):
agent_obj = self.create_test_object()

task_test = TaskTest()
task_obj = task_test.create_test_object(delete=True)

helper = Helper()

result = helper.assign_agent(agent=agent_obj, task=task_obj)

self.assertEqual(result['assign'], 'success')

result = helper.unassign_agent(agent=agent_obj)

self.assertEqual(result['unassign'], 'success')

task_test.tearDown()
2 changes: 2 additions & 0 deletions src/api/v2/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public function process(Request $request, RequestHandler $handler): Response {
require __DIR__ . "/../../inc/apiv2/model/vouchers.routes.php";

require __DIR__ . "/../../inc/apiv2/helper/abortChunk.routes.php";
require __DIR__ . "/../../inc/apiv2/helper/assignAgent.routes.php";
require __DIR__ . "/../../inc/apiv2/helper/createSupertask.routes.php";
require __DIR__ . "/../../inc/apiv2/helper/createSuperHashlist.routes.php";
require __DIR__ . "/../../inc/apiv2/helper/exportCrackedHashes.routes.php";
Expand All @@ -278,5 +279,6 @@ public function process(Request $request, RequestHandler $handler): Response {
require __DIR__ . "/../../inc/apiv2/helper/recountFileLines.routes.php";
require __DIR__ . "/../../inc/apiv2/helper/resetChunk.routes.php";
require __DIR__ . "/../../inc/apiv2/helper/setUserPassword.routes.php";
require __DIR__ . "/../../inc/apiv2/helper/unassignAgent.routes.php";

$app->run();
36 changes: 36 additions & 0 deletions src/inc/apiv2/helper/assignAgent.routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use DBA\Agent;
use DBA\Task;

require_once(dirname(__FILE__) . "/../common/AbstractHelperAPI.class.php");

class AssignAgentHelperAPI extends AbstractHelperAPI {
public static function getBaseUri(): string {
return "/api/v2/helper/assignAgent";
}

public static function getAvailableMethods(): array {
return ['POST'];
}

public function getRequiredPermissions(string $method): array {
return [Agent::PERM_UPDATE, Task::PERM_UPDATE];
}

public function getFormFields(): array {
return [
Agent::AGENT_ID => ["type" => "int"],
Task::TASK_ID => ["type" => "int"],
];
}

public function actionPost($data): array|null {
AgentUtils::assign($data[Agent::AGENT_ID], $data[Task::TASK_ID], $this->getCurrentUser());

# TODO: Check how to handle custom return messages that are not object, probably we want that to be in some kind of standardized form.
return ["assign" => "success"];
}
}

AssignAgentHelperAPI::register($app);
35 changes: 35 additions & 0 deletions src/inc/apiv2/helper/unassignAgent.routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use DBA\Agent;
use DBA\Task;

require_once(dirname(__FILE__) . "/../common/AbstractHelperAPI.class.php");

class UnassignAgentHelperAPI extends AbstractHelperAPI {
public static function getBaseUri(): string {
return "/api/v2/helper/unassignAgent";
}

public static function getAvailableMethods(): array {
return ['POST'];
}

public function getRequiredPermissions(string $method): array {
return [Agent::PERM_UPDATE, Task::PERM_UPDATE];
}

public function getFormFields(): array {
return [
Agent::AGENT_ID => ["type" => "int"],
];
}

public function actionPost($data): array|null {
AgentUtils::assign($data[Agent::AGENT_ID], 0, $this->getCurrentUser());

# TODO: Check how to handle custom return messages that are not object, probably we want that to be in some kind of standardized form.
return ["unassign" => "success"];
}
}

UnassignAgentHelperAPI::register($app);

0 comments on commit 2c8e947

Please sign in to comment.