Commit 0a4f86dda71679c761c6f2354e417dfe8557f03e

Authored by Rodrigo Souto
1 parent 4cb1363d

api: remove trailing whitespaces

lib/noosfero/api/v1/articles.rb
@@ -3,11 +3,11 @@ module Noosfero @@ -3,11 +3,11 @@ module Noosfero
3 module V1 3 module V1
4 class Articles < Grape::API 4 class Articles < Grape::API
5 before { authenticate! } 5 before { authenticate! }
6 - 6 +
7 ARTICLE_TYPES = Article.descendants.map{|a| a.to_s} 7 ARTICLE_TYPES = Article.descendants.map{|a| a.to_s}
8 - 8 +
9 resource :articles do 9 resource :articles do
10 - 10 +
11 # Collect articles 11 # Collect articles
12 # 12 #
13 # Parameters: 13 # Parameters:
@@ -22,13 +22,13 @@ module Noosfero @@ -22,13 +22,13 @@ module Noosfero
22 articles = articles.display_filter(current_person, nil) 22 articles = articles.display_filter(current_person, nil)
23 present articles, :with => Entities::Article, :fields => params[:fields] 23 present articles, :with => Entities::Article, :fields => params[:fields]
24 end 24 end
25 - 25 +
26 desc "Return the article id" 26 desc "Return the article id"
27 get ':id' do 27 get ':id' do
28 article = find_article(environment.articles, params[:id]) 28 article = find_article(environment.articles, params[:id])
29 present article, :with => Entities::Article, :fields => params[:fields] 29 present article, :with => Entities::Article, :fields => params[:fields]
30 end 30 end
31 - 31 +
32 get ':id/children' do 32 get ':id/children' do
33 article = find_article(environment.articles, params[:id]) 33 article = find_article(environment.articles, params[:id])
34 34
@@ -37,7 +37,7 @@ module Noosfero @@ -37,7 +37,7 @@ module Noosfero
37 articles = select_filtered_collection_of(article, 'children', params) 37 articles = select_filtered_collection_of(article, 'children', params)
38 articles = articles.display_filter(current_person, nil) 38 articles = articles.display_filter(current_person, nil)
39 39
40 - 40 +
41 #TODO make tests for this situation 41 #TODO make tests for this situation
42 if votes_order 42 if votes_order
43 articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').reorder('sum(coalesce(votes.vote, 0)) DESC') 43 articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').reorder('sum(coalesce(votes.vote, 0)) DESC')
@@ -46,7 +46,7 @@ module Noosfero @@ -46,7 +46,7 @@ module Noosfero
46 Article.hit(articles) 46 Article.hit(articles)
47 present articles, :with => Entities::Article, :fields => params[:fields] 47 present articles, :with => Entities::Article, :fields => params[:fields]
48 end 48 end
49 - 49 +
50 get ':id/children/:child_id' do 50 get ':id/children/:child_id' do
51 article = find_article(environment.articles, params[:id]) 51 article = find_article(environment.articles, params[:id])
52 present find_article(article.children, params[:child_id]), :with => Entities::Article, :fields => params[:fields] 52 present find_article(article.children, params[:child_id]), :with => Entities::Article, :fields => params[:fields]
@@ -75,7 +75,7 @@ module Noosfero @@ -75,7 +75,7 @@ module Noosfero
75 return forbidden! unless parent_article.allow_create?(current_person) 75 return forbidden! unless parent_article.allow_create?(current_person)
76 76
77 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] 77 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
78 - #FIXME see how to check the article types 78 + #FIXME see how to check the article types
79 #return forbidden! unless ARTICLE_TYPES.include?(klass_type) 79 #return forbidden! unless ARTICLE_TYPES.include?(klass_type)
80 80
81 article = klass_type.constantize.new(params[:article]) 81 article = klass_type.constantize.new(params[:article])
@@ -92,7 +92,7 @@ module Noosfero @@ -92,7 +92,7 @@ module Noosfero
92 end 92 end
93 93
94 end 94 end
95 - 95 +
96 resource :communities do 96 resource :communities do
97 segment '/:community_id' do 97 segment '/:community_id' do
98 resource :articles do 98 resource :articles do
@@ -102,38 +102,38 @@ module Noosfero @@ -102,38 +102,38 @@ module Noosfero
102 articles = articles.display_filter(current_person, community) 102 articles = articles.display_filter(current_person, community)
103 present articles, :with => Entities::Article, :fields => params[:fields] 103 present articles, :with => Entities::Article, :fields => params[:fields]
104 end 104 end
105 - 105 +
106 get ':id' do 106 get ':id' do
107 community = environment.communities.find(params[:community_id]) 107 community = environment.communities.find(params[:community_id])
108 article = find_article(community.articles, params[:id]) 108 article = find_article(community.articles, params[:id])
109 present article, :with => Entities::Article, :fields => params[:fields] 109 present article, :with => Entities::Article, :fields => params[:fields]
110 end 110 end
111 - 111 +
112 # Example Request: 112 # Example Request:
113 # POST api/v1/communites/:community_id/articles?private_token=234298743290432&article[name]=title&article[body]=body 113 # POST api/v1/communites/:community_id/articles?private_token=234298743290432&article[name]=title&article[body]=body
114 post do 114 post do
115 community = environment.communities.find(params[:community_id]) 115 community = environment.communities.find(params[:community_id])
116 return forbidden! unless current_person.can_post_content?(community) 116 return forbidden! unless current_person.can_post_content?(community)
117 - 117 +
118 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] 118 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
119 return forbidden! unless ARTICLE_TYPES.include?(klass_type) 119 return forbidden! unless ARTICLE_TYPES.include?(klass_type)
120 - 120 +
121 article = klass_type.constantize.new(params[:article]) 121 article = klass_type.constantize.new(params[:article])
122 article.last_changed_by = current_person 122 article.last_changed_by = current_person
123 article.created_by= current_person 123 article.created_by= current_person
124 article.profile = community 124 article.profile = community
125 - 125 +
126 if !article.save 126 if !article.save
127 render_api_errors!(article.errors.full_messages) 127 render_api_errors!(article.errors.full_messages)
128 end 128 end
129 present article, :with => Entities::Article, :fields => params[:fields] 129 present article, :with => Entities::Article, :fields => params[:fields]
130 end 130 end
131 - 131 +
132 end 132 end
133 end 133 end
134 - 134 +
135 end 135 end
136 - 136 +
137 resource :people do 137 resource :people do
138 segment '/:person_id' do 138 segment '/:person_id' do
139 resource :articles do 139 resource :articles do
@@ -143,36 +143,36 @@ module Noosfero @@ -143,36 +143,36 @@ module Noosfero
143 articles = articles.display_filter(current_person, person) 143 articles = articles.display_filter(current_person, person)
144 present articles, :with => Entities::Article, :fields => params[:fields] 144 present articles, :with => Entities::Article, :fields => params[:fields]
145 end 145 end
146 - 146 +
147 get ':id' do 147 get ':id' do
148 person = environment.people.find(params[:person_id]) 148 person = environment.people.find(params[:person_id])
149 article = find_article(person.articles, params[:id]) 149 article = find_article(person.articles, params[:id])
150 present article, :with => Entities::Article, :fields => params[:fields] 150 present article, :with => Entities::Article, :fields => params[:fields]
151 end 151 end
152 - 152 +
153 post do 153 post do
154 person = environment.people.find(params[:person_id]) 154 person = environment.people.find(params[:person_id])
155 return forbidden! unless current_person.can_post_content?(person) 155 return forbidden! unless current_person.can_post_content?(person)
156 - 156 +
157 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] 157 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
158 return forbidden! unless ARTICLE_TYPES.include?(klass_type) 158 return forbidden! unless ARTICLE_TYPES.include?(klass_type)
159 - 159 +
160 article = klass_type.constantize.new(params[:article]) 160 article = klass_type.constantize.new(params[:article])
161 article.last_changed_by = current_person 161 article.last_changed_by = current_person
162 article.created_by= current_person 162 article.created_by= current_person
163 article.profile = person 163 article.profile = person
164 - 164 +
165 if !article.save 165 if !article.save
166 render_api_errors!(article.errors.full_messages) 166 render_api_errors!(article.errors.full_messages)
167 end 167 end
168 present article, :with => Entities::Article, :fields => params[:fields] 168 present article, :with => Entities::Article, :fields => params[:fields]
169 end 169 end
170 - 170 +
171 end 171 end
172 end 172 end
173 - 173 +
174 end 174 end
175 - 175 +
176 resource :enterprises do 176 resource :enterprises do
177 segment '/:enterprise_id' do 177 segment '/:enterprise_id' do
178 resource :articles do 178 resource :articles do
@@ -182,37 +182,36 @@ module Noosfero @@ -182,37 +182,36 @@ module Noosfero
182 articles = articles.display_filter(current_person, enterprise) 182 articles = articles.display_filter(current_person, enterprise)
183 present articles, :with => Entities::Article, :fields => params[:fields] 183 present articles, :with => Entities::Article, :fields => params[:fields]
184 end 184 end
185 - 185 +
186 get ':id' do 186 get ':id' do
187 enterprise = environment.enterprises.find(params[:enterprise_id]) 187 enterprise = environment.enterprises.find(params[:enterprise_id])
188 article = find_article(enterprise.articles, params[:id]) 188 article = find_article(enterprise.articles, params[:id])
189 present article, :with => Entities::Article, :fields => params[:fields] 189 present article, :with => Entities::Article, :fields => params[:fields]
190 end 190 end
191 - 191 +
192 post do 192 post do
193 enterprise = environment.enterprises.find(params[:enterprise_id]) 193 enterprise = environment.enterprises.find(params[:enterprise_id])
194 return forbidden! unless current_person.can_post_content?(enterprise) 194 return forbidden! unless current_person.can_post_content?(enterprise)
195 - 195 +
196 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] 196 klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
197 return forbidden! unless ARTICLE_TYPES.include?(klass_type) 197 return forbidden! unless ARTICLE_TYPES.include?(klass_type)
198 - 198 +
199 article = klass_type.constantize.new(params[:article]) 199 article = klass_type.constantize.new(params[:article])
200 article.last_changed_by = current_person 200 article.last_changed_by = current_person
201 article.created_by= current_person 201 article.created_by= current_person
202 article.profile = enterprise 202 article.profile = enterprise
203 - 203 +
204 if !article.save 204 if !article.save
205 render_api_errors!(article.errors.full_messages) 205 render_api_errors!(article.errors.full_messages)
206 end 206 end
207 present article, :with => Entities::Article, :fields => params[:fields] 207 present article, :with => Entities::Article, :fields => params[:fields]
208 end 208 end
209 - 209 +
210 end 210 end
211 end 211 end
212 - 212 +
213 end 213 end
214 -  
215 - 214 +
216 end 215 end
217 end 216 end
218 end 217 end
lib/noosfero/api/v1/categories.rb
@@ -3,22 +3,22 @@ module Noosfero @@ -3,22 +3,22 @@ module Noosfero
3 module V1 3 module V1
4 class Categories < Grape::API 4 class Categories < Grape::API
5 before { authenticate! } 5 before { authenticate! }
6 - 6 +
7 resource :categories do 7 resource :categories do
8 - 8 +
9 get do 9 get do
10 type = params[:category_type] 10 type = params[:category_type]
11 categories = type.nil? ? environment.categories : environment.categories.find(:all, :conditions => {:type => type}) 11 categories = type.nil? ? environment.categories : environment.categories.find(:all, :conditions => {:type => type})
12 present categories, :with => Entities::Category 12 present categories, :with => Entities::Category
13 end 13 end
14 -  
15 - desc "Return the category by id" 14 +
  15 + desc "Return the category by id"
