2021-04-27 07:06:45 +00:00
|
|
|
class AppUsersController < ApplicationController
|
2021-04-29 06:41:23 +00:00
|
|
|
def create
|
|
|
|
|
org_user_id = params[:org_user_id]
|
|
|
|
|
app_id = params[:app_id]
|
|
|
|
|
role = params[:role]
|
2021-04-27 07:06:45 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
org_user = OrganizationUser.find org_user_id
|
|
|
|
|
app = App.find app_id
|
2021-04-27 07:06:45 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
app_user = AppUser.new(
|
|
|
|
|
role: role,
|
|
|
|
|
app: app,
|
|
|
|
|
user_id: org_user.user_id
|
|
|
|
|
)
|
2021-04-27 07:06:45 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
authorize app_user
|
2021-04-27 07:06:45 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
if app_user.save
|
|
|
|
|
render json: { success: true }
|
|
|
|
|
else
|
|
|
|
|
render json: { message: 'Could not create user' }, status: 500
|
2021-04-27 07:06:45 +00:00
|
|
|
end
|
2021-04-29 06:41:23 +00:00
|
|
|
end
|
2021-04-27 07:06:45 +00:00
|
|
|
end
|