diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5463f01f..d298012f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true class UsersController < ApplicationController - load_and_authorize_resource :user, only: %i[index edit new update destroy] + load_and_authorize_resource :user, only: %i[index edit update destroy] - before_action :build_user, only: :create - authorize_resource :user, only: :create + before_action :build_user, only: %i[new create] + authorize_resource :user, only: %i[new create] def index @users = @@ -14,7 +14,7 @@ class UsersController < ApplicationController @users.active end - @pagy, @users = pagy(@users.order(id: :desc)) + @pagy, @users = pagy(@users.where(account: current_account).order(id: :desc)) end def new; end @@ -81,6 +81,11 @@ class UsersController < ApplicationController end def user_params - params.require(:user).permit(:email, :first_name, :last_name, :password, :role, :archived_at) + if params.key?(:user) + params.require(:user).permit(:email, :first_name, :last_name, :password, + :role, :archived_at, :account_id) + else + {} + end end end diff --git a/app/models/account.rb b/app/models/account.rb index 8ea2d2be..929a37c6 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -4,13 +4,14 @@ # # Table name: accounts # -# id :bigint not null, primary key -# locale :string not null -# name :string not null -# timezone :string not null -# uuid :string not null -# created_at :datetime not null -# updated_at :datetime not null +# id :bigint not null, primary key +# archived_at :datetime +# locale :string not null +# name :string not null +# timezone :string not null +# uuid :string not null +# created_at :datetime not null +# updated_at :datetime not null # # Indexes # @@ -49,6 +50,8 @@ class Account < ApplicationRecord attribute :timezone, :string, default: 'UTC' attribute :locale, :string, default: 'en-US' + scope :active, -> { where(archived_at: nil) } + def testing? linked_account_account&.testing? end diff --git a/app/models/user.rb b/app/models/user.rb index 237ebc41..ff066cd9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -73,7 +73,7 @@ class User < ApplicationRecord end def active_for_authentication? - super && !archived_at? + super && !archived_at? && !account.archived_at? end def remember_me diff --git a/app/views/shared/_settings_nav.html.erb b/app/views/shared/_settings_nav.html.erb index 563f5f51..553b5eb2 100644 --- a/app/views/shared/_settings_nav.html.erb +++ b/app/views/shared/_settings_nav.html.erb @@ -37,11 +37,17 @@ <%= link_to 'E-Signature', settings_esign_path, class: 'text-base hover:bg-base-300' %> <% end %> + <% if can?(:read, AccountConfig) %> +