16 get ':id' do 16 get ':id' do
17 present environment.categories.find(params[:id]), :with => Entities::Category 17 present environment.categories.find(params[:id]), :with => Entities::Category
18 end 18 end
19 - 19 +
20 end 20 end
21 - 21 +
22 end 22 end
23 end 23 end
24 end 24 end
lib/noosfero/api/v1/communities.rb
@@ -3,9 +3,9 @@ module Noosfero @@ -3,9 +3,9 @@ module Noosfero
3 module V1 3 module V1
4 class Communities < Grape::API 4 class Communities < Grape::API
5 before { authenticate! } 5 before { authenticate! }
6 - 6 +
7 resource :communities do 7 resource :communities do
8 - 8 +
9 # Collect comments from articles 9 # Collect comments from articles
10 # 10 #
11 # Parameters: 11 # Parameters:
@@ -21,8 +21,8 @@ module Noosfero @@ -21,8 +21,8 @@ module Noosfero
21 communities = communities.visible_for_person(current_person) 21 communities = communities.visible_for_person(current_person)
22 present communities, :with => Entities::Community 22 present communities, :with => Entities::Community
23 end 23 end
24 -  
25 - 24 +
  25 +
26 # Example Request: 26 # Example Request:
27 # POST api/v1/communties?private_token=234298743290432&community[name]=some_name 27 # POST api/v1/communties?private_token=234298743290432&community[name]=some_name
28 post do 28 post do
@@ -32,40 +32,40 @@ module Noosfero @@ -32,40 +32,40 @@ module Noosfero
32 rescue 32 rescue
33 community = Community.new(params[:community]) 33 community = Community.new(params[:community])
34 end 34 end
35 - 35 +
36 if !community.save 36 if !community.save
37 render_api_errors!(community.errors.full_messages) 37 render_api_errors!(community.errors.full_messages)
38 end 38 end
39 - 39 +
40 present community, :with => Entities::Community 40 present community, :with => Entities::Community
41 end 41 end
42 - 42 +
43 get ':id' do 43 get ':id' do
44 community = environment.communities.visible.find_by_id(params[:id]) 44 community = environment.communities.visible.find_by_id(params[:id])
45 present community, :with => Entities::Community 45 present community, :with => Entities::Community
46 end 46 end
47 - 47 +
48 end 48 end
49 - 49 +
50 resource :people do 50 resource :people do
51 - 51 +
52 segment '/:person_id' do 52 segment '/:person_id' do
53 - 53 +
54 resource :communities do 54 resource :communities do
55 - 55 +
56 get do 56 get do
57 person = environment.people.find(params[:person_id]) 57 person = environment.people.find(params[:person_id])
58 communities = select_filtered_collection_of(person, 'communities', params) 58 communities = select_filtered_collection_of(person, 'communities', params)
59 communities = communities.visible 59 communities = communities.visible
60 present communities, :with => Entities::Community 60 present communities, :with => Entities::Community
61 end 61 end
62 - 62 +
63 end 63 end
64 - 64 +
65 end 65 end
66 - 66 +
67 end 67 end
68 - 68 +
69 end 69 end
70 end 70 end
71 end 71 end
lib/noosfero/api/v1/enterprises.rb
@@ -3,9 +3,9 @@ module Noosfero @@ -3,9 +3,9 @@ module Noosfero
3 module V1 3 module V1
4 class Enterprises < Grape::API 4 class Enterprises < Grape::API
5 before { authenticate! } 5 before { authenticate! }
6 - 6 +
7 resource :enterprises do 7 resource :enterprises do
8 - 8 +
9 # Collect comments from articles 9 # Collect comments from articles
10 # 10 #
11 # Parameters: 11 # Parameters:
@@ -21,35 +21,35 @@ module Noosfero @@ -21,35 +21,35 @@ module Noosfero
21 enterprises = enterprises.visible_for_person(current_person) 21 enterprises = enterprises.visible_for_person(current_person)
22 present enterprises, :with => Entities::Enterprise 22 present enterprises, :with => Entities::Enterprise
23 end 23 end
24 - 24 +
25 desc "Return one enterprise by id" 25 desc "Return one enterprise by id"
26 get ':id' do 26 get ':id' do
27 enterprise = environment.enterprises.visible.find_by_id(params[:id]) 27 enterprise = environment.enterprises.visible.find_by_id(params[:id])
28 present enterprise, :with => Entities::Enterprise 28 present enterprise, :with => Entities::Enterprise
29 end 29 end
30 - 30 +
31 end 31 end
32 - 32 +
33 resource :people do 33 resource :people do
34 - 34 +
35 segment '/:person_id' do 35 segment '/:person_id' do
36 - 36 +
37 resource :enterprises do 37 resource :enterprises do
38 - 38 +
39 get do 39 get do
40 person = environment.people.find(params[:person_id]) 40 person = environment.people.find(params[:person_id])
41 enterprises = select_filtered_collection_of(person, 'enterprises', params) 41 enterprises = select_filtered_collection_of(person, 'enterprises', params)
42 enterprises = enterprises.visible 42 enterprises = enterprises.visible
43 present enterprises, :with => Entities::Enterprise 43 present enterprises, :with => Entities::Enterprise
44 end 44 end
45 - 45 +
46 end 46 end
47 - 47 +
48 end 48 end
49 - 49 +
50 end 50 end
51 -  
52 - 51 +
  52 +
