From 744b811b62723b0d2374a2dddd9645aeebe6b858 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 25 Oct 2022 11:57:26 +0200 Subject: [PATCH] (feat) remove admins group: allow admins to reserve --- .rubocop.yml | 4 ++ app/controllers/api/admins_controller.rb | 2 +- app/controllers/api/groups_controller.rb | 2 +- .../components/group/change-group.tsx | 2 +- .../components/plans/plans-filter.tsx | 2 +- .../pricing/machines/machines-pricing.tsx | 2 +- .../pricing/spaces/spaces-pricing.tsx | 2 +- .../supporting-documents-types-list.tsx | 2 +- .../components/user/change-role-modal.tsx | 2 +- .../components/user/user-profile-form.tsx | 7 +--- .../javascript/controllers/admin/members.js | 11 ++++-- .../src/javascript/controllers/admin/plans.js | 2 +- .../javascript/controllers/admin/pricing.js | 4 +- .../src/javascript/controllers/application.js | 4 +- .../src/javascript/controllers/members.js | 2 +- app/frontend/src/javascript/models/group.ts | 3 +- app/frontend/src/javascript/router.js | 3 +- .../templates/admin/groups/index.html | 2 +- .../templates/shared/_admin_form.html | 13 +++++++ app/models/group.rb | 22 +++++------ app/models/plan.rb | 20 +++++----- app/models/subscription.rb | 18 ++++----- app/services/group_service.rb | 10 +---- app/services/members/members_service.rb | 14 +------ app/services/user_service.rb | 3 -- config/initializers/active_record_base.rb | 8 ++-- .../application_controller_renderer.rb | 8 ---- config/initializers/assets.rb | 39 ------------------- config/initializers/backtrace_silencers.rb | 7 ---- .../initializers/content_security_policy.rb | 10 ----- config/initializers/friendly_id.rb | 5 ++- config/initializers/session_store.rb | 17 ++++---- config/initializers/sidekiq.rb | 2 +- config/locales/en.yml | 1 - lib/tasks/fablab/setup.rake | 6 ++- 35 files changed, 94 insertions(+), 167 deletions(-) delete mode 100644 config/initializers/application_controller_renderer.rb delete mode 100644 config/initializers/assets.rb delete mode 100644 config/initializers/backtrace_silencers.rb diff --git a/.rubocop.yml b/.rubocop.yml index b99d77cae..c781751ab 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -34,3 +34,7 @@ Style/AndOr: EnforcedStyle: conditionals Style/FormatString: EnforcedStyle: sprintf +Rails/RedundantPresenceValidationOnBelongsTo: + Enabled: false +Rails/UnknownEnv: + Environments: development, test, staging, production diff --git a/app/controllers/api/admins_controller.rb b/app/controllers/api/admins_controller.rb index 651e457fd..31a5a285f 100644 --- a/app/controllers/api/admins_controller.rb +++ b/app/controllers/api/admins_controller.rb @@ -35,7 +35,7 @@ class API::AdminsController < API::ApiController def admin_params params.require(:admin).permit( - :username, :email, + :username, :email, :group_id, profile_attributes: %i[first_name last_name phone], invoicing_profile_attributes: [address_attributes: [:address]], statistic_profile_attributes: %i[gender birthday] diff --git a/app/controllers/api/groups_controller.rb b/app/controllers/api/groups_controller.rb index 03b2d1c3d..7276f54e7 100644 --- a/app/controllers/api/groups_controller.rb +++ b/app/controllers/api/groups_controller.rb @@ -6,7 +6,7 @@ class API::GroupsController < API::ApiController before_action :authenticate_user!, except: :index def index - @groups = GroupService.list(current_user, params) + @groups = GroupService.list(params) end def create diff --git a/app/frontend/src/javascript/components/group/change-group.tsx b/app/frontend/src/javascript/components/group/change-group.tsx index 653f65931..3b49732d7 100644 --- a/app/frontend/src/javascript/components/group/change-group.tsx +++ b/app/frontend/src/javascript/components/group/change-group.tsx @@ -43,7 +43,7 @@ export const ChangeGroup: React.FC = ({ user, onSuccess, onErr const { handleSubmit, control } = useForm(); useEffect(() => { - GroupAPI.index({ disabled: false, admins: user?.role === 'admin' }).then(setGroups).catch(onError); + GroupAPI.index({ disabled: false }).then(setGroups).catch(onError); MemberAPI.current().then(setOperator).catch(onError); SettingAPI.get('user_change_group').then((setting) => { setAllowedUserChangeGoup(setting.value === 'true'); diff --git a/app/frontend/src/javascript/components/plans/plans-filter.tsx b/app/frontend/src/javascript/components/plans/plans-filter.tsx index 8a280bd62..96e0582df 100644 --- a/app/frontend/src/javascript/components/plans/plans-filter.tsx +++ b/app/frontend/src/javascript/components/plans/plans-filter.tsx @@ -39,7 +39,7 @@ export const PlansFilter: React.FC = ({ user, groups, onGroupS * Convert all groups to the react-select format */ const buildGroupOptions = (): Array => { - return groups.filter(g => !g.disabled && g.slug !== 'admins').map(g => { + return groups.filter(g => !g.disabled).map(g => { return { value: g.id, label: g.name }; }); }; diff --git a/app/frontend/src/javascript/components/pricing/machines/machines-pricing.tsx b/app/frontend/src/javascript/components/pricing/machines/machines-pricing.tsx index 652a543c0..3df72caf9 100644 --- a/app/frontend/src/javascript/components/pricing/machines/machines-pricing.tsx +++ b/app/frontend/src/javascript/components/pricing/machines/machines-pricing.tsx @@ -41,7 +41,7 @@ export const MachinesPricing: React.FC = ({ onError, onSuc MachineAPI.index({ disabled: false }) .then(data => setMachines(data)) .catch(error => onError(error)); - GroupAPI.index({ disabled: false, admins: false }) + GroupAPI.index({ disabled: false }) .then(data => setGroups(data)) .catch(error => onError(error)); PriceAPI.index({ priceable_type: 'Machine', plan_id: null }) diff --git a/app/frontend/src/javascript/components/pricing/spaces/spaces-pricing.tsx b/app/frontend/src/javascript/components/pricing/spaces/spaces-pricing.tsx index 3bca4d6f6..2772cb9c7 100644 --- a/app/frontend/src/javascript/components/pricing/spaces/spaces-pricing.tsx +++ b/app/frontend/src/javascript/components/pricing/spaces/spaces-pricing.tsx @@ -38,7 +38,7 @@ export const SpacesPricing: React.FC = ({ onError, onSuccess SpaceAPI.index() .then(data => setSpaces(data)) .catch(error => onError(error)); - GroupAPI.index({ disabled: false, admins: false }) + GroupAPI.index({ disabled: false }) .then(data => setGroups(data)) .catch(error => onError(error)); PriceAPI.index({ priceable_type: 'Space', plan_id: null }) diff --git a/app/frontend/src/javascript/components/supporting-documents/supporting-documents-types-list.tsx b/app/frontend/src/javascript/components/supporting-documents/supporting-documents-types-list.tsx index 71030e138..02c5d23d7 100644 --- a/app/frontend/src/javascript/components/supporting-documents/supporting-documents-types-list.tsx +++ b/app/frontend/src/javascript/components/supporting-documents/supporting-documents-types-list.tsx @@ -45,7 +45,7 @@ const SupportingDocumentsTypesList: React.FC // get groups useEffect(() => { - GroupAPI.index({ disabled: false, admins: false }).then(data => { + GroupAPI.index({ disabled: false }).then(data => { setGroups(data); ProofOfIdentityTypeAPI.index().then(pData => { setSupportingDocumentsTypes(pData); diff --git a/app/frontend/src/javascript/components/user/change-role-modal.tsx b/app/frontend/src/javascript/components/user/change-role-modal.tsx index 3f844f643..c141795d1 100644 --- a/app/frontend/src/javascript/components/user/change-role-modal.tsx +++ b/app/frontend/src/javascript/components/user/change-role-modal.tsx @@ -45,7 +45,7 @@ export const ChangeRoleModal: React.FC = ({ isOpen, toggle const [selectedRole, setSelectedRole] = useState(user.role); useEffect(() => { - GroupAPI.index({ disabled: false, admins: false }).then(setGroups).catch(onError); + GroupAPI.index({ disabled: false }).then(setGroups).catch(onError); }, []); /** diff --git a/app/frontend/src/javascript/components/user/user-profile-form.tsx b/app/frontend/src/javascript/components/user/user-profile-form.tsx index f4aedbb08..f1457e7ab 100644 --- a/app/frontend/src/javascript/components/user/user-profile-form.tsx +++ b/app/frontend/src/javascript/components/user/user-profile-form.tsx @@ -77,7 +77,7 @@ export const UserProfileForm: React.FC = ({ action, size, setIsLocalDatabaseProvider(data.providable_type === 'DatabaseProvider'); }).catch(error => onError(error)); if (showGroupInput) { - GroupAPI.index({ disabled: false, admins: user.role === 'admin' }).then(data => { + GroupAPI.index({ disabled: false }).then(data => { setGroups(buildOptions(data)); }).catch(error => onError(error)); } @@ -155,11 +155,6 @@ export const UserProfileForm: React.FC = ({ action, size, * Check if the given field path should be disabled */ const isDisabled = function (id: string) { - // never allows admins to change their group - if (id === 'group_id' && user.role === 'admin') { - return true; - } - // if the current provider is the local database, then all fields are enabled if (isLocalDatabaseProvider) { return false; diff --git a/app/frontend/src/javascript/controllers/admin/members.js b/app/frontend/src/javascript/controllers/admin/members.js index ab1bdae22..52c03bed6 100644 --- a/app/frontend/src/javascript/controllers/admin/members.js +++ b/app/frontend/src/javascript/controllers/admin/members.js @@ -38,7 +38,7 @@ class MembersController { constructor ($scope, $state, Group, Training) { // Retrieve the profiles groups (e.g. students ...) - Group.query(function (groups) { $scope.groups = groups.filter(function (g) { return (g.slug !== 'admins') && !g.disabled; }); }); + Group.query(function (groups) { $scope.groups = groups.filter(function (g) { return !g.disabled; }); }); // Retrieve the list of available trainings Training.query().$promise.then(function (data) { @@ -1118,8 +1118,8 @@ Application.Controllers.controller('ImportMembersResultController', ['$scope', ' /** * Controller used in the admin creation page (admin view) */ -Application.Controllers.controller('NewAdminController', ['$state', '$scope', 'Admin', 'growl', '_t', 'settingsPromise', - function ($state, $scope, Admin, growl, _t, settingsPromise) { +Application.Controllers.controller('NewAdminController', ['$state', '$scope', 'Admin', 'growl', '_t', 'settingsPromise', 'groupsPromise', + function ($state, $scope, Admin, growl, _t, settingsPromise, groupsPromise) { // default admin profile let getGender; $scope.admin = { @@ -1145,6 +1145,9 @@ Application.Controllers.controller('NewAdminController', ['$state', '$scope', 'A // is the address required in _admin_form? $scope.addressRequired = (settingsPromise.address_required === 'true'); + // all available groups + $scope.groups = groupsPromise; + /** * Shows the birthday datepicker */ @@ -1208,7 +1211,7 @@ Application.Controllers.controller('NewManagerController', ['$state', '$scope', }; // list of all groups - $scope.groups = groupsPromise.filter(function (g) { return (g.slug !== 'admins') && !g.disabled; }); + $scope.groups = groupsPromise.filter(function (g) { return !g.disabled; }); // list of all tags $scope.tags = tagsPromise; diff --git a/app/frontend/src/javascript/controllers/admin/plans.js b/app/frontend/src/javascript/controllers/admin/plans.js index 5ac4f62aa..792ea12ac 100644 --- a/app/frontend/src/javascript/controllers/admin/plans.js +++ b/app/frontend/src/javascript/controllers/admin/plans.js @@ -27,7 +27,7 @@ class PlanController { // groups list $scope.groups = groups - .filter(function (g) { return (g.slug !== 'admins') && !g.disabled; }) + .filter(function (g) { return !g.disabled; }) .map(e => Object.assign({}, e, { category: 'app.shared.plan.groups', id: `${e.id}` })); $scope.groups.push({ id: 'all', name: 'app.shared.plan.transversal_all_groups', category: 'app.shared.plan.all' }); diff --git a/app/frontend/src/javascript/controllers/admin/pricing.js b/app/frontend/src/javascript/controllers/admin/pricing.js index da5afd614..4891e921a 100644 --- a/app/frontend/src/javascript/controllers/admin/pricing.js +++ b/app/frontend/src/javascript/controllers/admin/pricing.js @@ -30,8 +30,8 @@ Application.Controllers.controller('EditPricingController', ['$scope', '$state', $scope.enabledPlans = plans.filter(function (p) { return !p.disabled; }); // List of groups (eg. normal, student ...) - $scope.groups = groups.filter(function (g) { return g.slug !== 'admins'; }); - $scope.enabledGroups = groups.filter(function (g) { return (g.slug !== 'admins') && !g.disabled; }); + $scope.groups = groups; + $scope.enabledGroups = groups.filter(function (g) { return !g.disabled; }); // List of all plan-categories $scope.planCategories = planCategories; diff --git a/app/frontend/src/javascript/controllers/application.js b/app/frontend/src/javascript/controllers/application.js index 93d9e6c1e..4250bfb51 100644 --- a/app/frontend/src/javascript/controllers/application.js +++ b/app/frontend/src/javascript/controllers/application.js @@ -117,9 +117,7 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco // retrieve the groups (standard, student ...) Group.query(function (groups) { $scope.groups = groups; - $scope.enabledGroups = groups.filter(function (g) { - return (g.slug !== 'admins') && !g.disabled; - }); + $scope.enabledGroups = groups.filter(g => !g.disabled); }); // retrieve the CGU diff --git a/app/frontend/src/javascript/controllers/members.js b/app/frontend/src/javascript/controllers/members.js index 461892fb7..0f40d51f1 100644 --- a/app/frontend/src/javascript/controllers/members.js +++ b/app/frontend/src/javascript/controllers/members.js @@ -161,7 +161,7 @@ Application.Controllers.controller('EditProfileController', ['$scope', '$rootSco * Check if it is allowed the change the group of the current user */ $scope.isAllowedChangingGroup = function () { - return !$scope.user.subscribed_plan?.name && $scope.user.role !== 'admin'; + return !$scope.user.subscribed_plan?.name; }; /** diff --git a/app/frontend/src/javascript/models/group.ts b/app/frontend/src/javascript/models/group.ts index bf3eda384..26d19f43e 100644 --- a/app/frontend/src/javascript/models/group.ts +++ b/app/frontend/src/javascript/models/group.ts @@ -1,8 +1,7 @@ import { ApiFilter } from './api'; export interface GroupIndexFilter extends ApiFilter { - disabled?: boolean, - admins?: boolean, + disabled?: boolean } export interface Group { diff --git a/app/frontend/src/javascript/router.js b/app/frontend/src/javascript/router.js index 1ca1d2752..195726187 100644 --- a/app/frontend/src/javascript/router.js +++ b/app/frontend/src/javascript/router.js @@ -1001,7 +1001,8 @@ angular.module('application.router', ['ui.router']) } }, resolve: { - settingsPromise: ['Setting', function (Setting) { return Setting.query({ names: "['phone_required', 'address_required']" }).$promise; }] + settingsPromise: ['Setting', function (Setting) { return Setting.query({ names: "['phone_required', 'address_required']" }).$promise; }], + groupsPromise: ['Group', function (Group) { return Group.query({ disabled: false }).$promise; }] } }) .state('app.admin.managers_new', { diff --git a/app/frontend/templates/admin/groups/index.html b/app/frontend/templates/admin/groups/index.html index 6cb85780e..2bb4fa8aa 100644 --- a/app/frontend/templates/admin/groups/index.html +++ b/app/frontend/templates/admin/groups/index.html @@ -37,7 +37,7 @@ -
+
diff --git a/app/frontend/templates/shared/_admin_form.html b/app/frontend/templates/shared/_admin_form.html index 458a79a50..808db2c5c 100644 --- a/app/frontend/templates/shared/_admin_form.html +++ b/app/frontend/templates/shared/_admin_form.html @@ -119,6 +119,19 @@ ng-required="phoneRequired">
+ +
+
+ + +
+
diff --git a/app/models/group.rb b/app/models/group.rb index cd54e6312..278434ed4 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,17 +2,15 @@ # Group is way to bind users with prices. Different prices can be defined for each plan/reservable, for each group class Group < ApplicationRecord - has_many :plans - has_many :users - has_many :statistic_profiles + has_many :plans, dependent: :destroy + has_many :users, dependent: :nullify + has_many :statistic_profiles, dependent: :nullify has_many :trainings_pricings, dependent: :destroy - has_many :machines_prices, -> { where(priceable_type: 'Machine') }, class_name: 'Price', dependent: :destroy - has_many :spaces_prices, -> { where(priceable_type: 'Space') }, class_name: 'Price', dependent: :destroy + has_many :machines_prices, -> { where(priceable_type: 'Machine') }, class_name: 'Price', dependent: :destroy, inverse_of: :group + has_many :spaces_prices, -> { where(priceable_type: 'Space') }, class_name: 'Price', dependent: :destroy, inverse_of: :group has_many :proof_of_identity_types_groups, dependent: :destroy has_many :proof_of_identity_types, through: :proof_of_identity_types_groups - scope :all_except_admins, -> { where.not(slug: 'admins') } - extend FriendlyId friendly_id :name, use: :slugged @@ -41,26 +39,26 @@ class Group < ApplicationRecord end def create_trainings_pricings - Training.all.each do |training| + Training.find_each do |training| TrainingsPricing.create(group: self, training: training, amount: 0) end end def create_machines_prices - Machine.all.each do |machine| + Machine.find_each do |machine| Price.create(priceable: machine, group: self, amount: 0) end end def create_spaces_prices - Space.all.each do |space| + Space.find_each do |space| Price.create(priceable: space, group: self, amount: 0) end end def create_statistic_subtype user_index = StatisticIndex.find_by(es_type_key: 'user') - StatisticSubType.create!( statistic_types: user_index.statistic_types, key: slug, label: name) + StatisticSubType.create!(statistic_types: user_index.statistic_types, key: slug, label: name) end def update_statistic_subtype @@ -74,7 +72,7 @@ class Group < ApplicationRecord def disable_plans plans.each do |plan| - plan.update_attributes(disabled: disabled) + plan.update(disabled: disabled) end end end diff --git a/app/models/plan.rb b/app/models/plan.rb index 5a0150dd0..8e1c69d65 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -7,13 +7,13 @@ class Plan < ApplicationRecord belongs_to :plan_category has_many :credits, dependent: :destroy - has_many :training_credits, -> { where(creditable_type: 'Training') }, class_name: 'Credit' - has_many :machine_credits, -> { where(creditable_type: 'Machine') }, class_name: 'Credit' - has_many :space_credits, -> { where(creditable_type: 'Space') }, class_name: 'Credit' - has_many :subscriptions + has_many :training_credits, -> { where(creditable_type: 'Training') }, class_name: 'Credit', dependent: :destroy, inverse_of: :plan + has_many :machine_credits, -> { where(creditable_type: 'Machine') }, class_name: 'Credit', dependent: :destroy, inverse_of: :plan + has_many :space_credits, -> { where(creditable_type: 'Space') }, class_name: 'Credit', dependent: :destroy, inverse_of: :plan + has_many :subscriptions, dependent: :nullify has_one :plan_file, as: :viewable, dependent: :destroy has_many :prices, dependent: :destroy - has_one :payment_gateway_object, as: :item + has_one :payment_gateway_object, as: :item, dependent: :destroy extend FriendlyId friendly_id :base_name, use: :slugged @@ -37,7 +37,7 @@ class Plan < ApplicationRecord def self.create_for_all_groups(plan_params) plans = [] - Group.all_except_admins.each do |group| + Group.find_each do |group| plan = if plan_params[:type] == 'PartnerPlan' PartnerPlan.new(plan_params.except(:group_id, :type)) else @@ -59,14 +59,14 @@ class Plan < ApplicationRecord end def create_machines_prices - Machine.all.each do |machine| + Machine.all.find_each do |machine| default_price = Price.find_by(priceable: machine, plan: nil, group_id: group_id)&.amount || 0 Price.create(priceable: machine, plan: self, group_id: group_id, amount: default_price) end end def create_spaces_prices - Space.all.each do |space| + Space.all.find_each do |space| default_price = Price.find_by(priceable: space, plan: nil, group_id: group_id)&.amount || 0 Price.create(priceable: space, plan: self, group_id: group_id, amount: default_price) end @@ -123,12 +123,12 @@ class Plan < ApplicationRecord StatisticTypeSubType.create!(statistic_type: stat_type, statistic_sub_type: stat_subtype) else Rails.logger.error 'Unable to create the statistics association for the new plan. ' \ - 'Possible causes: the type or the subtype were not created successfully.' + 'Possible causes: the type or the subtype were not created successfully.' end end def set_name - update_columns(name: human_readable_name) + update_columns(name: human_readable_name) # rubocop:disable Rails/SkipsModelValidations end def update_gateway_product diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 5c0e40dd1..febf5323e 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -8,11 +8,11 @@ class Subscription < ApplicationRecord belongs_to :statistic_profile has_one :payment_schedule_object, as: :object, dependent: :destroy - has_one :payment_gateway_object, as: :item + has_one :payment_gateway_object, as: :item, dependent: :destroy has_many :invoice_items, as: :object, dependent: :destroy has_many :offer_days, dependent: :destroy - validates_presence_of :plan_id + validates :plan_id, presence: true validates_with SubscriptionGroupValidator # creation @@ -21,18 +21,20 @@ class Subscription < ApplicationRecord after_save :notify_admin_subscribed_plan after_save :notify_partner_subscribed_plan, if: :of_partner_plan? + delegate :user, to: :statistic_profile + def generate_and_save_invoice(operator_profile_id) generate_invoice(operator_profile_id).save end def expire(time) - if !expired? - update_columns(expiration_date: time, canceled_at: time) + if expired? + false + else + update_columns(expiration_date: time, canceled_at: time) # rubocop:disable Rails/SkipsModelValidations notify_admin_subscription_canceled notify_member_subscription_canceled true - else - false end end @@ -47,10 +49,6 @@ class Subscription < ApplicationRecord expiration_date end - def user - statistic_profile.user - end - def original_payment_schedule payment_schedule_object&.payment_schedule end diff --git a/app/services/group_service.rb b/app/services/group_service.rb index 3b0e6e482..c330edca8 100644 --- a/app/services/group_service.rb +++ b/app/services/group_service.rb @@ -2,20 +2,14 @@ # Provides methods for Groups class GroupService - def self.list(operator, filters = {}) - groups = if operator&.admin? - Group.where(nil) - else - Group.where.not(slug: 'admins') - end + def self.list(filters = {}) + groups = Group.where(nil) if filters[:disabled].present? state = filters[:disabled] == 'false' ? [nil, false] : true groups = groups.where(disabled: state) end - groups = groups.where.not(slug: 'admins') if filters[:admins] == 'false' - groups end end diff --git a/app/services/members/members_service.rb b/app/services/members/members_service.rb index 7e7bf8807..ba21f312e 100644 --- a/app/services/members/members_service.rb +++ b/app/services/members/members_service.rb @@ -15,12 +15,6 @@ class Members::MembersService return false end - if admin_group_change?(params) - # an admin cannot change his group - @member.errors.add(:group_id, I18n.t('members.admins_cant_change_group')) - return false - end - group_changed = user_group_change?(params) ex_group = @member.group @@ -130,9 +124,7 @@ class Members::MembersService @member.remove_role ex_role @member.add_role new_role - # if the new role is 'admin', then change the group to the admins group, otherwise to change to the provided group - group_id = new_role == 'admin' ? Group.find_by(slug: 'admins').id : new_group_id - @member.update(group_id: group_id) + @member.update(group_id: new_group_id) # notify NotificationCenter.call type: 'notify_user_role_update', @@ -176,10 +168,6 @@ class Members::MembersService params[:group_id] && @member.group_id != params[:group_id].to_i && !@member.subscribed_plan.nil? end - def admin_group_change?(params) - params[:group_id] && params[:group_id].to_i != Group.find_by(slug: 'admins').id && @member.admin? - end - def user_group_change?(params) @member.group_id && params[:group_id] && @member.group_id != params[:group_id].to_i end diff --git a/app/services/user_service.rb b/app/services/user_service.rb index 23973e80b..db40f94cf 100644 --- a/app/services/user_service.rb +++ b/app/services/user_service.rb @@ -36,9 +36,6 @@ class UserService admin = User.new(params.merge(password: generated_password)) admin.send :set_slug - # we associate the admin group to prevent linking any other 'normal' group (which won't be deletable afterwards) - admin.group = Group.find_by(slug: 'admins') - # if the authentication is made through an SSO, generate a migration token admin.generate_auth_migration_token unless AuthProvider.active.providable_type == DatabaseProvider.name diff --git a/config/initializers/active_record_base.rb b/config/initializers/active_record_base.rb index 4bb708204..333831e30 100644 --- a/config/initializers/active_record_base.rb +++ b/config/initializers/active_record_base.rb @@ -2,18 +2,16 @@ ActiveRecord::Base.class_eval do def dump_fixture - fixture_file = "#{Rails.root}/test/fixtures/#{self.class.table_name}.yml" + fixture_file = Rails.root.join("/test/fixtures/#{self.class.table_name}.yml") File.open(fixture_file, 'a') do |f| - f.puts({ "#{self.class.table_name.singularize}_#{id}" => attributes }. - to_yaml.sub!(/---\s?/, "\n")) + f.puts({ "#{self.class.table_name.singularize}_#{id}" => attributes }.to_yaml.sub!(/---\s?/, "\n")) end end def self.dump_fixtures - fixture_file = "#{Rails.root}/test/fixtures/#{table_name}.yml" + fixture_file = Rails.root.join("/test/fixtures/#{table_name}.yml") mode = (File.exist?(fixture_file) ? 'a' : 'w') File.open(fixture_file, mode) do |f| - if attribute_names.include?('id') all.each do |instance| f.puts({ "#{table_name.singularize}_#{instance.id}" => instance.attributes }.to_yaml.sub!(/---\s?/, "\n")) diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb deleted file mode 100644 index 89d2efab2..000000000 --- a/config/initializers/application_controller_renderer.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# ActiveSupport::Reloader.to_prepare do -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) -# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb deleted file mode 100644 index 913a6fe6b..000000000 --- a/config/initializers/assets.rb +++ /dev/null @@ -1,39 +0,0 @@ -# # frozen_string_literal: true -# -# # Be sure to restart your server when you modify this file. -# -# # Version of your assets, change this if you want to expire all your assets. -# Rails.application.config.assets.version = '1.0' -# -# # allow use rails helpers in angular templates -# Rails.application.config.assets.configure do |env| -# env.context_class.class_eval do -# include ActionView::Helpers -# include Rails.application.routes.url_helpers -# end -# end -# -# # Add additional assets to the asset load path. -# # Rails.application.config.assets.paths << Emoji.images_path -# # Add Yarn node_modules folder to the asset load path. -# Rails.application.config.assets.paths << Rails.root.join('node_modules') -# -# # Precompile additional assets. -# # application.js, application.css, and all non-JS/CSS in the app/assets -# # folder are already added. -# # Rails.application.config.assets.precompile += %w( admin.js admin.css ) -# -# Rails.application.config.assets.precompile += %w[ -# fontawesome-webfont.eot -# fontawesome-webfont.woff -# fontawesome-webfont.svg -# fontawesome-webfont.ttf -# ] -# Rails.application.config.assets.precompile += %w[app.printer.css] -# -# Rails.application.config.assets.precompile += %w[ -# angular-i18n/angular-locale_*.js -# moment/locale/*.js -# summernote/lang/*.js -# fullcalendar/dist/lang/*.js -# ] diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb deleted file mode 100644 index 59385cdf3..000000000 --- a/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } - -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index a92544780..e5bd6c449 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -8,16 +8,6 @@ Rails.application.config.content_security_policy do |policy| # # If you are using webpack-dev-server then specify webpack-dev-server host policy.connect_src :self, :https, :wss, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development? - -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https - -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" end # If you are using UJS then enable automatic nonce generation diff --git a/config/initializers/friendly_id.rb b/config/initializers/friendly_id.rb index caa04057c..43656468e 100644 --- a/config/initializers/friendly_id.rb +++ b/config/initializers/friendly_id.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # FriendlyId Global Configuration # # Use this to set up shared configuration options for your entire application. @@ -16,8 +18,7 @@ FriendlyId.defaults do |config| # undesirable to allow as slugs. Edit this list as needed for your app. config.use :reserved - config.reserved_words = %w(new edit index session login logout users - stylesheets assets javascripts images) + config.reserved_words = %w[new edit index session login logout users stylesheets assets javascripts images] # ## Friendly Finders # diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index a86375742..6b832c4b0 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -2,14 +2,15 @@ # Be sure to restart your server when you modify this file. -redis_host = ENV['REDIS_HOST'] || 'localhost' +redis_host = ENV.fetch('REDIS_HOST', 'localhost') Rails.application.config.session_store :redis_session_store, - redis: { - expire_after: 14.days, # cookie expiration - ttl: 14.days, # Redis expiration, defaults to 'expire_after' - key_prefix: 'fabmanager:session:', - url: "redis://#{redis_host}:6379", - }, + redis: { + expire_after: 14.days, # cookie expiration + ttl: 14.days, # Redis expiration, defaults to 'expire_after' + key_prefix: 'fabmanager:session:', + url: "redis://#{redis_host}:6379" + }, key: '_Fab-manager_session', - secure: (Rails.env.production? || Rails.env.staging?) && !Rails.application.secrets.allow_insecure_http + secure: (Rails.env.production? || Rails.env.staging?) && + !Rails.application.secrets.allow_insecure_http diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 4dca7c99d..517b06e02 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -5,7 +5,7 @@ require 'sidekiq-scheduler' require 'sidekiq/middleware/i18n' require 'sidekiq/server_locale' -redis_host = ENV['REDIS_HOST'] || 'localhost' +redis_host = ENV.fetch('REDIS_HOST', 'localhost') redis_url = "redis://#{redis_host}:6379" Sidekiq.configure_server do |config| diff --git a/config/locales/en.yml b/config/locales/en.yml index 6756c46d7..d98398690 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -57,7 +57,6 @@ en: #members management members: unable_to_change_the_group_while_a_subscription_is_running: "Unable to change the group while a subscription is running" - admins_cant_change_group: "Unable to remove an administrator from his dedicated group" please_input_the_authentication_code_sent_to_the_address: "Please input the authentication code sent to the e-mail address %{EMAIL}" your_authentication_code_is_not_valid: "Your authentication code is not valid." current_authentication_method_no_code: "The current authentication method does not require any migration code" diff --git a/lib/tasks/fablab/setup.rake b/lib/tasks/fablab/setup.rake index 96889de16..52aa5f89d 100644 --- a/lib/tasks/fablab/setup.rake +++ b/lib/tasks/fablab/setup.rake @@ -12,7 +12,9 @@ namespace :fablab do desc 'add missing VAT rate to history' task :add_vat_rate, %i[rate date] => :environment do |_task, args| - raise 'Missing argument. Usage exemple: rails fablab:setup:add_vat_rate[20,2014-01-01]. Use 0 to disable' unless args.rate && args.date + unless args.rate && args.date + raise 'Missing argument. Usage exemple: rails fablab:setup:add_vat_rate[20,2014-01-01]. Use 0 to disable' + end if args.rate == '0' setting = Setting.find_by(name: 'invoice_VAT-active') @@ -116,6 +118,8 @@ namespace :fablab do admin.update(group_id: select_group(groups)) PaymentGatewayService.new.create_user(admin.id) end + print "\e[91m::\e[0m \e[1mRemoving the 'admins' group...\e[0m\n" + Group.find_by(slug: 'admins').destroy print "\e[32m✅\e[0m \e[1mDone\e[0m\n" end