Skip to content

Commit b00ef43

Browse files
committed
Introduce secure vs. managed tasks
1 parent 3bdf6c1 commit b00ef43

File tree

2 files changed

+274
-137
lines changed

2 files changed

+274
-137
lines changed

contracts/extensions/Tasks.sol

+55-17
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ contract Tasks is DSMath {
3333
/// @param taskId The newly added task id
3434
event TaskAdded(uint256 taskId);
3535

36+
/// @notice Event logged when a task's security status changes (secure vs. managed)
37+
/// @param taskId Id of the task
38+
/// @param secure Boolean of security status (true: secure, false: managed)
39+
event TaskSecuritySet(uint256 indexed taskId, bool secure);
40+
3641
/// @notice Event logged when a task's specification hash changes
3742
/// @param taskId Id of the task
3843
/// @param specificationHash New specification hash of the task
@@ -69,6 +74,7 @@ contract Tasks is DSMath {
6974
uint256 dueDate;
7075
uint256 completionTimestamp;
7176
uint256 changeNonce;
77+
bool secure;
7278
}
7379

7480
struct Role {
@@ -103,6 +109,7 @@ contract Tasks is DSMath {
103109
roleAssignmentSigs[bytes4(keccak256("setTaskWorkerRole(uint256,address)"))] = true;
104110

105111
// Initialise the task update reviewers
112+
reviewers[bytes4(keccak256("setTaskSecurity(uint256,bool)"))] = [TaskRole.Manager, TaskRole.Worker];
106113
reviewers[bytes4(keccak256("setTaskBrief(uint256,bytes32)"))] = [TaskRole.Manager, TaskRole.Worker];
107114
reviewers[bytes4(keccak256("setTaskDueDate(uint256,uint256)"))] = [TaskRole.Manager, TaskRole.Worker];
108115
reviewers[bytes4(keccak256("setTaskSkill(uint256,uint256)"))] = [TaskRole.Manager, TaskRole.Worker];
@@ -115,8 +122,8 @@ contract Tasks is DSMath {
115122
reviewers[bytes4(keccak256("cancelTask(uint256)"))] = [TaskRole.Manager, TaskRole.Worker];
116123
}
117124

118-
modifier self() {
119-
require(address(this) == msg.sender, "task-not-self");
125+
modifier self(uint256 _id) {
126+
require(managerCanCall(_id) || address(this) == msg.sender, "task-not-self");
120127
_;
121128
}
122129

@@ -274,7 +281,8 @@ contract Tasks is DSMath {
274281
bytes32 _specificationHash,
275282
uint256 _domainId,
276283
uint256 _skillId,
277-
uint256 _dueDate
284+
uint256 _dueDate,
285+
bool _secure
278286
)
279287
public
280288
isAdmin(msg.sender, _callerPermissionDomainId, _callerChildSkillIndex, _domainId)
@@ -285,9 +293,13 @@ contract Tasks is DSMath {
285293
tasks[taskCount].expenditureId = expenditureId;
286294
tasks[taskCount].specificationHash = _specificationHash;
287295
tasks[taskCount].dueDate = (_dueDate > 0) ? _dueDate : now + 90 days; // Note: can set dueDate in past?
296+
tasks[taskCount].secure = _secure;
288297

289298
setTaskRoleUser(taskCount, TaskRole.Manager, msg.sender);
290-
setTaskRoleUser(taskCount, TaskRole.Evaluator, msg.sender);
299+
300+
if (_secure) {
301+
setTaskRoleUser(taskCount, TaskRole.Evaluator, msg.sender);
302+
}
291303

292304
if (_skillId > 0) {
293305
this.setTaskSkill(taskCount, _skillId);
@@ -355,46 +367,56 @@ contract Tasks is DSMath {
355367
return ratingSecrets[_id].secret[_role];
356368
}
357369

370+
function setTaskSecurity(uint256 _id, bool _secure) public self(_id) {
371+
tasks[_id].secure = _secure;
372+
373+
if (!_secure) {
374+
removeTaskEvaluatorRole(_id);
375+
}
376+
377+
emit TaskSecuritySet(_id, _secure);
378+
}
379+
358380
// Note: the domain permissions arguments are placed at the end for consistency with the other role change functions
359381
function setTaskManagerRole(uint256 _id, address payable _user, uint256 _permissionDomainId, uint256 _childSkillIndex)
360382
public
361-
self
383+
self(_id)
362384
isAdmin(_user, _permissionDomainId, _childSkillIndex, colony.getExpenditure(tasks[_id].expenditureId).domainId)
363385
{
364386
setTaskRoleUser(_id, TaskRole.Manager, _user);
365387
}
366388

367-
function setTaskEvaluatorRole(uint256 _id, address payable _user) public self {
389+
function setTaskEvaluatorRole(uint256 _id, address payable _user) public self(_id) {
368390
// Can only assign role if no one is currently assigned to it
369391
require(getTaskRoleUser(_id, TaskRole.Evaluator) == address(0x0), "task-evaluator-role-assigned");
370392
setTaskRoleUser(_id, TaskRole.Evaluator, _user);
371393
}
372394

373-
function setTaskWorkerRole(uint256 _id, address payable _user) public self {
395+
function setTaskWorkerRole(uint256 _id, address payable _user) public self(_id) {
374396
// Can only assign role if no one is currently assigned to it
375397
require(getTaskRoleUser(_id, TaskRole.Worker) == address(0x0), "task-worker-role-assigned");
376398
uint256[] memory skills = colony.getExpenditureSlot(tasks[_id].expenditureId, uint256(TaskRole.Worker)).skills;
377399
require(skills.length > 0 && skills[0] > 0, "task-skill-not-set"); // ignore-swc-110
378400
setTaskRoleUser(_id, TaskRole.Worker, _user);
379401
}
380402

381-
function removeTaskEvaluatorRole(uint256 _id) public self {
403+
function removeTaskEvaluatorRole(uint256 _id) public self(_id) {
382404
setTaskRoleUser(_id, TaskRole.Evaluator, address(0x0));
383405
}
384406

385-
function removeTaskWorkerRole(uint256 _id) public self {
407+
function removeTaskWorkerRole(uint256 _id) public self(_id) {
386408
setTaskRoleUser(_id, TaskRole.Worker, address(0x0));
387409
}
388410

389-
function setTaskManagerPayout(uint256 _id, address _token, uint256 _amount) public self {
411+
function setTaskManagerPayout(uint256 _id, address _token, uint256 _amount) public self(_id) {
390412
colony.setExpenditurePayout(_id, uint256(TaskRole.Manager), _token, _amount);
391413
}
392414

393-
function setTaskEvaluatorPayout(uint256 _id, address _token, uint256 _amount) public self {
415+
function setTaskEvaluatorPayout(uint256 _id, address _token, uint256 _amount) public self(_id) {
394416
colony.setExpenditurePayout(_id, uint256(TaskRole.Evaluator), _token, _amount);
395417
}
396418

397-
function setTaskWorkerPayout(uint256 _id, address _token, uint256 _amount) public self {
419+
function setTaskWorkerPayout(uint256 _id, address _token, uint256 _amount) public self(_id) {
398420
colony.setExpenditurePayout(_id, uint256(TaskRole.Worker), _token, _amount);
399421
}
400422

@@ -421,13 +443,13 @@ contract Tasks is DSMath {
421443
this.setTaskWorkerPayout(_id, _token, _workerAmount);
422444
}
423445

424-
function setTaskSkill(uint256 _id, uint256 _skillId) public self {
446+
function setTaskSkill(uint256 _id, uint256 _skillId) public self(_id) {
425447
colony.setExpenditureSkill(tasks[_id].expenditureId, uint256(TaskRole.Worker), _skillId);
426448
}
427449

428450
function setTaskBrief(uint256 _id, bytes32 _specificationHash)
429451
public
430-
self
452+
self(_id)
431453
taskExists(_id)
432454
taskNotComplete(_id)
433455
{
@@ -438,7 +460,7 @@ contract Tasks is DSMath {
438460

439461
function setTaskDueDate(uint256 _id, uint256 _dueDate)
440462
public
441-
self
463+
self(_id)
442464
taskExists(_id)
443465
taskNotComplete(_id)
444466
{
@@ -479,19 +501,21 @@ contract Tasks is DSMath {
479501

480502
function cancelTask(uint256 _id)
481503
public
482-
self
504+
self(_id)
483505
taskExists(_id)
484506
taskNotComplete(_id)
485507
{
486508
colony.cancelExpenditure(tasks[_id].expenditureId);
487509
}
488510

489511
// Permissions pertain to the Arbitration role here
490-
function finalizeTask(uint256 _permissionDomainId, uint256 _childSkillIndex, uint256 _id)
512+
function finalizeSecureTask(uint256 _permissionDomainId, uint256 _childSkillIndex, uint256 _id)
491513
public
492514
taskExists(_id)
493515
taskComplete(_id)
494516
{
517+
require(tasks[_id].secure, "task-not-secure");
518+
495519
colony.finalizeExpenditure(tasks[_id].expenditureId);
496520

497521
assignWorkRatings(_id);
@@ -510,6 +534,16 @@ contract Tasks is DSMath {
510534
}
511535
}
512536

537+
function finalizeManagedTask(uint256 _id)
538+
public
539+
taskExists(_id)
540+
confirmTaskRoleIdentity(_id, msg.sender, TaskRole.Manager)
541+
{
542+
require(!tasks[_id].secure, "task-not-managed");
543+
544+
colony.finalizeExpenditure(tasks[_id].expenditureId);
545+
}
546+
513547
function getTaskCount() public view returns (uint256) {
514548
return taskCount;
515549
}
@@ -687,4 +721,8 @@ contract Tasks is DSMath {
687721
function isTaskComplete(uint256 _id) internal view returns (bool) {
688722
return tasks[_id].completionTimestamp > 0;
689723
}
724+
725+
function managerCanCall(uint256 _id) internal view returns (bool) {
726+
return !tasks[_id].secure && getTaskRoleUser(_id, TaskRole.Manager) == msg.sender;
727+
}
690728
}

0 commit comments

Comments
 (0)