53 end 53 end
54 end 54 end
55 end 55 end
lib/noosfero/api/v1/people.rb
@@ -3,9 +3,9 @@ module Noosfero @@ -3,9 +3,9 @@ module Noosfero
3 module V1 3 module V1
4 class People < Grape::API 4 class People < Grape::API
5 before { authenticate! } 5 before { authenticate! }
6 - 6 +
7 resource :people do 7 resource :people do
8 - 8 +
9 # Collect comments from articles 9 # Collect comments from articles
10 # 10 #
11 # Parameters: 11 # Parameters:
@@ -21,21 +21,21 @@ module Noosfero @@ -21,21 +21,21 @@ module Noosfero
21 people = people.visible_for_person(current_person) 21 people = people.visible_for_person(current_person)
22 present people, :with => Entities::Person 22 present people, :with => Entities::Person
23 end 23 end
24 - 24 +
25 desc "Return the person information" 25 desc "Return the person information"
26 get ':id' do 26 get ':id' do
27 person = environment.people.visible.find_by_id(params[:id]) 27 person = environment.people.visible.find_by_id(params[:id])
28 present person, :with => Entities::Person 28 present person, :with => Entities::Person
29 end 29 end
30 - 30 +
31 desc "Return the person friends" 31 desc "Return the person friends"
32 get ':id/friends' do 32 get ':id/friends' do
33 friends = current_person.friends.visible 33 friends = current_person.friends.visible
34 present friends, :with => Entities::Person 34 present friends, :with => Entities::Person
35 end 35 end
36 - 36 +
37 end 37 end
38 - 38 +
39 end 39 end
40 end 40 end
41 end 41 end
lib/noosfero/api/v1/tasks.rb
@@ -3,11 +3,11 @@ module Noosfero @@ -3,11 +3,11 @@ module Noosfero
3 module V1 3 module V1
4 class Tasks < Grape::API 4 class Tasks < Grape::API
5 # before { authenticate! } 5 # before { authenticate! }
6 - 6 +
7 # ARTICLE_TYPES = Article.descendants.map{|a| a.to_s} 7 # ARTICLE_TYPES = Article.descendants.map{|a| a.to_s}
8 - 8 +
9 resource :tasks do 9 resource :tasks do
10 - 10 +
11 # Collect tasks 11 # Collect tasks
12 # 12 #
13 # Parameters: 13 # Parameters:
@@ -22,16 +22,16 @@ module Noosfero @@ -22,16 +22,16 @@ module Noosfero
22 tasks = select_filtered_collection_of(environment, 'tasks', params) 22 tasks = select_filtered_collection_of(environment, 'tasks', params)
23 present tasks, :with => Entities::Task, :fields => params[:fields] 23 present tasks, :with => Entities::Task, :fields => params[:fields]
24 end 24 end
25 - 25 +
26 desc "Return the task id" 26 desc "Return the task id"
27 get ':id' do 27 get ':id' do
28 task = find_task(environment.tasks, params[:id]) 28 task = find_task(environment.tasks, params[:id])
29 present task, :with => Entities::Task, :fields => params[:fields] 29 present task, :with => Entities::Task, :fields => params[:fields]
30 end 30 end
31 - 31 +
32 32
33 end 33 end
34 - 34 +
35 resource :communities do 35 resource :communities do
36 segment '/:community_id' do 36 segment '/:community_id' do
37 resource :tasks do 37 resource :tasks do
@@ -41,38 +41,38 @@ module Noosfero @@ -41,38 +41,38 @@ module Noosfero
41 tasks = select_filtered_collection_of(community, 'tasks', params) 41 tasks = select_filtered_collection_of(community, 'tasks', params)
42 present tasks, :with => Entities::Task, :fields => params[:fields] 42 present tasks, :with => Entities::Task, :fields => params[:fields]
43 end 43 end
44 - 44 +
45 get ':id' do 45 get ':id' do
46 community = environment.communities.find(params[:community_id]) 46 community = environment.communities.find(params[:community_id])
47 task = find_task(community.tasks, params[:id]) 47 task = find_task(community.tasks, params[:id])
48 present task, :with => Entities::Task, :fields => params[:fields] 48 present task, :with => Entities::Task, :fields => params[:fields]
49 end 49 end
50 - 50 +
51 # Example Request: 51 # Example Request:
52 # POST api/v1/communites/:community_id/articles?private_token=234298743290432&article[name]=title&article[body]=body 52 # POST api/v1/communites/:community_id/articles?private_token=234298743290432&article[name]=title&article[body]=body
53 post do 53 post do
54 community = environment.communities.find(params[:community_id]) 54 community = environment.communities.find(params[:community_id])
55 #FIXME see the correct permission 55 #FIXME see the correct permission
56 return forbidden! unless current_person.can_post_content?(community) 56 return forbidden! unless current_person.can_post_content?(community)
57 -#FIXME check the task type before create 57 +#FIXME check the task type before create
58 klass_type= params[:content_type].nil? ? 'Task' : params[:content_type] 58 klass_type= params[:content_type].nil? ? 'Task' : params[:content_type]
59 # return forbidden! unless ARTICLE_TYPES.include?(klass_type) 59 # return forbidden! unless ARTICLE_TYPES.include?(klass_type)
60 -# 60 +#
61 task = klass_type.constantize.new(params[:task]) 61 task = klass_type.constantize.new(params[:task])
62 task.requestor = current_person 62 task.requestor = current_person
63 task.target = community 63 task.target = community
64 - 64 +
65 if !task.save 65 if !task.save
66 render_api_errors!(task.errors.full_messages) 66 render_api_errors!(task.errors.full_messages)
67 end 67 end
68 present task, :with => Entities::Task, :fields => params[:fields] 68 present task, :with => Entities::Task, :fields => params[:fields]
69 end 69 end
70 - 70 +
71 end 71 end
72 end 72 end
73 - 73 +
74 end 74 end
75 - 75 +
76 resource :people do 76 resource :people do
77 segment '/:person_id' do 77 segment '/:person_id' do
78 resource :tasks do 78 resource :tasks do
@@ -83,38 +83,38 @@ module Noosfero @@ -83,38 +83,38 @@ module Noosfero
83 tasks = Task.all 83 tasks = Task.all
84 present tasks, :with => Entities::Task, :fields => params[:fields] 84 present tasks, :with => Entities::Task, :fields => params[:fields]
85 end 85 end
86 - 86 +
87 get ':id' do 87 get ':id' do
88 # person = environment.people.find(params[:person_id]) 88 # person = environment.people.find(params[:person_id])
89 # article = find_article(person.articles, params[:id]) 89 # article = find_article(person.articles, params[:id])
90 task = Task.first 90 task = Task.first
91 present task, :with => Entities::Task, :fields => params[:fields] 91 present task, :with => Entities::Task, :fields => params[:fields]
92 end 92 end
93 - 93 +
94 post do 94 post do
95 # person = environment.people.find(params[:person_id]) 95 # person = environment.people.find(params[:person_id])
96 # return forbidden! unless current_person.can_post_content?(person) 96 # return forbidden! unless current_person.can_post_content?(person)
97 -# 97 +#
98 # klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] 98 # klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
99 # return forbidden! unless ARTICLE_TYPES.include?(klass_type) 99 # return forbidden! unless ARTICLE_TYPES.include?(klass_type)
100 -# 100 +#
101 # article = klass_type.constantize.new(params[:article]) 101 # article = klass_type.constantize.new(params[:article])
102 # article.last_changed_by = current_person 102 # article.last_changed_by = current_person
103 # article.created_by= current_person 103 # article.created_by= current_person
104 # article.profile = person 104 # article.profile = person
105 -# 105 +#
106 # if !article.save 106 # if !article.save
107 # render_api_errors!(article.errors.full_messages) 107 # render_api_errors!(article.errors.full_messages)
108 # end 108 # end
109 task = Task.first 109 task = Task.first
110 present task, :with => Entities::Task, :fields => params[:fields] 110 present task, :with => Entities::Task, :fields => params[:fields]
111 end 111 end
112 - 112 +
113 end 113 end
114 end 114 end
115 - 115 +
116 end 116 end
117 - 117 +
118 resource :enterprises do 118 resource :enterprises do
119 segment '/:enterprise_id' do 119 segment '/:enterprise_id' do
120 resource :tasks do 120 resource :tasks do
@@ -125,39 +125,39 @@ task = Task.first @@ -125,39 +125,39 @@ task = Task.first
125 tasks = Task.all 125 tasks = Task.all
126 present tasks, :with => Entities::Task, :fields => params[:fields] 126 present tasks, :with => Entities::Task, :fields => params[:fields]
127 end 127 end
128 - 128 +
129 get ':id' do 129 get ':id' do
130 # enterprise = environment.enterprises.find(params[:enterprise_id]) 130 # enterprise = environment.enterprises.find(params[:enterprise_id])
131 # article = find_article(enterprise.articles, params[:id]) 131 # article = find_article(enterprise.articles, params[:id])
132 task = Task.first 132 task = Task.first
133 present task, :with => Entities::Task, :fields => params[:fields] 133 present task, :with => Entities::Task, :fields => params[:fields]
134 end 134 end
135 - 135 +
136 post do 136 post do
137 # enterprise = environment.enterprises.find(params[:enterprise_id]) 137 # enterprise = environment.enterprises.find(params[:enterprise_id])
138 # return forbidden! unless current_person.can_post_content?(enterprise) 138 # return forbidden! unless current_person.can_post_content?(enterprise)
139 -# 139 +#
140 # klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] 140 # klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
141 # return forbidden! unless ARTICLE_TYPES.include?(klass_type) 141 # return forbidden! unless ARTICLE_TYPES.include?(klass_type)
142 -# 142 +#
143 # article = klass_type.constantize.new(params[:article]) 143 # article = klass_type.constantize.new(params[:article])
144 # article.last_changed_by = current_person 144 # article.last_changed_by = current_person
145 # article.created_by= current_person 145 # article.created_by= current_person
146 # article.profile = enterprise 146 # article.profile = enterprise
147 -# 147 +#
148 # if !article.save 148 # if !article.save
149 # render_api_errors!(article.errors.full_messages) 149 # render_api_errors!(article.errors.full_messages)
150 # end 150 # end
151 task = Task.first 151 task = Task.first
152 present task, :with => Entities::Task, :fields => params[:fields] 152 present task, :with => Entities::Task, :fields => params[:fields]
153 end 153 end
154 - 154 +
155 end 155 end
156 end 156 end
157 - 157 +
158 end 158 end
159 -  
160 - 159 +
  160 +
