Skip to content

Commit 1fb84ef

Browse files
authored
Merge pull request #111 from Jess-White/feature/412-add-authorization-remove-org-users-actions
Feature/412 add authorization remove org users actions
2 parents c9abdc4 + 3950537 commit 1fb84ef

File tree

2 files changed

+0
-147
lines changed

2 files changed

+0
-147
lines changed

app/controllers/api/organization_users_controller.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@ def index
99
render 'api/users/index.json.jb'
1010
end
1111

12-
def create
13-
user = User.find(params[:id])
14-
@organization_user = OrganizationUser.create!(
15-
organization: @organization,
16-
user: user
17-
)
18-
19-
render 'show.json.jb', status: :created
20-
rescue ActiveRecord::RecordNotUnique
21-
@organization_user = organization_user
22-
render 'show.json.jb', status: :ok
23-
end
24-
25-
def show
26-
@organization_user = organization_user
27-
render 'show.json.jb'
28-
end
29-
3012
def destroy
3113
@organization_user = organization_user
3214
authorize @organization_user

spec/controllers/api/organization_users_controller_spec.rb

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -77,135 +77,6 @@
7777
end
7878
end
7979

80-
describe 'POST /organizations/:organization_id/users' do
81-
let(:michael) { create(:user, first_name: 'Michael') }
82-
83-
let(:new_organization_user_params) do
84-
{
85-
organization_id: good_place.id,
86-
id: michael.id
87-
}
88-
end
89-
90-
it 'renders 401 if unauthenticated' do
91-
post :create, params: new_organization_user_params
92-
expect(response).to have_http_status(401)
93-
end
94-
95-
it 'renders 401 if organization does not exist' do
96-
set_auth_header(chidi)
97-
post :create, params: {
98-
**new_organization_user_params,
99-
organization_id: '37e485b8-65e5-4502-a8aa-5217dd3160c3'
100-
}
101-
102-
expect(response).to have_http_status(401)
103-
end
104-
105-
it 'renders 401 if user does not exist' do
106-
set_auth_header(chidi)
107-
post :create, params: {
108-
**new_organization_user_params,
109-
id: 'dc846e2f-a86a-4e78-b217-6517a8bbca00'
110-
}
111-
112-
expect(response).to have_http_status(401)
113-
end
114-
115-
it 'renders 401 if not member of organization' do
116-
shawn = User.find_by!(first_name: 'Shawn')
117-
set_auth_header(shawn)
118-
post :create, params: new_organization_user_params
119-
120-
expect(response).to have_http_status(401)
121-
end
122-
123-
it 'renders 201 with added organization user' do
124-
set_auth_header(chidi)
125-
post :create, params: new_organization_user_params
126-
127-
expect(response).to have_http_status(201)
128-
expect(JSON.parse(response.body).keys).to contain_exactly(*user_fields)
129-
expect(JSON.parse(response.body)).to match(
130-
a_hash_including(
131-
'id' => michael.id,
132-
'created_at' => michael.created_at.iso8601(3),
133-
'updated_at' => michael.updated_at.iso8601(3),
134-
'email' => michael.email,
135-
'first_name' => michael.first_name,
136-
'last_name' => michael.last_name
137-
)
138-
)
139-
end
140-
141-
it 'renders 200 when user is already in organization' do
142-
set_auth_header(chidi)
143-
144-
post :create, params: new_organization_user_params
145-
expect(response).to have_http_status(201)
146-
147-
post :create, params: new_organization_user_params
148-
expect(response).to have_http_status(200)
149-
150-
expect(OrganizationUser.where(organization_id: good_place.id).count).to eq(3)
151-
end
152-
end
153-
154-
describe 'GET /organizations/:organization_id/users/:id' do
155-
it 'renders 401 if unauthenticated' do
156-
get :show, params: { organization_id: good_place.id, id: chidi.id }
157-
expect(response).to have_http_status(401)
158-
end
159-
160-
it 'renders 401 if organization does not exist' do
161-
set_auth_header(chidi)
162-
get :show, params: { organization_id: '43698687-16b4-4c23-939d-a2a8e8b8b6b1', id: chidi.id }
163-
164-
expect(response).to have_http_status(401)
165-
end
166-
167-
it 'renders 401 if user does not exist' do
168-
set_auth_header(chidi)
169-
get :show, params: { organization_id: good_place, id: '351b7cbe-c753-445f-a4dc-c24597ab923e' }
170-
171-
expect(response).to have_http_status(401)
172-
end
173-
174-
it 'renders 401 if requested user is not member of organization' do
175-
shawn = User.find_by!(first_name: 'Shawn')
176-
set_auth_header(chidi)
177-
get :show, params: { organization_id: good_place, id: shawn.id }
178-
179-
expect(response).to have_http_status(401)
180-
end
181-
182-
it 'renders 401 if authenticated user is not member of organization' do
183-
shawn = User.find_by!(first_name: 'Shawn')
184-
set_auth_header(shawn)
185-
get :show, params: { organization_id: good_place.id, id: chidi.id }
186-
187-
expect(response).to have_http_status(401)
188-
end
189-
190-
it 'renders 200 with organization user' do
191-
set_auth_header(chidi)
192-
get :show, params: { organization_id: good_place.id, id: chidi.id }
193-
194-
expect(response).to have_http_status(200)
195-
expect(JSON.parse(response.body).keys).to contain_exactly(*user_fields)
196-
expect(JSON.parse(response.body)).to match(
197-
a_hash_including(
198-
'id' => chidi.id,
199-
'created_at' => chidi.created_at.iso8601(3),
200-
'updated_at' => chidi.updated_at.iso8601(3),
201-
'email' => chidi.email,
202-
'first_name' => chidi.first_name,
203-
'last_name' => chidi.last_name
204-
)
205-
)
206-
end
207-
end
208-
20980
describe 'DELETE /organizations/:organization_id/users/:id' do
21081
before do
21182
allow_any_instance_of(OrganizationUserPolicy).to receive(:destroy?).and_return(true)

0 commit comments

Comments
 (0)