diff --git a/app/controllers/admin/m_odr_reps_controller.rb b/app/controllers/admin/m_odr_reps_controller.rb index 7f616e3..9de5874 100644 --- a/app/controllers/admin/m_odr_reps_controller.rb +++ b/app/controllers/admin/m_odr_reps_controller.rb @@ -14,6 +14,11 @@ class Admin::MOdrRepsController < ApplicationController @m_odr_reps = MOdrRep.includes(:particulars) + if !current_admin.has_permission?("odr_rep.view") + @m_odr_reps = @m_odr_reps.joins(:m_odr).where(:m_odrs => {:p_customer_id => current_admin.p_customers.ids}) + + end + if params[:search][:state].to_s != "" diff --git a/app/models/admin.rb b/app/models/admin.rb index c3e9e1d..46ad964 100644 --- a/app/models/admin.rb +++ b/app/models/admin.rb @@ -6,6 +6,8 @@ class Admin < ApplicationRecord has_many :timer_watchers has_many :admin_preferences + has_many :admin_p_customers + has_many :p_customers, :through => :admin_p_customers has_secure_password @@ -59,11 +61,14 @@ class Admin < ApplicationRecord has_many :admin_permissions, :through => :admin_roles - def has_permission?(permission) + def has_permission?(permission_slug) + permission = AdminPermission.where(:slug => permission_slug).first + permission = AdminPermission.create(:slug => permission_slug) if !permission + if self.super_admin true else - permission = AdminPermission.where("code = ? or slug = ?",permission, permission).first + if permission if self.admin_permissions.include?(permission) @@ -75,7 +80,6 @@ class Admin < ApplicationRecord false end - end end diff --git a/app/models/admin_p_customer.rb b/app/models/admin_p_customer.rb new file mode 100644 index 0000000..e450ca8 --- /dev/null +++ b/app/models/admin_p_customer.rb @@ -0,0 +1,4 @@ +class AdminPCustomer < ApplicationRecord + belongs_to :admin + belongs_to :p_customer +end diff --git a/app/models/admin_permission.rb b/app/models/admin_permission.rb index fad7e51..62a2507 100644 --- a/app/models/admin_permission.rb +++ b/app/models/admin_permission.rb @@ -1,6 +1,6 @@ class AdminPermission < ApplicationRecord def member_label - self.code.to_s+" "+self.name + self.slug.to_s+" "+self.name.to_s end end diff --git a/app/models/m_odr.rb b/app/models/m_odr.rb index 1818de9..0949ed3 100644 --- a/app/models/m_odr.rb +++ b/app/models/m_odr.rb @@ -49,7 +49,7 @@ class MOdr < ApplicationRecord has_many :m_odr_reps, :dependent => :destroy - + has_many :m_odr_coupons diff --git a/app/models/m_odr_coupon.rb b/app/models/m_odr_coupon.rb new file mode 100644 index 0000000..07a8c34 --- /dev/null +++ b/app/models/m_odr_coupon.rb @@ -0,0 +1,3 @@ +class MOdrCoupon < ApplicationRecord + belongs_to :m_odr +end diff --git a/app/models/m_odr_rep.rb b/app/models/m_odr_rep.rb index 84bfec1..05ddda8 100644 --- a/app/models/m_odr_rep.rb +++ b/app/models/m_odr_rep.rb @@ -104,6 +104,15 @@ file_admin_ok remise particular_civilite particular_name particular_firstname pa end before_validation do + + if self.m_odr.reduc_code_needed and self.m_odr.m_odr_coupons.count > 0 and !self.m_odr.m_odr_coupons.where("name LIKE ?", self.reduc_code).first + + errors.add(:reduc_code, 'doit être différent de la page actuelle') + + + end + + self.particular = self.particulars.first if !self.state diff --git a/app/views/admin/admin_spaces/_stocks.html.haml b/app/views/admin/admin_spaces/_stocks.html.haml index ea8d178..90aae40 100644 --- a/app/views/admin/admin_spaces/_stocks.html.haml +++ b/app/views/admin/admin_spaces/_stocks.html.haml @@ -3,6 +3,6 @@ %li= link_to "Participations ODR", admin_m_odr_reps_path - -%li= link_to "ODR", admin_m_odrs_path -%li= link_to "Historique mail", admin_mail_hists_path +-if current_admin.has_permission?("odr.view") + %li= link_to "ODR", admin_m_odrs_path + %li= link_to "Historique mail", admin_mail_hists_path diff --git a/app/views/admin/admins/_form.html.haml b/app/views/admin/admins/_form.html.haml index b54ad16..b2a6e0d 100644 --- a/app/views/admin/admins/_form.html.haml +++ b/app/views/admin/admins/_form.html.haml @@ -35,6 +35,9 @@ =f.input :super_admin, :label => "Super admin ?" =f.input :admin_roles, :label => "Rôles :", :collection => AdminRole.all, :as => :check_boxes + + + =f.input :p_customers, :label => "Vue autorisée pour les clinets suivant :", :collection => PCustomer.all, :as => :check_boxes .actions= f.submit "Sauvegarder", :class => "btn btn-primary" diff --git a/app/views/admin/m_odr_reps/_m_odr_rep.html.haml b/app/views/admin/m_odr_reps/_m_odr_rep.html.haml index 899d3d6..1b26cfe 100644 --- a/app/views/admin/m_odr_reps/_m_odr_rep.html.haml +++ b/app/views/admin/m_odr_reps/_m_odr_rep.html.haml @@ -21,9 +21,11 @@ -tr[:actions] = capture do %td.actions - = link_to i(:"trash-o"), [:admin, m_odr_rep], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true - = link_to i(:pencil), edit_admin_m_odr_rep_path(m_odr_rep), :remote => true - = link_to i(:eye), admin_m_odr_rep_path(m_odr_rep) + -if current_admin.has_permission?("odr_rep.delete") + = link_to i(:"trash-o"), [:admin, m_odr_rep], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + -if current_admin.has_permission?("odr_rep.update") + = link_to i(:pencil), edit_admin_m_odr_rep_path(m_odr_rep), :remote => true + = link_to i(:eye), admin_m_odr_rep_path(m_odr_rep) diff --git a/app/views/admin/m_odr_reps/index.html.haml b/app/views/admin/m_odr_reps/index.html.haml index 194565e..d4fde13 100644 --- a/app/views/admin/m_odr_reps/index.html.haml +++ b/app/views/admin/m_odr_reps/index.html.haml @@ -1,5 +1,6 @@ .qi_header - .right= link_to 'Ajouter ', new_admin_m_odr_rep_path(), :class => "btn btn-primary", :remote => true + -if current_admin.has_permission?("odr_rep.create") + .right= link_to 'Ajouter ', new_admin_m_odr_rep_path(), :class => "btn btn-primary", :remote => true %h1 ODR %span @@ -20,7 +21,15 @@ %td Opération : - =select_tag "search[m_odr_id]", options_for_select([["",""]]+MOdr.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:m_odr_id]) + + -if !current_admin.has_permission?("odr_rep.view") + -m_odrs = MOdr.where(:p_customer_id => current_admin.p_customers.ids) + -else + -m_odrs = MOdr + + + + =select_tag "search[m_odr_id]", options_for_select([["",""]]+m_odrs.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:m_odr_id]) %td=text_field_tag :name, params[:name],:class => "form-control", :placeholder => "Nom" diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 0cdd237..1af5610 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -31,17 +31,19 @@ -if true - .element - =link_to admin_p_customers_path do - .cat#big_cat_clients - =ic :"address-book-o" - Clients + -if current_admin.has_permission?("customer.view") + .element + =link_to admin_p_customers_path do + .cat#big_cat_clients + =ic :"address-book-o" + Clients - .element - =link_to admin_m_odr_reps_path do - .cat#big_cat_stocks - =ic :"cubes" - Opérations ODR + -if current_admin.has_permission?("odr_rep.view_for_my") or current_admin.has_permission?("odr_rep.view") + .element + =link_to admin_m_odr_reps_path do + .cat#big_cat_stocks + =ic :"cubes" + Opérations ODR @@ -58,18 +60,19 @@ =ic :"file-text-o" Documents - - .element - =link_to admin_m_odr_virements_path do - .cat#big_cat_payments - =ic :"eur" - Virements + -if current_admin.has_permission?("virements.view") + .element + =link_to admin_m_odr_virements_path do + .cat#big_cat_payments + =ic :"eur" + Virements - .element - =link_to admin_file_tunels_path do - .cat#big_cat_tournees - =ic :"lock" - Tunnels fichier sécurisés + -if current_admin.has_permission?("file_tunels.view") + .element + =link_to admin_file_tunels_path do + .cat#big_cat_tournees + =ic :"lock" + Tunnels fichier sécurisés -if false diff --git a/config/environments/production.rb b/config/environments/production.rb index de50875..889d923 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -115,15 +115,15 @@ Rails.application.configure do config.action_mailer.default_url_options = { :host => HOSTNAME } - config.action_mailer.delivery_method = :mailjet + #config.action_mailer.delivery_method = :mailjet - #config.action_mailer.delivery_method = :smtp - #config.action_mailer.smtp_settings = { - # :address => "localhost", - # :port => 25, - # :openssl_verify_mode => 'none' - #} + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + :address => "localhost", + :port => 25, + :openssl_verify_mode => 'none' + } Rails.application.routes.default_url_options = config.action_mailer.default_url_options = { :host => HOSTNAME, :protocol => 'https' } diff --git a/db/migrate/20200401115523_create_admin_p_customers.rb b/db/migrate/20200401115523_create_admin_p_customers.rb new file mode 100644 index 0000000..117712e --- /dev/null +++ b/db/migrate/20200401115523_create_admin_p_customers.rb @@ -0,0 +1,10 @@ +class CreateAdminPCustomers < ActiveRecord::Migration[6.0] + def change + create_table :admin_p_customers do |t| + t.references :admin, foreign_key: true + t.references :p_customer, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20200401121041_create_m_odr_coupons.rb b/db/migrate/20200401121041_create_m_odr_coupons.rb new file mode 100644 index 0000000..2d3e31f --- /dev/null +++ b/db/migrate/20200401121041_create_m_odr_coupons.rb @@ -0,0 +1,10 @@ +class CreateMOdrCoupons < ActiveRecord::Migration[6.0] + def change + create_table :m_odr_coupons do |t| + t.string :name + t.references :m_odr, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d810637..06615c6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_03_09_142522) do +ActiveRecord::Schema.define(version: 2020_04_01_115523) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -29,6 +29,15 @@ ActiveRecord::Schema.define(version: 2020_03_09_142522) do t.index ["admin_role_id"], name: "index_admin_admin_roles_on_admin_role_id" end + create_table "admin_p_customers", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.bigint "admin_id" + t.bigint "p_customer_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["admin_id"], name: "index_admin_p_customers_on_admin_id" + t.index ["p_customer_id"], name: "index_admin_p_customers_on_p_customer_id" + end + create_table "admin_permission_admin_roles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.bigint "admin_permission_id" t.bigint "admin_role_id" @@ -634,7 +643,7 @@ ActiveRecord::Schema.define(version: 2020_03_09_142522) do t.index ["m_odr_id"], name: "index_m_odr_places_on_m_odr_id" end - create_table "m_odr_product_cats", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + create_table "m_odr_product_cats", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t| t.bigint "m_odr_id" t.string "name" t.datetime "created_at", precision: 6, null: false @@ -2560,6 +2569,8 @@ ActiveRecord::Schema.define(version: 2020_03_09_142522) do t.datetime "updated_at", precision: 6, null: false end + add_foreign_key "admin_p_customers", "admins" + add_foreign_key "admin_p_customers", "p_customers" add_foreign_key "admin_preferences", "admins" add_foreign_key "file_tunel_downloads", "file_tunel_sends" add_foreign_key "file_tunel_downloads", "file_tunels" diff --git a/public/uploads/tmp/1583668901-949748450899485-0001-2599/Capture_d_écran_2020-03-08_à_13.00.45.png b/public/uploads/tmp/1583668901-949748450899485-0001-2599/Capture_d_écran_2020-03-08_à_13.00.45.png new file mode 100644 index 0000000..da84bc0 Binary files /dev/null and b/public/uploads/tmp/1583668901-949748450899485-0001-2599/Capture_d_écran_2020-03-08_à_13.00.45.png differ diff --git a/test/fixtures/admin_p_customers.yml b/test/fixtures/admin_p_customers.yml new file mode 100644 index 0000000..00bdb5b --- /dev/null +++ b/test/fixtures/admin_p_customers.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + admin: one + p_customer: one + +two: + admin: two + p_customer: two diff --git a/test/fixtures/m_odr_coupons.yml b/test/fixtures/m_odr_coupons.yml new file mode 100644 index 0000000..a2eff1d --- /dev/null +++ b/test/fixtures/m_odr_coupons.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + m_odr: one + +two: + name: MyString + m_odr: two diff --git a/test/models/admin_p_customer_test.rb b/test/models/admin_p_customer_test.rb new file mode 100644 index 0000000..a6324f5 --- /dev/null +++ b/test/models/admin_p_customer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class AdminPCustomerTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/m_odr_coupon_test.rb b/test/models/m_odr_coupon_test.rb new file mode 100644 index 0000000..a6dbfca --- /dev/null +++ b/test/models/m_odr_coupon_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MOdrCouponTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end