From c30ae8179ea79123f60cfc922a2ecbcc8d48b00a Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 22 Apr 2020 10:46:46 +0200 Subject: [PATCH] fix groups and tags in manager creation + helpers to get users w/ role partner|manager --- app/assets/javascripts/controllers/admin/members.js.erb | 2 +- app/controllers/api/users_controller.rb | 9 +++++---- app/models/user.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/controllers/admin/members.js.erb b/app/assets/javascripts/controllers/admin/members.js.erb index b7478619d..842fe97e0 100644 --- a/app/assets/javascripts/controllers/admin/members.js.erb +++ b/app/assets/javascripts/controllers/admin/members.js.erb @@ -1096,7 +1096,7 @@ Application.Controllers.controller('NewManagerController', ['$state', '$scope', }; // list of all groups - $scope.groups = groupsPromise; + $scope.groups = groupsPromise.filter(function (g) { return (g.slug !== 'admins') && !g.disabled; }); // list of all tags $scope.tags = tagsPromise; diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index 7d77ff160..aa7c68df2 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -49,10 +49,11 @@ class API::UsersController < API::ApiController def manager_params params.require(:manager).permit( - :username, :email, :group_id, :tag_ids, - profile_attributes: %i[first_name last_name phone], - invoicing_profile_attributes: [address_attributes: [:address]], - statistic_profile_attributes: %i[gender birthday] + :username, :email, :group_id, + tag_ids: [], + profile_attributes: %i[first_name last_name phone], + invoicing_profile_attributes: [address_attributes: [:address]], + statistic_profile_attributes: %i[gender birthday] ) end end diff --git a/app/models/user.rb b/app/models/user.rb index 9f580e3e1..e7be6e14d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -97,6 +97,14 @@ class User < ApplicationRecord User.with_role(:member) end + def self.partners + User.with_role(:partner) + end + + def self.managers + User.with_role(:manager) + end + def self.superadmin return unless Rails.application.secrets.superadmin_email.present?