Commit 94d1fa5087801dda87170797277db24f082706ff
1 parent
ef14bd51
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
adding endpoints for juventude app
Showing
4 changed files
with
53 additions
and
3 deletions
Show diff stats
lib/noosfero/api/entities.rb
| ... | ... | @@ -48,6 +48,7 @@ module Noosfero |
| 48 | 48 | |
| 49 | 49 | class Region < Category |
| 50 | 50 | root 'regions', 'region' |
| 51 | + expose :parent_id | |
| 51 | 52 | end |
| 52 | 53 | |
| 53 | 54 | class Profile < Entity |
| ... | ... | @@ -55,6 +56,8 @@ module Noosfero |
| 55 | 56 | expose :created_at, :format_with => :timestamp |
| 56 | 57 | expose :image, :using => Image |
| 57 | 58 | expose :region, :using => Region |
| 59 | + expose :city, :using => Region | |
| 60 | + expose :state, :using => Region | |
| 58 | 61 | end |
| 59 | 62 | |
| 60 | 63 | class UserBasic < Entity |
| ... | ... | @@ -65,6 +68,7 @@ module Noosfero |
| 65 | 68 | class Person < Profile |
| 66 | 69 | root 'people', 'person' |
| 67 | 70 | expose :user, :using => UserBasic |
| 71 | + expose :orientacao_sexual, :identidade_genero, :transgenero, :etnia | |
| 68 | 72 | end |
| 69 | 73 | |
| 70 | 74 | class Enterprise < Profile |
| ... | ... | @@ -120,7 +124,7 @@ module Noosfero |
| 120 | 124 | expose :id |
| 121 | 125 | expose :login |
| 122 | 126 | expose :email |
| 123 | - expose :person, :using => Profile | |
| 127 | + expose :person, :using => Person | |
| 124 | 128 | expose :activated?, as: :activated |
| 125 | 129 | expose :permissions do |user, options| |
| 126 | 130 | output = {} | ... | ... |
lib/noosfero/api/helpers.rb
| ... | ... | @@ -5,7 +5,7 @@ require 'grape' |
| 5 | 5 | module API |
| 6 | 6 | module APIHelpers |
| 7 | 7 | PRIVATE_TOKEN_PARAM = :private_token |
| 8 | - DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type] | |
| 8 | + DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type, :author_id] | |
| 9 | 9 | |
| 10 | 10 | include SanitizeParams |
| 11 | 11 | include Noosfero::Plugin::HotSpot | ... | ... |
plugins/juventude
test/unit/api/articles_test.rb
| ... | ... | @@ -102,6 +102,52 @@ class ArticlesTest < ActiveSupport::TestCase |
| 102 | 102 | end |
| 103 | 103 | end |
| 104 | 104 | |
| 105 | + should "update body of article created by me" do | |
| 106 | + new_value = "Another body" | |
| 107 | + params[:article] = {:body => new_value} | |
| 108 | + article = fast_create(Article, :profile_id => person.id) | |
| 109 | + post "/api/v1/articles/#{article.id}?#{params.to_query}" | |
| 110 | + json = JSON.parse(last_response.body) | |
| 111 | + assert_equal new_value, json["article"]["body"] | |
| 112 | + end | |
| 113 | + | |
| 114 | + should "update title of article created by me" do | |
| 115 | + new_value = "Another name" | |
| 116 | + params[:article] = {:name => new_value} | |
| 117 | + article = fast_create(Article, :profile_id => person.id) | |
| 118 | + post "/api/v1/articles/#{article.id}?#{params.to_query}" | |
| 119 | + json = JSON.parse(last_response.body) | |
| 120 | + assert_equal new_value, json["article"]["title"] | |
| 121 | + end | |
| 122 | + | |
| 123 | + should 'not update article of another user' do | |
| 124 | + another_person = fast_create(Person, :environment_id => environment.id) | |
| 125 | + article = fast_create(Article, :profile_id => another_person.id) | |
| 126 | + params[:article] = {:title => 'Some title'} | |
| 127 | + post "/api/v1/articles/#{article.id}?#{params.to_query}" | |
| 128 | + assert_equal 403, last_response.status | |
| 129 | + end | |
| 130 | + | |
| 131 | + should 'not update article without permission in community' do | |
| 132 | + community = fast_create(Community, :environment_id => environment.id) | |
| 133 | + article = fast_create(Article, :profile_id => community.id) | |
| 134 | + params[:article] = {:name => 'New title'} | |
| 135 | + post "/api/v1/articles/#{article.id}?#{params.to_query}" | |
| 136 | + assert_equal 403, last_response.status | |
| 137 | + end | |
| 138 | + | |
| 139 | + | |
| 140 | + should 'update article of community if user has permission' do | |
| 141 | + community = fast_create(Community, :environment_id => environment.id) | |
| 142 | + give_permission(person, 'post_content', community) | |
| 143 | + article = fast_create(Article, :profile_id => community.id) | |
| 144 | + new_value = "Another body" | |
| 145 | + params[:article] = {:body => new_value} | |
| 146 | + post "/api/v1/articles/#{article.id}?#{params.to_query}" | |
| 147 | + json = JSON.parse(last_response.body) | |
| 148 | + assert_equal new_value, json["article"]["body"] | |
| 149 | + end | |
| 150 | + | |
| 105 | 151 | ############################# |
| 106 | 152 | # Profile Articles # |
| 107 | 153 | ############################# | ... | ... |