2021-04-01 10:59:27 +00:00
|
|
|
class AppsController < ApplicationController
|
2021-05-07 08:25:09 +00:00
|
|
|
skip_before_action :authenticate_request, only: [:show]
|
|
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
def index
|
|
|
|
|
authorize App
|
2021-05-10 19:28:06 +00:00
|
|
|
@apps = App.where(organization: @current_user.organization).order('created_at desc').includes(:user)
|
2021-04-29 06:41:23 +00:00
|
|
|
end
|
2021-04-05 07:49:48 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
def create
|
|
|
|
|
authorize App
|
|
|
|
|
@app = App.create({
|
|
|
|
|
name: 'Untitled app',
|
|
|
|
|
organization: @current_user.organization,
|
2021-05-10 19:23:57 +00:00
|
|
|
current_version: AppVersion.new(name: 'v0'),
|
|
|
|
|
user: @current_user
|
2021-04-29 06:41:23 +00:00
|
|
|
})
|
|
|
|
|
end
|
2021-04-02 11:09:35 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
def show
|
2021-05-07 08:25:09 +00:00
|
|
|
@app = App.find params[:id]
|
|
|
|
|
|
|
|
|
|
# Logic to bypass auth for public apps
|
|
|
|
|
unless @app.is_public
|
|
|
|
|
authenticate_request
|
|
|
|
|
authorize @app
|
|
|
|
|
end
|
2021-04-29 06:41:23 +00:00
|
|
|
end
|
2021-04-02 11:09:35 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
def update
|
|
|
|
|
authorize App
|
|
|
|
|
@app = App.find params[:id]
|
2021-05-07 08:25:09 +00:00
|
|
|
@app.update(params['app'].permit('name', 'current_version_id', 'is_public'))
|
2021-04-29 06:41:23 +00:00
|
|
|
end
|
2021-04-12 04:12:00 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
def users
|
|
|
|
|
@app = App.find params[:app_id]
|
|
|
|
|
@app_users = AppUser.where(app: @app).includes(:user)
|
|
|
|
|
end
|
2021-04-01 10:59:27 +00:00
|
|
|
end
|