mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
refactored roles methods to match ruby conventions
This commit is contained in:
parent
0927336956
commit
f6e236aeb5
@ -34,7 +34,7 @@ class API::AdminsController < API::ApiController
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@admin = User.admins.find(params[:id])
|
@admin = User.admins.find(params[:id])
|
||||||
if current_user.is_admin? and @admin != current_user
|
if current_user.admin? and @admin != current_user
|
||||||
@admin.destroy
|
@admin.destroy
|
||||||
head :no_content
|
head :no_content
|
||||||
else
|
else
|
||||||
|
@ -139,14 +139,14 @@ class API::AvailabilitiesController < API::ApiController
|
|||||||
else
|
else
|
||||||
current_user
|
current_user
|
||||||
end
|
end
|
||||||
@current_user_role = current_user.is_admin? ? 'admin' : 'user'
|
@current_user_role = current_user.admin? ? 'admin' : 'user'
|
||||||
@machine = Machine.friendly.find(params[:machine_id])
|
@machine = Machine.friendly.find(params[:machine_id])
|
||||||
@slots = []
|
@slots = []
|
||||||
@reservations = Reservation.where('reservable_type = ? and reservable_id = ?', @machine.class.to_s, @machine.id)
|
@reservations = Reservation.where('reservable_type = ? and reservable_id = ?', @machine.class.to_s, @machine.id)
|
||||||
.includes(:slots, user: [:profile])
|
.includes(:slots, user: [:profile])
|
||||||
.references(:slots, :user)
|
.references(:slots, :user)
|
||||||
.where('slots.start_at > ?', Time.now)
|
.where('slots.start_at > ?', Time.now)
|
||||||
if @user.is_admin?
|
if @user.admin?
|
||||||
@availabilities = @machine.availabilities.includes(:tags)
|
@availabilities = @machine.availabilities.includes(:tags)
|
||||||
.where("end_at > ? AND available_type = 'machines'", Time.now)
|
.where("end_at > ? AND available_type = 'machines'", Time.now)
|
||||||
.where(lock: false)
|
.where(lock: false)
|
||||||
@ -201,7 +201,7 @@ class API::AvailabilitiesController < API::ApiController
|
|||||||
|
|
||||||
# who made the request?
|
# who made the request?
|
||||||
# 1) an admin (he can see all future availabilities)
|
# 1) an admin (he can see all future availabilities)
|
||||||
if current_user.is_admin?
|
if current_user.admin?
|
||||||
@availabilities = @availabilities.includes(:tags, :slots, trainings: [:machines])
|
@availabilities = @availabilities.includes(:tags, :slots, trainings: [:machines])
|
||||||
.where('availabilities.start_at > ?', Time.now)
|
.where('availabilities.start_at > ?', Time.now)
|
||||||
.where(lock: false)
|
.where(lock: false)
|
||||||
@ -227,13 +227,13 @@ class API::AvailabilitiesController < API::ApiController
|
|||||||
else
|
else
|
||||||
current_user
|
current_user
|
||||||
end
|
end
|
||||||
@current_user_role = current_user.is_admin? ? 'admin' : 'user'
|
@current_user_role = current_user.admin? ? 'admin' : 'user'
|
||||||
@space = Space.friendly.find(params[:space_id])
|
@space = Space.friendly.find(params[:space_id])
|
||||||
@slots = []
|
@slots = []
|
||||||
@reservations = Reservation.where('reservable_type = ? and reservable_id = ?', @space.class.to_s, @space.id)
|
@reservations = Reservation.where('reservable_type = ? and reservable_id = ?', @space.class.to_s, @space.id)
|
||||||
.includes(:slots, user: [:profile]).references(:slots, :user)
|
.includes(:slots, user: [:profile]).references(:slots, :user)
|
||||||
.where('slots.start_at > ?', Time.now)
|
.where('slots.start_at > ?', Time.now)
|
||||||
if current_user.is_admin?
|
if current_user.admin?
|
||||||
@availabilities = @space.availabilities.includes(:tags)
|
@availabilities = @space.availabilities.includes(:tags)
|
||||||
.where("end_at > ? AND available_type = 'space'", Time.now)
|
.where("end_at > ? AND available_type = 'space'", Time.now)
|
||||||
.where(lock: false)
|
.where(lock: false)
|
||||||
|
@ -24,7 +24,7 @@ class API::CouponsController < API::ApiController
|
|||||||
if @coupon.nil?
|
if @coupon.nil?
|
||||||
render json: {status: 'rejected'}, status: :not_found
|
render json: {status: 'rejected'}, status: :not_found
|
||||||
else
|
else
|
||||||
if !current_user.is_admin?
|
if !current_user.admin?
|
||||||
_user_id = current_user.id
|
_user_id = current_user.id
|
||||||
else
|
else
|
||||||
_user_id = params[:user_id]
|
_user_id = params[:user_id]
|
||||||
|
@ -11,7 +11,7 @@ class API::EventsController < API::ApiController
|
|||||||
@events = @events.joins(:event_themes).where('event_themes.id = :theme', theme: params[:theme_id]) if params[:theme_id]
|
@events = @events.joins(:event_themes).where('event_themes.id = :theme', theme: params[:theme_id]) if params[:theme_id]
|
||||||
@events = @events.where('age_range_id = :age_range', age_range: params[:age_range_id]) if params[:age_range_id]
|
@events = @events.where('age_range_id = :age_range', age_range: params[:age_range_id]) if params[:age_range_id]
|
||||||
|
|
||||||
if current_user and current_user.is_admin?
|
if current_user and current_user.admin?
|
||||||
case params[:scope]
|
case params[:scope]
|
||||||
when 'future'
|
when 'future'
|
||||||
@events = @events.where('availabilities.start_at >= ?', Time.now).order('availabilities.start_at DESC')
|
@events = @events.where('availabilities.start_at >= ?', Time.now).order('availabilities.start_at DESC')
|
||||||
|
@ -2,7 +2,7 @@ class API::GroupsController < API::ApiController
|
|||||||
before_action :authenticate_user!, except: :index
|
before_action :authenticate_user!, except: :index
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if current_user and current_user.is_admin?
|
if current_user and current_user.admin?
|
||||||
@groups = Group.all
|
@groups = Group.all
|
||||||
else
|
else
|
||||||
@groups = Group.where.not(slug: 'admins')
|
@groups = Group.where.not(slug: 'admins')
|
||||||
|
@ -43,7 +43,7 @@ class API::MembersController < API::ApiController
|
|||||||
|
|
||||||
|
|
||||||
# if the user is created by an admin and the authentication is made through an SSO, generate a migration token
|
# if the user is created by an admin and the authentication is made through an SSO, generate a migration token
|
||||||
if current_user.is_admin? and AuthProvider.active.providable_type != DatabaseProvider.name
|
if current_user.admin? and AuthProvider.active.providable_type != DatabaseProvider.name
|
||||||
@member.generate_auth_migration_token
|
@member.generate_auth_migration_token
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ class API::MembersController < API::ApiController
|
|||||||
.where("users.is_active = 'true' AND roles.name = 'member'")
|
.where("users.is_active = 'true' AND roles.name = 'member'")
|
||||||
.where("lower(f_unaccent(profiles.first_name)) ~ regexp_replace(:search, E'\\\\s+', '|') OR lower(f_unaccent(profiles.last_name)) ~ regexp_replace(:search, E'\\\\s+', '|')", search: params[:query].downcase)
|
.where("lower(f_unaccent(profiles.first_name)) ~ regexp_replace(:search, E'\\\\s+', '|') OR lower(f_unaccent(profiles.last_name)) ~ regexp_replace(:search, E'\\\\s+', '|')", search: params[:query].downcase)
|
||||||
|
|
||||||
if current_user.is_member?
|
if current_user.member?
|
||||||
# non-admin can only retrieve users with "public profiles"
|
# non-admin can only retrieve users with "public profiles"
|
||||||
@members = @members.where("users.is_allow_contact = 'true'")
|
@members = @members.where("users.is_allow_contact = 'true'")
|
||||||
else
|
else
|
||||||
@ -266,7 +266,7 @@ class API::MembersController < API::ApiController
|
|||||||
organization_attributes: [:id, :name,
|
organization_attributes: [:id, :name,
|
||||||
address_attributes: %i[id address]]])
|
address_attributes: %i[id address]]])
|
||||||
|
|
||||||
elsif current_user.is_admin?
|
elsif current_user.admin?
|
||||||
params.require(:user).permit(:username, :email, :password, :password_confirmation,
|
params.require(:user).permit(:username, :email, :password, :password_confirmation,
|
||||||
:is_allow_contact, :is_allow_newsletter, :group_id,
|
:is_allow_contact, :is_allow_newsletter, :group_id,
|
||||||
training_ids: [], tag_ids: [],
|
training_ids: [], tag_ids: [],
|
||||||
|
@ -44,7 +44,7 @@ class API::PricesController < API::ApiController
|
|||||||
@amount = {elements: nil, total: 0, before_coupon: 0}
|
@amount = {elements: nil, total: 0, before_coupon: 0}
|
||||||
else
|
else
|
||||||
_reservable = _price_params[:reservable_type].constantize.find(_price_params[:reservable_id])
|
_reservable = _price_params[:reservable_type].constantize.find(_price_params[:reservable_id])
|
||||||
@amount = Price.compute(current_user.is_admin?, _user, _reservable, _price_params[:slots_attributes] || [], _price_params[:plan_id], _price_params[:nb_reserve_places], _price_params[:tickets_attributes], coupon_params[:coupon_code])
|
@amount = Price.compute(current_user.admin?, _user, _reservable, _price_params[:slots_attributes] || [], _price_params[:plan_id], _price_params[:nb_reserve_places], _price_params[:tickets_attributes], coupon_params[:coupon_code])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@ class API::ReservationsController < API::ApiController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:reservable_id] && params[:reservable_type] && params[:user_id]
|
if params[:reservable_id] && params[:reservable_type] && params[:user_id]
|
||||||
params[:user_id] = current_user.id unless current_user.is_admin?
|
params[:user_id] = current_user.id unless current_user.admin?
|
||||||
|
|
||||||
@reservations = Reservation.where(params.permit(:reservable_id, :reservable_type, :user_id))
|
@reservations = Reservation.where(params.permit(:reservable_id, :reservable_type, :user_id))
|
||||||
elsif params[:reservable_id] && params[:reservable_type] && current_user.is_admin?
|
elsif params[:reservable_id] && params[:reservable_type] && current_user.admin?
|
||||||
@reservations = Reservation.where(params.permit(:reservable_id, :reservable_type))
|
@reservations = Reservation.where(params.permit(:reservable_id, :reservable_type))
|
||||||
else
|
else
|
||||||
@reservations = []
|
@reservations = []
|
||||||
@ -18,8 +18,8 @@ class API::ReservationsController < API::ApiController
|
|||||||
def show; end
|
def show; end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
method = current_user.is_admin? ? :local : :stripe
|
method = current_user.admin? ? :local : :stripe
|
||||||
user_id = current_user.is_admin? ? reservation_params[:user_id] : current_user.id
|
user_id = current_user.admin? ? reservation_params[:user_id] : current_user.id
|
||||||
|
|
||||||
@reservation = Reservation.new(reservation_params)
|
@reservation = Reservation.new(reservation_params)
|
||||||
is_reserve = Reservations::Reserve.new(user_id)
|
is_reserve = Reservations::Reserve.new(user_id)
|
||||||
|
@ -12,8 +12,8 @@ class API::SubscriptionsController < API::ApiController
|
|||||||
if fablab_plans_deactivated?
|
if fablab_plans_deactivated?
|
||||||
head 403
|
head 403
|
||||||
else
|
else
|
||||||
method = current_user.is_admin? ? :local : :stripe
|
method = current_user.admin? ? :local : :stripe
|
||||||
user_id = current_user.is_admin? ? subscription_params[:user_id] : current_user.id
|
user_id = current_user.admin? ? subscription_params[:user_id] : current_user.id
|
||||||
|
|
||||||
@subscription = Subscription.new(subscription_params)
|
@subscription = Subscription.new(subscription_params)
|
||||||
is_subscribe = Subscriptions::Subscribe.new(user_id)
|
is_subscribe = Subscriptions::Subscribe.new(user_id)
|
||||||
|
@ -6,7 +6,7 @@ class API::TrainingsPricingsController < API::ApiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if current_user.is_admin?
|
if current_user.admin?
|
||||||
@trainings_pricing = TrainingsPricing.find(params[:id])
|
@trainings_pricing = TrainingsPricing.find(params[:id])
|
||||||
_trainings_pricing_params = trainings_pricing_params
|
_trainings_pricing_params = trainings_pricing_params
|
||||||
_trainings_pricing_params[:amount] = _trainings_pricing_params[:amount] * 100
|
_trainings_pricing_params[:amount] = _trainings_pricing_params[:amount] * 100
|
||||||
|
@ -2,7 +2,7 @@ class API::UsersController < API::ApiController
|
|||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if current_user.is_admin? && params[:role] == 'partner'
|
if current_user.admin? && params[:role] == 'partner'
|
||||||
@users = User.with_role(:partner).includes(:profile)
|
@users = User.with_role(:partner).includes(:profile)
|
||||||
else
|
else
|
||||||
head 403
|
head 403
|
||||||
@ -10,7 +10,7 @@ class API::UsersController < API::ApiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if current_user.is_admin?
|
if current_user.admin?
|
||||||
generated_password = Devise.friendly_token.first(8)
|
generated_password = Devise.friendly_token.first(8)
|
||||||
@user = User.new(email: partner_params[:email],
|
@user = User.new(email: partner_params[:email],
|
||||||
username: "#{partner_params[:first_name]}#{partner_params[:last_name]}",
|
username: "#{partner_params[:first_name]}#{partner_params[:last_name]}",
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# User is a physical or moral person with its authentication parameters
|
||||||
|
# It is linked to the Profile model with hold informations about this person (like address, name, etc.)
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
include NotifyWith::NotificationReceiver
|
include NotifyWith::NotificationReceiver
|
||||||
include NotifyWith::NotificationAttachedObject
|
include NotifyWith::NotificationAttachedObject
|
||||||
# Include default devise modules. Others available are:
|
# Include default devise modules. Others available are:
|
||||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
# :lockable, :timeoutable and :omniauthable
|
||||||
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable,
|
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable,
|
||||||
:confirmable, :async
|
:confirmable, :async
|
||||||
rolify
|
rolify
|
||||||
@ -73,7 +77,7 @@ class User < ActiveRecord::Base
|
|||||||
scope :without_subscription, -> { includes(:subscriptions).where(subscriptions: { user_id: nil }) }
|
scope :without_subscription, -> { includes(:subscriptions).where(subscriptions: { user_id: nil }) }
|
||||||
scope :with_subscription, -> { joins(:subscriptions) }
|
scope :with_subscription, -> { joins(:subscriptions) }
|
||||||
|
|
||||||
def to_json(options = {})
|
def to_json(*)
|
||||||
ApplicationController.new.view_context.render(
|
ApplicationController.new.view_context.render(
|
||||||
partial: 'api/members/member',
|
partial: 'api/members/member',
|
||||||
locals: { member: self },
|
locals: { member: self },
|
||||||
@ -87,7 +91,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def training_machine?(machine)
|
def training_machine?(machine)
|
||||||
return true if is_admin?
|
return true if admin?
|
||||||
|
|
||||||
trainings.map(&:machines).flatten.uniq.include?(machine)
|
trainings.map(&:machines).flatten.uniq.include?(machine)
|
||||||
end
|
end
|
||||||
@ -106,11 +110,11 @@ class User < ActiveRecord::Base
|
|||||||
subscriptions.order(:created_at).last
|
subscriptions.order(:created_at).last
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_admin?
|
def admin?
|
||||||
has_role? :admin
|
has_role? :admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_member?
|
def member?
|
||||||
has_role? :member
|
has_role? :member
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -285,7 +289,6 @@ class User < ActiveRecord::Base
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assign_default_role
|
def assign_default_role
|
||||||
@ -340,5 +343,4 @@ class User < ActiveRecord::Base
|
|||||||
receiver: self,
|
receiver: self,
|
||||||
attached_object: self
|
attached_object: self
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
class AdminPolicy < ApplicationPolicy
|
class AdminPolicy < ApplicationPolicy
|
||||||
def index?
|
def index?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class AgeRangePolicy < ApplicationPolicy
|
class AgeRangePolicy < ApplicationPolicy
|
||||||
%w(create update destroy show).each do |action|
|
%w(create update destroy show).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ class AuthProviderPolicy < ApplicationPolicy
|
|||||||
|
|
||||||
%w(index? show? create? update? destroy? mapping_fields?).each do |action|
|
%w(index? show? create? update? destroy? mapping_fields?).each do |action|
|
||||||
define_method action do
|
define_method action do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class AvailabilityPolicy < ApplicationPolicy
|
class AvailabilityPolicy < ApplicationPolicy
|
||||||
%w(index? show? create? update? destroy? reservations? export? lock?).each do |action|
|
%w(index? show? create? update? destroy? reservations? export? lock?).each do |action|
|
||||||
define_method action do
|
define_method action do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class CategoryPolicy < ApplicationPolicy
|
class CategoryPolicy < ApplicationPolicy
|
||||||
%w(create update destroy show).each do |action|
|
%w(create update destroy show).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class ComponentPolicy < ApplicationPolicy
|
class ComponentPolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class CouponPolicy < ApplicationPolicy
|
class CouponPolicy < ApplicationPolicy
|
||||||
%w(index show create update destroy send_to).each do |action|
|
%w(index show create update destroy send_to).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class CreditPolicy < ApplicationPolicy
|
class CreditPolicy < ApplicationPolicy
|
||||||
def index?
|
def index?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
class CustomAssetPolicy < ApplicationPolicy
|
class CustomAssetPolicy < ApplicationPolicy
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class EventPolicy < ApplicationPolicy
|
class EventPolicy < ApplicationPolicy
|
||||||
class Scope < Scope
|
class Scope < Scope
|
||||||
def resolve
|
def resolve
|
||||||
if user.nil? or (user and !user.is_admin?)
|
if user.nil? or (user and !user.admin?)
|
||||||
scope.includes(:event_image, :event_files, :availability, :category)
|
scope.includes(:event_image, :event_files, :availability, :category)
|
||||||
.where('availabilities.start_at >= ?', Time.now)
|
.where('availabilities.start_at >= ?', Time.now)
|
||||||
.order('availabilities.start_at ASC')
|
.order('availabilities.start_at ASC')
|
||||||
@ -14,7 +14,7 @@ class EventPolicy < ApplicationPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class EventThemePolicy < ApplicationPolicy
|
class EventThemePolicy < ApplicationPolicy
|
||||||
%w(create update destroy show).each do |action|
|
%w(create update destroy show).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class ExportPolicy < Struct.new(:user, :export)
|
class ExportPolicy < Struct.new(:user, :export)
|
||||||
%w(export_reservations export_members export_subscriptions export_availabilities download status).each do |action|
|
%w(export_reservations export_members export_subscriptions export_availabilities download status).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
class GroupPolicy < ApplicationPolicy
|
class GroupPolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
user.is_admin? and record.destroyable?
|
user.admin? and record.destroyable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
class InvoicePolicy < ApplicationPolicy
|
class InvoicePolicy < ApplicationPolicy
|
||||||
def index?
|
def index?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def download?
|
def download?
|
||||||
user.is_admin? or (record.user_id == user.id)
|
user.admin? or (record.user_id == user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def list?
|
def list?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class LicencePolicy < ApplicationPolicy
|
class LicencePolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
class MachinePolicy < ApplicationPolicy
|
class MachinePolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
user.is_admin? and record.destroyable?
|
user.admin? and record.destroyable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
class PartnerPlanPolicy < ApplicationPolicy
|
class PartnerPlanPolicy < ApplicationPolicy
|
||||||
def index?
|
def index?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
user.is_admin? and record.destroyable?
|
user.admin? and record.destroyable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
class PlanPolicy < ApplicationPolicy
|
class PlanPolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
user.is_admin? and record.destroyable?
|
user.admin? and record.destroyable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class PriceCategoryPolicy < ApplicationPolicy
|
class PriceCategoryPolicy < ApplicationPolicy
|
||||||
%w(show create update destroy).each do |action|
|
%w(show create update destroy).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
class PricePolicy < ApplicationPolicy
|
class PricePolicy < ApplicationPolicy
|
||||||
def index?
|
def index?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class PricingPolicy < ApplicationPolicy
|
class PricingPolicy < ApplicationPolicy
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,10 +15,10 @@ class ProjectPolicy < ApplicationPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin? or record.author == user or record.users.include?(user)
|
user.admin? or record.author == user or record.users.include?(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
user.is_admin? or record.author == user
|
user.admin? or record.author == user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class ReservationPolicy < ApplicationPolicy
|
class ReservationPolicy < ApplicationPolicy
|
||||||
def update?
|
def update?
|
||||||
user.is_admin? or record.user == user
|
user.admin? or record.user == user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class SettingPolicy < ApplicationPolicy
|
class SettingPolicy < ApplicationPolicy
|
||||||
%w(update).each do |action|
|
%w(update).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,11 +5,11 @@ class SlotPolicy < ApplicationPolicy
|
|||||||
enabled = (Setting.find_by( name: 'booking_move_enable').value == 'true')
|
enabled = (Setting.find_by( name: 'booking_move_enable').value == 'true')
|
||||||
|
|
||||||
# these condition does not apply to admins
|
# these condition does not apply to admins
|
||||||
user.is_admin? or
|
user.admin? or
|
||||||
(record.reservation.user == user and enabled and ((record.start_at - Time.now).to_i / 3600 >= delay))
|
(record.reservation.user == user and enabled and ((record.start_at - Time.now).to_i / 3600 >= delay))
|
||||||
end
|
end
|
||||||
|
|
||||||
def cancel?
|
def cancel?
|
||||||
user.is_admin? or record.reservation.user == user
|
user.admin? or record.reservation.user == user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
class SpacePolicy < ApplicationPolicy
|
class SpacePolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
user.is_admin? and record.destroyable?
|
user.admin? and record.destroyable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ class StatisticPolicy < ApplicationPolicy
|
|||||||
%w(index account event machine project subscription training user space scroll export_subscription export_machine
|
%w(index account event machine project subscription training user space scroll export_subscription export_machine
|
||||||
export_training export_event export_account export_project export_space export_global).each do |action|
|
export_training export_event export_account export_project export_space export_global).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
class SubscriptionPolicy < ApplicationPolicy
|
class SubscriptionPolicy < ApplicationPolicy
|
||||||
def show?
|
def show?
|
||||||
user.is_admin? or record.user_id == user.id
|
user.admin? or record.user_id == user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class TagPolicy < ApplicationPolicy
|
class TagPolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class ThemePolicy < ApplicationPolicy
|
class ThemePolicy < ApplicationPolicy
|
||||||
def create?
|
def create?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
|
@ -7,15 +7,15 @@ class TrainingPolicy < ApplicationPolicy
|
|||||||
|
|
||||||
%w(create update).each do |action|
|
%w(create update).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
user.is_admin? and record.destroyable?
|
user.admin? and record.destroyable?
|
||||||
end
|
end
|
||||||
|
|
||||||
def availabilities?
|
def availabilities?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class UserPolicy < ApplicationPolicy
|
class UserPolicy < ApplicationPolicy
|
||||||
class Scope < Scope
|
class Scope < Scope
|
||||||
def resolve
|
def resolve
|
||||||
if user.is_admin?
|
if user.admin?
|
||||||
scope.includes(:group, :training_credits, :machine_credits, :subscriptions => [:plan => [:credits]], :profile => [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").order('users.created_at desc')
|
scope.includes(:group, :training_credits, :machine_credits, :subscriptions => [:plan => [:credits]], :profile => [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").order('users.created_at desc')
|
||||||
else
|
else
|
||||||
scope.includes(:profile => [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").where(is_allow_contact: true).order('users.created_at desc')
|
scope.includes(:profile => [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").where(is_allow_contact: true).order('users.created_at desc')
|
||||||
@ -10,11 +10,11 @@ class UserPolicy < ApplicationPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show?
|
def show?
|
||||||
user.is_admin? or (record.is_allow_contact and record.is_member?) or (user.id == record.id)
|
user.admin? or (record.is_allow_contact and record.member?) or (user.id == record.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin? or (user.id == record.id)
|
user.admin? or (user.id == record.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
@ -27,7 +27,7 @@ class UserPolicy < ApplicationPolicy
|
|||||||
|
|
||||||
%w(list create mapping).each do |action|
|
%w(list create mapping).each do |action|
|
||||||
define_method "#{action}?" do
|
define_method "#{action}?" do
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class VersionPolicy < ApplicationPolicy
|
class VersionPolicy < ApplicationPolicy
|
||||||
def show?
|
def show?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
class WalletPolicy < ApplicationPolicy
|
class WalletPolicy < ApplicationPolicy
|
||||||
def by_user?
|
def by_user?
|
||||||
user.is_admin? or user == record.user
|
user.admin? or user == record.user
|
||||||
end
|
end
|
||||||
|
|
||||||
def transactions?
|
def transactions?
|
||||||
user.is_admin? or user == record.user
|
user.admin? or user == record.user
|
||||||
end
|
end
|
||||||
|
|
||||||
def credit?
|
def credit?
|
||||||
user.is_admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
user_is_admin = (current_user and current_user.is_admin?)
|
user_is_admin = (current_user and current_user.admin?)
|
||||||
|
|
||||||
json.array!(@age_ranges) do |ar|
|
json.array!(@age_ranges) do |ar|
|
||||||
json.extract! ar, :id, :name
|
json.extract! ar, :id, :name
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
user_is_admin = (current_user and current_user.is_admin?)
|
user_is_admin = (current_user and current_user.admin?)
|
||||||
|
|
||||||
json.array!(@categories) do |category|
|
json.array!(@categories) do |category|
|
||||||
json.extract! category, :id, :name
|
json.extract! category, :id, :name
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
user_is_admin = (current_user and current_user.is_admin?)
|
user_is_admin = (current_user and current_user.admin?)
|
||||||
|
|
||||||
json.array!(@event_themes) do |theme|
|
json.array!(@event_themes) do |theme|
|
||||||
json.extract! theme, :id, :name
|
json.extract! theme, :id, :name
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
user_is_admin = (current_user and current_user.is_admin?)
|
user_is_admin = (current_user and current_user.admin?)
|
||||||
max_members = @query.except(:offset, :limit, :order).count
|
max_members = @query.except(:offset, :limit, :order).count
|
||||||
|
|
||||||
json.array!(@members) do |member|
|
json.array!(@members) do |member|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
user_is_admin = (current_user and current_user.is_admin?)
|
user_is_admin = (current_user and current_user.admin?)
|
||||||
|
|
||||||
json.array!(@price_categories) do |category|
|
json.array!(@price_categories) do |category|
|
||||||
json.extract! category, :id, :name, :conditions
|
json.extract! category, :id, :name, :conditions
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
role = (current_user and current_user.is_admin?) ? 'admin' : 'user'
|
role = (current_user and current_user.admin?) ? 'admin' : 'user'
|
||||||
|
|
||||||
json.array!(@trainings) do |training|
|
json.array!(@trainings) do |training|
|
||||||
json.extract! training, :id, :name, :description, :machine_ids, :nb_total_places, :slug, :disabled
|
json.extract! training, :id, :name, :description, :machine_ids, :nb_total_places, :slug, :disabled
|
||||||
|
@ -4,7 +4,7 @@ class AvailabilitiesExportWorker
|
|||||||
def perform(export_id)
|
def perform(export_id)
|
||||||
export = Export.find(export_id)
|
export = Export.find(export_id)
|
||||||
|
|
||||||
unless export.user.is_admin?
|
unless export.user.admin?
|
||||||
raise SecurityError, 'Not allowed to export'
|
raise SecurityError, 'Not allowed to export'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ class StatisticsExportWorker
|
|||||||
def perform(export_id)
|
def perform(export_id)
|
||||||
export = Export.find(export_id)
|
export = Export.find(export_id)
|
||||||
|
|
||||||
unless export.user.is_admin?
|
unless export.user.admin?
|
||||||
raise SecurityError, 'Not allowed to export'
|
raise SecurityError, 'Not allowed to export'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ class UsersExportWorker
|
|||||||
def perform(export_id)
|
def perform(export_id)
|
||||||
export = Export.find(export_id)
|
export = Export.find(export_id)
|
||||||
|
|
||||||
unless export.user.is_admin?
|
unless export.user.admin?
|
||||||
raise SecurityError, 'Not allowed to export'
|
raise SecurityError, 'Not allowed to export'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
match '/project_collaborator/:valid_token', to: 'api/projects#collaborator_valid', via: :get
|
match '/project_collaborator/:valid_token', to: 'api/projects#collaborator_valid', via: :get
|
||||||
|
|
||||||
authenticate :user, lambda { |u| u.is_admin? } do
|
authenticate :user, lambda { |u| u.admin? } do
|
||||||
mount Sidekiq::Web => '/admin/sidekiq'
|
mount Sidekiq::Web => '/admin/sidekiq'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ namespace :fablab do
|
|||||||
task migrate_admins_group: :environment do
|
task migrate_admins_group: :environment do
|
||||||
admins = Group.find_by(slug: 'admins')
|
admins = Group.find_by(slug: 'admins')
|
||||||
User.all.each do |user|
|
User.all.each do |user|
|
||||||
if user.is_admin?
|
if user.admin?
|
||||||
user.group = admins
|
user.group = admins
|
||||||
user.save!
|
user.save!
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user