Commit f6bd3c2687abc7411c816189ad96b694da6b5796
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'noosfero_grape_api' into rails3_api
Conflicts: lib/api/v1/users.rb
Showing
5 changed files
with
52 additions
and
2 deletions
Show diff stats
lib/api/api.rb
lib/api/entities.rb
... | ... | @@ -59,8 +59,18 @@ module API |
59 | 59 | |
60 | 60 | class User < Grape::Entity |
61 | 61 | root 'users', 'user' |
62 | + expose :id | |
62 | 63 | expose :login |
63 | 64 | expose :person, :using => Profile |
65 | + expose :permissions do |user, options| | |
66 | + output = {} | |
67 | + user.person.role_assignments.map do |role_assigment| | |
68 | + if role_assigment.resource.respond_to?(:identifier) | |
69 | + output[role_assigment.resource.identifier] = role_assigment.role.permissions | |
70 | + end | |
71 | + end | |
72 | + output | |
73 | + end | |
64 | 74 | end |
65 | 75 | |
66 | 76 | class UserLogin < User | ... | ... |
lib/api/v1/articles.rb
... | ... | @@ -65,8 +65,12 @@ module API |
65 | 65 | # POST api/v1/communites/:community_id/articles?private_toke=234298743290432&article[name]=title&article[body]=body |
66 | 66 | post do |
67 | 67 | community = environment.communities.find(params[:community_id]) |
68 | - article = community.articles.build(params[:article].merge(:last_changed_by => current_person)) | |
69 | - article.type= params[:type].nil? ? 'TinyMceArticle' : params[:type] | |
68 | + klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] | |
69 | + article = klass_type.constantize.new(params[:article]) | |
70 | + article.last_changed_by = current_person | |
71 | + article.created_by= current_person | |
72 | + article.profile = community | |
73 | + | |
70 | 74 | if !article.save |
71 | 75 | render_api_errors!(article.errors.full_messages) |
72 | 76 | end | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +module API | |
2 | + module V1 | |
3 | + class Categories < Grape::API | |
4 | + before { detect_stuff_by_domain } | |
5 | + before { authenticate! } | |
6 | + | |
7 | + resource :categories do | |
8 | + | |
9 | + get do | |
10 | + type = params[:category_type] | |
11 | + categories = type.nil? ? environment.categories : environment.categories.find(:all, :conditions => {:type => type}) | |
12 | + present categories, :with => Entities::Category | |
13 | + end | |
14 | + | |
15 | + desc "Return the category by id" | |
16 | + get ':id' do | |
17 | + present environment.categories.find(params[:id]), :with => Entities::Category | |
18 | + end | |
19 | + | |
20 | + end | |
21 | + | |
22 | + end | |
23 | + end | |
24 | +end | ... | ... |
lib/api/v1/users.rb
... | ... | @@ -15,6 +15,17 @@ module API |
15 | 15 | present environment.users.find(params[:id]), :with => Entities::User |
16 | 16 | end |
17 | 17 | |
18 | + get ":id/permissions" do | |
19 | + user = environment.users.find(params[:id]) | |
20 | + output = {} | |
21 | + user.person.role_assignments.map do |role_assigment| | |
22 | + if role_assigment.resource.respond_to?(:identifier) && role_assigment.resource.identifier == params[:profile] | |
23 | + output[:permissions] = role_assigment.role.permissions | |
24 | + end | |
25 | + end | |
26 | + present output | |
27 | + end | |
28 | + | |
18 | 29 | end |
19 | 30 | |
20 | 31 | end | ... | ... |