Commit 0aabc96cb2ab2bd8f5bb86651919c56312a11831
Exists in
staging
and in
1 other branch
Merge branch 'master' into staging
Showing
4 changed files
with
46 additions
and
7 deletions
Show diff stats
lib/noosfero/api/entities.rb
lib/noosfero/api/helpers.rb
... | ... | @@ -41,6 +41,11 @@ require_relative '../../find_by_contents' |
41 | 41 | current_user.person unless current_user.nil? |
42 | 42 | end |
43 | 43 | |
44 | + def is_admin?(environment) | |
45 | + return false unless current_user | |
46 | + return current_person.is_admin?(environment) | |
47 | + end | |
48 | + | |
44 | 49 | def logout |
45 | 50 | @current_user = nil |
46 | 51 | end | ... | ... |
lib/noosfero/api/v1/environments.rb
... | ... | @@ -11,13 +11,15 @@ module Noosfero |
11 | 11 | end |
12 | 12 | |
13 | 13 | get ':id' do |
14 | + local_environment = nil | |
14 | 15 | if (params[:id] == "default") |
15 | - present Environment.default | |
16 | + local_environment = Environment.default | |
16 | 17 | elsif (params[:id] == "context") |
17 | - present environment | |
18 | + local_environment = environment | |
18 | 19 | else |
19 | - present Environment.find(params[:id]) | |
20 | + local_environment = Environment.find(params[:id]) | |
20 | 21 | end |
22 | + present_partial local_environment, :with => Entities::Environment, :is_admin => is_admin?(local_environment) | |
21 | 23 | end |
22 | 24 | |
23 | 25 | end | ... | ... |
test/api/environment_test.rb
... | ... | @@ -2,16 +2,45 @@ require_relative 'test_helper' |
2 | 2 | |
3 | 3 | class EnvironmentTest < ActiveSupport::TestCase |
4 | 4 | |
5 | - def setup | |
6 | - @person = create_user('testing').person | |
5 | + should 'return the default environment' do | |
6 | + environment = Environment.default | |
7 | + get "/api/v1/environment/default" | |
8 | + json = JSON.parse(last_response.body) | |
9 | + assert_equal environment.id, json['id'] | |
7 | 10 | end |
8 | - attr_reader :person | |
9 | 11 | |
10 | - should 'return the default environment' do | |
12 | + should 'not return the default environment settings' do | |
11 | 13 | environment = Environment.default |
12 | 14 | get "/api/v1/environment/default" |
13 | 15 | json = JSON.parse(last_response.body) |
14 | 16 | assert_equal environment.id, json['id'] |
17 | + assert_nil json['settings'] | |
18 | + end | |
19 | + | |
20 | + should 'return the default environment settings for admin' do | |
21 | + login_api | |
22 | + environment = Environment.default | |
23 | + environment.add_admin(person) | |
24 | + get "/api/v1/environment/default?#{params.to_query}" | |
25 | + json = JSON.parse(last_response.body) | |
26 | + assert_equal environment.id, json['id'] | |
27 | + assert_equal environment.settings, json['settings'] | |
28 | + end | |
29 | + | |
30 | + should 'not return the default environment settings for non admin users' do | |
31 | + login_api | |
32 | + environment = Environment.default | |
33 | + get "/api/v1/environment/default?#{params.to_query}" | |
34 | + json = JSON.parse(last_response.body) | |
35 | + assert_equal environment.id, json['id'] | |
36 | + assert_nil json['settings'] | |
37 | + end | |
38 | + | |
39 | + should 'return the default environment description' do | |
40 | + environment = Environment.default | |
41 | + get "/api/v1/environment/default" | |
42 | + json = JSON.parse(last_response.body) | |
43 | + assert_equal environment.description, json['description'] | |
15 | 44 | end |
16 | 45 | |
17 | 46 | should 'return created environment' do | ... | ... |