Skip to content

Commit

Permalink
allow editing of taskruns
Browse files Browse the repository at this point in the history
  • Loading branch information
dchhabda committed Jan 23, 2023
1 parent 6ec316e commit 30db600
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pybossa/api/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def _forbidden_attributes(self, data):
raise BadRequest("Reserved keys in payload")

def _update_attribute(self, new, old):
for key, value in old.info.items():
if not new.info.get(key):
new.info[key] = value

gold_task = bool(new.gold_answers)
n_taskruns = len(new.task_runs)
if new.state == 'completed':
Expand Down
5 changes: 5 additions & 0 deletions pybossa/api/task_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def _update_object(self, taskrun):
self._add_user_info(taskrun)
self._add_timestamps(taskrun, task, guard)

def _update_attribute(self, new, old):
for key, value in old.info.items():
if not new.info.get(key):
new.info[key] = value

def _forbidden_attributes(self, data):
for key in data.keys():
if key in self.reserved_keys:
Expand Down
6 changes: 5 additions & 1 deletion pybossa/auth/taskrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def _read(self, user, taskrun=None):
return user.is_authenticated

def _update(self, user, taskrun):
return self._delete(user, taskrun)
if taskrun.user_id is None:
return user.admin
project = self.project_repo.get(taskrun.project_id)
allow_taskrun_edit = project.info.get("allow_taskrun_edit") or False
return user.admin or (allow_taskrun_edit and taskrun.user_id == user.id)

def _delete(self, user, taskrun):
if user.is_anonymous:
Expand Down

0 comments on commit 30db600

Please sign in to comment.