[Git][noosfero/noosfero][master] 2 commits: api: accept parameters to update a task when accept/reject

Leandro Nunes gitlab at mg.gitlab.com
Fri Jul 22 18:29:29 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
dccf72d4 by Victor Costa at 2016-07-22T13:07:27-03:00
api: accept parameters to update a task when accept/reject

- - - - -
020591c2 by Leandro Nunes at 2016-07-22T21:27:33+00:00
Merge branch 'api_task_param' into 'master'

api: accept parameters to update a task when accept/reject



See merge request !984
- - - - -


2 changed files:

- app/api/v1/tasks.rb
- test/api/task_test.rb


Changes:

=====================================
app/api/v1/tasks.rb
=====================================
--- a/app/api/v1/tasks.rb
+++ b/app/api/v1/tasks.rb
@@ -31,8 +31,13 @@ module Api
           desc "#{action.capitalize} a task"
           put ":id/#{action}" do
             task = find_task(current_person, Task.to(current_person), params[:id])
-            task.send(action, current_person) if (task.status == Task::Status::ACTIVE)
-            present_partial task, :with => Entities::Task
+            begin
+              task.update(params[:task])
+              task.send(action, current_person) if (task.status == Task::Status::ACTIVE)
+              present_partial task, :with => Entities::Task
+            rescue Exception => ex
+              render_api_error!(ex.message, 500)
+            end
           end
         end
       end


=====================================
test/api/task_test.rb
=====================================
--- a/test/api/task_test.rb
+++ b/test/api/task_test.rb
@@ -204,6 +204,24 @@ class TasksTest < ActiveSupport::TestCase
       assert_nil task.reload.closed_by_id
       assert_equal Task::Status::ACTIVE, task.status
     end
+
+    should "person be able to #{action} a task with parameters" do
+      person1 = fast_create(Person)
+      task = create(Task, :requestor => person1, :target => person)
+      params[:task] = {reject_explanation: "reject explanation"}
+      put "/api/v1/tasks/#{task.id}/#{action}?#{params.to_query}"
+      assert_equal "Task::Status::#{task_actions_state[action]}".constantize, task.reload.status
+      assert_equal "reject explanation", task.reload.reject_explanation
+    end
+
+    should "not update a forbidden parameter when #{action} a task" do
+      person1 = fast_create(Person)
+      person2 = fast_create(Person)
+      task = create(Task, :requestor => person1, :target => person)
+      params[:task] = { requestor: {id: person2.id} }
+      put "/api/v1/tasks/#{task.id}/#{action}?#{params.to_query}"
+      assert_equal 500, last_response.status
+    end
   end
 
   #################################################



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/3e2a483accb48c7a76ff617ed933c46d236581be...020591c2c4710835d7c1cc2a485f13991a5e87f2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160722/2e6e11f4/attachment-0001.html>


More information about the Noosfero-dev mailing list