mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
Merge branch 'dev' into us78
This commit is contained in:
commit
b1b5edbfb4
@ -1,15 +1,13 @@
|
||||
|
||||
class API::TagsController < API::ApiController
|
||||
|
||||
before_action :authenticate_user!, except: [:index, :show]
|
||||
before_action :set_tag, only: [:show, :update, :destroy]
|
||||
before_action :authenticate_user!, except: %i[index show]
|
||||
before_action :set_tag, only: %i[show update destroy]
|
||||
|
||||
def index
|
||||
@tags = Tag.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
def create
|
||||
authorize Tag
|
||||
@ -44,4 +42,4 @@ class API::TagsController < API::ApiController
|
||||
def tag_params
|
||||
params.require(:tag).permit(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,13 +1,12 @@
|
||||
class API::ThemesController < API::ApiController
|
||||
before_action :authenticate_user!, except: [:index, :show]
|
||||
before_action :set_theme, only: [:show, :update, :destroy]
|
||||
before_action :authenticate_user!, except: %i[index show]
|
||||
before_action :set_theme, only: %i[show update destroy]
|
||||
|
||||
def index
|
||||
@themes = Theme.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
def create
|
||||
authorize Theme
|
||||
@ -35,11 +34,12 @@ class API::ThemesController < API::ApiController
|
||||
end
|
||||
|
||||
private
|
||||
def set_theme
|
||||
@theme = Theme.find(params[:id])
|
||||
end
|
||||
|
||||
def theme_params
|
||||
params.require(:theme).permit(:name)
|
||||
end
|
||||
def set_theme
|
||||
@theme = Theme.find(params[:id])
|
||||
end
|
||||
|
||||
def theme_params
|
||||
params.require(:theme).permit(:name)
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
class API::TrainingsController < API::ApiController
|
||||
include ApplicationHelper
|
||||
|
||||
before_action :authenticate_user!, except: [:index, :show]
|
||||
before_action :set_training, only: [:update, :destroy]
|
||||
before_action :authenticate_user!, except: %i[index show]
|
||||
before_action :set_training, only: %i[update destroy]
|
||||
|
||||
def index
|
||||
@requested_attributes = params[:requested_attributes]
|
||||
@ -12,7 +12,8 @@ class API::TrainingsController < API::ApiController
|
||||
end
|
||||
|
||||
if attribute_requested?(@requested_attributes, 'availabilities')
|
||||
@trainings = @trainings.includes(:availabilities => [:slots => [:reservation => [:user => [:profile, :trainings]]]]).order('availabilities.start_at DESC')
|
||||
@trainings = @trainings.includes(availabilities: [slots: [reservation: [user: %i[profile trainings]]]])
|
||||
.order('availabilities.start_at DESC')
|
||||
end
|
||||
end
|
||||
|
||||
@ -39,12 +40,10 @@ class API::TrainingsController < API::ApiController
|
||||
end
|
||||
|
||||
head :no_content
|
||||
elsif @training.update(training_params)
|
||||
render :show, status: :ok, location: @training
|
||||
else
|
||||
if @training.update(training_params)
|
||||
render :show, status: :ok, location: @training
|
||||
else
|
||||
render json: @training.errors, status: :unprocessable_entity
|
||||
end
|
||||
render json: @training.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@ -57,19 +56,24 @@ class API::TrainingsController < API::ApiController
|
||||
def availabilities
|
||||
authorize Training
|
||||
@training = Training.find(params[:id])
|
||||
@availabilities = @training.availabilities.includes(slots: {reservations: {user: [:profile, :trainings] }}).order('start_at DESC')
|
||||
@availabilities = @training.availabilities
|
||||
.includes(slots: { reservations: { user: %i[profile trainings] } })
|
||||
.order('start_at DESC')
|
||||
end
|
||||
|
||||
private
|
||||
def set_training
|
||||
@training = Training.find(params[:id])
|
||||
end
|
||||
|
||||
def valid_training_params
|
||||
params.require(:training).permit(:id, users: [])
|
||||
end
|
||||
def set_training
|
||||
@training = Training.find(params[:id])
|
||||
end
|
||||
|
||||
def training_params
|
||||
params.require(:training).permit(:id, :name, :description, :machine_ids, :plan_ids, :nb_total_places, :public_page, :disabled, training_image_attributes: [:attachment], machine_ids: [], plan_ids: [])
|
||||
end
|
||||
def valid_training_params
|
||||
params.require(:training).permit(:id, users: [])
|
||||
end
|
||||
|
||||
def training_params
|
||||
params.require(:training)
|
||||
.permit(:id, :name, :description, :machine_ids, :plan_ids, :nb_total_places, :public_page, :disabled,
|
||||
training_image_attributes: [:attachment], machine_ids: [], plan_ids: [])
|
||||
end
|
||||
end
|
||||
|
@ -4,8 +4,8 @@ class API::TranslationsController < API::ApiController
|
||||
|
||||
def show
|
||||
@translations = I18n.t params[:state]
|
||||
if @translations.class.name == String.name and @translations.start_with?('translation missing')
|
||||
render json: {error: @translations}, status: :unprocessable_entity
|
||||
if @translations.class.name == String.name && @translations.start_with?('translation missing')
|
||||
render json: { error: @translations }, status: :unprocessable_entity
|
||||
else
|
||||
render json: @translations, status: :ok
|
||||
end
|
||||
@ -15,4 +15,4 @@ class API::TranslationsController < API::ApiController
|
||||
I18n.locale = params[:locale] || I18n.default_locale
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ class API::UsersController < API::ApiController
|
||||
before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
if current_user.is_admin? and params[:role] == 'partner'
|
||||
if current_user.is_admin? && params[:role] == 'partner'
|
||||
@users = User.with_role(:partner).includes(:profile)
|
||||
else
|
||||
head 403
|
||||
@ -12,9 +12,16 @@ class API::UsersController < API::ApiController
|
||||
def create
|
||||
if current_user.is_admin?
|
||||
generated_password = Devise.friendly_token.first(8)
|
||||
@user = User.new(email: partner_params[:email], username: "#{partner_params[:first_name]}#{partner_params[:last_name]}",
|
||||
password: generated_password, password_confirmation: generated_password, group_id: Group.first.id)
|
||||
@user.build_profile(first_name: partner_params[:first_name], last_name: partner_params[:last_name], gender: true, birthday: Time.now, phone: '0000000000')
|
||||
@user = User.new(email: partner_params[:email],
|
||||
username: "#{partner_params[:first_name]}#{partner_params[:last_name]}",
|
||||
password: generated_password,
|
||||
password_confirmation: generated_password,
|
||||
group_id: Group.first.id)
|
||||
@user.build_profile(first_name: partner_params[:first_name],
|
||||
last_name: partner_params[:last_name],
|
||||
gender: true,
|
||||
birthday: Time.now,
|
||||
phone: '0000000000')
|
||||
|
||||
if @user.save
|
||||
@user.remove_role :member
|
||||
@ -29,6 +36,7 @@ class API::UsersController < API::ApiController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def partner_params
|
||||
params.require(:user).permit(:email, :first_name, :last_name)
|
||||
end
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
class API::VersionController < API::ApiController
|
||||
before_action :authenticate_user!
|
||||
|
||||
|
@ -29,6 +29,7 @@ class API::WalletController < API::ApiController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def credit_params
|
||||
params.permit(:id, :amount, :avoir, :avoir_date, :avoir_description)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user