161 end 161 end
162 end 162 end
163 end 163 end
lib/noosfero/api/v1/users.rb
@@ -3,15 +3,15 @@ module Noosfero @@ -3,15 +3,15 @@ module Noosfero
3 module V1 3 module V1
4 class Users < Grape::API 4 class Users < Grape::API
5 before { authenticate! } 5 before { authenticate! }
6 - 6 +
7 resource :users do 7 resource :users do
8 - 8 +
9 #FIXME make the pagination 9 #FIXME make the pagination
10 #FIXME put it on environment context 10 #FIXME put it on environment context
11 get do 11 get do
12 present environment.users, :with => Entities::User 12 present environment.users, :with => Entities::User
13 end 13 end
14 - 14 +
15 # Example Request: 15 # Example Request:
16 # POST api/v1/users?user[login]=some_login&user[password]=some 16 # POST api/v1/users?user[login]=some_login&user[password]=some
17 post do 17 post do
@@ -21,7 +21,7 @@ module Noosfero @@ -21,7 +21,7 @@ module Noosfero
21 if !user.save 21 if !user.save
22 render_api_errors!(user.errors.full_messages) 22 render_api_errors!(user.errors.full_messages)
23 end 23 end
24 - 24 +
25 present user, :with => Entities::User 25 present user, :with => Entities::User
26 end 26 end
27 27
@@ -38,14 +38,14 @@ module Noosfero @@ -38,14 +38,14 @@ module Noosfero
38 output = {} 38 output = {}
39 user.person.role_assignments.map do |role_assigment| 39 user.person.role_assignments.map do |role_assigment|
40 if role_assigment.resource.respond_to?(:identifier) && role_assigment.resource.identifier == params[:profile] 40 if role_assigment.resource.respond_to?(:identifier) && role_assigment.resource.identifier == params[:profile]
41 - output[:permissions] = role_assigment.role.permissions 41 + output[:permissions] = role_assigment.role.permissions
42 end 42 end
43 end 43 end
44 present output 44 present output
45 end 45 end
46 - 46 +
47 end 47 end
48 - 48 +
49 end 49 end
50 end 50 end
51 end 51 end