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) %> +
  • + <%= link_to 'Personalization', settings_personalization_path, class: 'text-base hover:bg-base-300' %> +
  • + <% end %> <% if can?(:read, User) %>
  • <%= link_to 'Users', settings_users_path, class: 'text-base hover:bg-base-300' %>
  • <% end %> + <%= render 'shared/settings_nav_extra' %> <% if Docuseal.demo? || !Docuseal.multitenant? %> <% if can?(:read, AccessToken) %>
  • @@ -54,12 +60,6 @@
  • <% end %> <% end %> - <% if can?(:read, AccountConfig) %> -
  • - <%= link_to 'Personalization', settings_personalization_path, class: 'text-base hover:bg-base-300' %> -
  • - <% end %> - <%= render 'shared/settings_nav_extra' %> <% if !Docuseal.demo? && can?(:manage, EncryptedConfig) && (current_user != true_user || !current_account.testing?) %>
  • <%= link_to Docuseal.multitenant? ? console_redirect_index_path(redir: "#{Docuseal::CONSOLE_URL}/plans") : "#{Docuseal::CLOUD_URL}/sign_up?#{{ redir: "#{Docuseal::CONSOLE_URL}/on_premise" }.to_query}", class: 'text-base hover:bg-base-300', data: { prefetch: false } do %> diff --git a/db/migrate/20240428072623_add_archived_at_to_accounts.rb b/db/migrate/20240428072623_add_archived_at_to_accounts.rb new file mode 100644 index 00000000..5d07dcdd --- /dev/null +++ b/db/migrate/20240428072623_add_archived_at_to_accounts.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddArchivedAtToAccounts < ActiveRecord::Migration[7.1] + def change + add_column :accounts, :archived_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 6c663ed6..3559c9f4 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[7.1].define(version: 2024_04_16_170023) do +ActiveRecord::Schema[7.1].define(version: 2024_04_28_072623) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -52,6 +52,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_16_170023) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "uuid", null: false + t.datetime "archived_at" t.index ["uuid"], name: "index_accounts_on_uuid", unique: true end