From 01232aed5a44374bedece62efa86dbd89c490856 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Sun, 18 May 2025 12:13:23 +0300 Subject: [PATCH] add account access --- app/controllers/users_controller.rb | 2 +- app/models/account.rb | 1 + app/models/account_access.rb | 24 +++++++++++++++++++ app/views/templates_dashboard/index.html.erb | 2 +- app/views/users/index.html.erb | 4 ++-- config/locales/i18n.yml | 11 +++++++++ db/migrate/20250518070555_account_accesses.rb | 14 +++++++++++ db/schema.rb | 11 ++++++++- 8 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 app/models/account_access.rb create mode 100644 db/migrate/20250518070555_account_accesses.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 47a88e05..9771fc4e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,7 +16,7 @@ class UsersController < ApplicationController @users.active.where.not(role: 'integration') end - @pagy, @users = pagy(@users.where(account: current_account).order(id: :desc)) + @pagy, @users = pagy(@users.preload(account: :account_accesses).where(account: current_account).order(id: :desc)) end def new; end diff --git a/app/models/account.rb b/app/models/account.rb index 6ad1071e..6265734d 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -33,6 +33,7 @@ class Account < ApplicationRecord has_many :account_linked_accounts, dependent: :destroy has_many :email_events, dependent: :destroy has_many :webhook_urls, dependent: :destroy + has_many :account_accesses, dependent: :destroy has_many :account_testing_accounts, -> { testing }, dependent: :destroy, class_name: 'AccountLinkedAccount', inverse_of: :account diff --git a/app/models/account_access.rb b/app/models/account_access.rb new file mode 100644 index 00000000..162c3703 --- /dev/null +++ b/app/models/account_access.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: account_accesses +# +# id :bigint not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# account_id :bigint not null +# user_id :bigint not null +# +# Indexes +# +# index_account_accesses_on_account_id_and_user_id (account_id,user_id) UNIQUE +# +# Foreign Keys +# +# fk_rails_... (account_id => accounts.id) +# +class AccountAccess < ApplicationRecord + belongs_to :account + belongs_to :user +end diff --git a/app/views/templates_dashboard/index.html.erb b/app/views/templates_dashboard/index.html.erb index 1fd59e73..bcd85b01 100644 --- a/app/views/templates_dashboard/index.html.erb +++ b/app/views/templates_dashboard/index.html.erb @@ -56,7 +56,7 @@ <% if @templates.present? %>
<%= render partial: 'templates/template', collection: @templates %> - <% if show_dropzone && current_user.created_at > 2.weeks.ago || params[:tour] == 'true' %> + <% if show_dropzone && (current_user.created_at > 2.weeks.ago || params[:tour] == 'true') && current_user == true_user %> <% user_config = current_user.user_configs.find_or_initialize_by(key: UserConfig::SHOW_APP_TOUR) %> <% if user_config.new_record? || user_config.value || params[:tour] == 'true' %>