Commit 2931665f9d7afa4a9e23c08f6d6a7441b1ebe6b5
Exists in
master
and in
21 other branches
Merge branch 'software_infos_api' into 'master'
Adicionar campos do software_info na API - Adicionar timestamps no software_info, e mostrar na API - Mostrar somente os softwares que possuem comunidades visiveis See merge request !158
Showing
4 changed files
with
29 additions
and
0 deletions
Show diff stats
src/noosfero-spb/software_communities/db/migrate/20160114190943_add_timestamps_to_software_info.rb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +class AddTimestampsToSoftwareInfo < ActiveRecord::Migration | |
2 | + def up | |
3 | + change_table :software_infos do |t| | |
4 | + t.datetime :created_at, :null => false, :default => Time.zone.now | |
5 | + t.datetime :updated_at, :null => false, :default => Time.zone.now | |
6 | + end | |
7 | + end | |
8 | + | |
9 | + def down | |
10 | + remove_column :software_infos, :created_at | |
11 | + remove_column :software_infos, :updated_at | |
12 | + end | |
13 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/api.rb
... | ... | @@ -9,6 +9,7 @@ class SoftwareCommunitiesPlugin::API < Grape::API |
9 | 9 | get do |
10 | 10 | authenticate! |
11 | 11 | softwares = select_filtered_collection_of(environment,'communities',params).joins(:software_info) |
12 | + softwares = softwares.visible_for_person(current_person) | |
12 | 13 | present softwares.map{|o|o.software_info}, :with => Entities::SoftwareInfo |
13 | 14 | end |
14 | 15 | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/api_entities.rb
... | ... | @@ -18,6 +18,8 @@ module Entities |
18 | 18 | expose :software_languages |
19 | 19 | expose :software_databases |
20 | 20 | expose :operating_system_names |
21 | + expose :created_at, :format_with => :timestamp | |
22 | + expose :updated_at, :format_with => :timestamp | |
21 | 23 | expose :community_id do |software_info,options| |
22 | 24 | software_info.community.id |
23 | 25 | end | ... | ... |
src/noosfero-spb/software_communities/test/unit/api_test.rb
... | ... | @@ -28,4 +28,17 @@ class SoftwareCommunitiesApiTest < ActiveSupport::TestCase |
28 | 28 | assert_equal @software_info.id, json["software_info"]["id"] |
29 | 29 | end |
30 | 30 | |
31 | + should 'list only softwares with visible community' do | |
32 | + @software_info = create_software_info("software_test") | |
33 | + @software_info2 = create_software_info("software_test2") | |
34 | + | |
35 | + @software_info2.community.visible = false | |
36 | + @software_info2.community.save! | |
37 | + | |
38 | + get "/api/v1/software_communities?#{params.to_query}" | |
39 | + json = JSON.parse(last_response.body) | |
40 | + | |
41 | + assert_includes json['software_infos'].map{|c| c['id']}, @software_info.id | |
42 | + assert_not_includes json['software_infos'].map{|c| c['id']}, @software_info2.id | |
43 | + end | |
31 | 44 | end | ... | ... |