3354: try again with edit (pencil) icon to the _right_ of the editable textile-render...
[arvados.git] / apps / workbench / test / functional / projects_controller_test.rb
1 require 'test_helper'
2
3 class ProjectsControllerTest < ActionController::TestCase
4   test "inactive user is asked to sign user agreements on front page" do
5     get :index, {}, session_for(:inactive)
6     assert_response :success
7     assert_not_empty assigns(:required_user_agreements),
8     "Inactive user did not have required_user_agreements"
9     assert_template 'user_agreements/index',
10     "Inactive user was not presented with a user agreement at the front page"
11   end
12
13   [[:active, true],
14    [:project_viewer, false]].each do |which_user, should_show|
15     test "create subproject button #{'not ' unless should_show} shown to #{which_user}" do
16       readonly_project_uuid = api_fixture('groups')['aproject']['uuid']
17       get :show, {
18         id: readonly_project_uuid
19       }, session_for(which_user)
20       buttons = css_select('[data-method=post]').select do |el|
21         el.attributes['href'].match /project.*owner_uuid.*#{readonly_project_uuid}/
22       end
23       if should_show
24         assert_not_empty(buttons, "did not offer to create a subproject")
25       else
26         assert_empty(buttons.collect(&:to_s),
27                      "offered to create a subproject in a non-writable project")
28       end
29     end
30   end
31
32   test "sharing a project with a user and group" do
33     uuid_list = [api_fixture("groups")["future_project_viewing_group"]["uuid"],
34                  api_fixture("users")["future_project_user"]["uuid"]]
35     post(:share_with, {
36            id: api_fixture("groups")["asubproject"]["uuid"],
37            uuids: uuid_list,
38            format: "json"},
39          session_for(:active))
40     assert_response :success
41     json_response = Oj.load(@response.body)
42     assert_equal(uuid_list, json_response["success"])
43   end
44
45   test "user with project read permission can't add permissions" do
46     share_uuid = api_fixture("users")["spectator"]["uuid"]
47     post(:share_with, {
48            id: api_fixture("groups")["aproject"]["uuid"],
49            uuids: [share_uuid],
50            format: "json"},
51          session_for(:project_viewer))
52     assert_response 422
53     json_response = Oj.load(@response.body)
54     assert(json_response["errors"].andand.
55              any? { |msg| msg.start_with?("#{share_uuid}: ") },
56            "JSON response missing properly formatted sharing error")
57   end
58
59   def user_can_manage(user_sym, group_key)
60     get(:show, {id: api_fixture("groups")[group_key]["uuid"]},
61         session_for(user_sym))
62     is_manager = assigns(:user_is_manager)
63     assert_not_nil(is_manager, "user_is_manager flag not set")
64     if not is_manager
65       assert_empty(assigns(:share_links),
66                    "non-manager has share links set")
67     end
68     is_manager
69   end
70
71   test "admin can_manage aproject" do
72     assert user_can_manage(:admin, "aproject")
73   end
74
75   test "owner can_manage aproject" do
76     assert user_can_manage(:active, "aproject")
77   end
78
79   test "owner can_manage asubproject" do
80     assert user_can_manage(:active, "asubproject")
81   end
82
83   test "viewer can't manage aproject" do
84     refute user_can_manage(:project_viewer, "aproject")
85   end
86
87   test "viewer can't manage asubproject" do
88     refute user_can_manage(:project_viewer, "asubproject")
89   end
90 end