[Git][noosfero/noosfero][master] 2 commits: Add feature to close tasks in api
Victor Costa
gitlab at mg.gitlab.com
Thu Jul 21 10:26:56 BRT 2016
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
ada7cf66 by Victor Navarro at 2016-07-21T09:09:40-03:00
Add feature to close tasks in api
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>
Signed-off-by: Victor Navarro <victor.matias.navarro at gmail.com>
Signed-off-by: Vitor Barbosa <vitornga15 at gmail.com>
- - - - -
b047dfa3 by Victor Costa at 2016-07-21T13:26:30+00:00
Merge branch 'api_task' into 'master'
Add endpoint to close task with status
Signed-off-by: Victor Navarro <victor.matias.navarro at gmail.com>
Signed-off-by: Vitor Barbosa <vitornga15 at gmail.com>
See merge request !939
- - - - -
3 changed files:
- app/api/helpers.rb
- app/api/v1/tasks.rb
- test/api/task_test.rb
Changes:
=====================================
app/api/helpers.rb
=====================================
--- a/app/api/helpers.rb
+++ b/app/api/helpers.rb
@@ -144,7 +144,8 @@ module Api
end
def find_task(asset, id)
- task = asset.tasks.find(id)
+ task = asset.tasks.find_by(id: id)
+ not_found! if task.blank?
current_person.has_permission?(task.permission, asset) ? task : forbidden!
end
=====================================
app/api/v1/tasks.rb
=====================================
--- a/app/api/v1/tasks.rb
+++ b/app/api/v1/tasks.rb
@@ -23,6 +23,16 @@ module Api
task = find_task(environment, params[:id])
present_partial task, :with => Entities::Task
end
+
+ %w[finish cancel].each do |action|
+ desc "#{action.capitalize} a task"
+ put ":id/#{action}" do
+ authenticate!
+ task = find_task(current_person, params[:id])
+ task.send(action, current_person) if (task.status == Task::Status::ACTIVE)
+ present_partial task, :with => Entities::Task
+ end
+ end
end
kinds = %w[community person enterprise]
=====================================
test/api/task_test.rb
=====================================
--- a/test/api/task_test.rb
+++ b/test/api/task_test.rb
@@ -183,6 +183,29 @@ class TasksTest < ActiveSupport::TestCase
assert_equal person, Task.last.target
end
+ task_actions=%w[finish cancel]
+ task_actions_state={"finish"=>"FINISHED","cancel"=>"CANCELLED"}
+ task_actions.each do |action|
+ should "person be able to #{action} his own task" do
+ login_api
+ person1 = fast_create(Person)
+ task = create(Task, :requestor => person1, :target => person)
+ put "/api/v1/tasks/#{task.id}/#{action}?#{params.to_query}"
+ assert_equal person.reload.id, task.reload.closed_by_id
+ assert_equal "Task::Status::#{task_actions_state[action]}".constantize, task.reload.status
+ end
+
+ should "person not be able to #{action} other person's task" do
+ login_api
+ user = fast_create(User)
+ person1 = fast_create(Person, :user_id => user)
+ task = create(Task, :requestor => person, :target => person1)
+ put "/api/v1/tasks/#{task.id}/#{action}?#{params.to_query}"
+ assert_nil task.reload.closed_by_id
+ assert_equal Task::Status::ACTIVE, task.status
+ end
+ end
+
#############################
# Enterprise Tasks #
#############################
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/f2b2ff07679df38d6f5db012e4fcdc12a9e3670a...b047dfa3f24f26ba2cf66e706e600308a58cc5d5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160721/8af788e6/attachment-0001.html>
More information about the Noosfero-dev
mailing list