From 633a7f286ffa1237ef97c9c42562cad0e8513e4d Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 5 Sep 2024 15:40:30 +0200 Subject: [PATCH 1/6] Use new resource_table component for user list If the new component is available we use that for rendering the user list in the admin. --- app/models/alchemy/user.rb | 4 +++ .../admin/users/_resource_table.html.erb | 34 ++++++++++++++++++ app/views/alchemy/admin/users/_table.html.erb | 28 +++++++++++++++ app/views/alchemy/admin/users/index.html.erb | 35 ++++--------------- 4 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 app/views/alchemy/admin/users/_resource_table.html.erb create mode 100644 app/views/alchemy/admin/users/_table.html.erb diff --git a/app/models/alchemy/user.rb b/app/models/alchemy/user.rb index 24bab48..e5b7d46 100644 --- a/app/models/alchemy/user.rb +++ b/app/models/alchemy/user.rb @@ -47,6 +47,10 @@ def ransackable_attributes(_auth_object = nil) ] end + def ransortable_attributes(_auth_object = nil) + %w[last_sign_in_at] + end + alias_method :searchable_alchemy_resource_attributes, :ransackable_attributes def ransackable_associations(_auth_object = nil) diff --git a/app/views/alchemy/admin/users/_resource_table.html.erb b/app/views/alchemy/admin/users/_resource_table.html.erb new file mode 100644 index 0000000..3bbbdc5 --- /dev/null +++ b/app/views/alchemy/admin/users/_resource_table.html.erb @@ -0,0 +1,34 @@ +<%= render Alchemy::Admin::Resource::Table.new(@users, query: @query) do |table| %> + <% table.icon_column do |user| %> + <%= render_icon(:user, style: user.logged_in? ? "solid" : "regular") %> + <% end %> + <% table.column :login, sortable: true do |user| %> + <% if can?(:edit, user) %> + <%= link_to_dialog user.login, + alchemy.edit_admin_user_path(user), { + title: Alchemy.t(:edit_user), + overflow: true, + size: "430x560" + }, + title: Alchemy.t(:edit_user) %> + <% else %> + <%= user.login %> + <% end %> + <% end %> + <% table.column :firstname, class_name: "name", sortable: true %> + <% table.column :lastname, sortable: true %> + <% table.column :email, sortable: true %> + <% table.column :language do |user| %> + <%= Alchemy.t(user.language, scope: :translations, default: Alchemy.t(:unknown)) %> + <% end %> + <% table.column :last_sign_in_at, sortable: true do |user| %> + <%= user.last_sign_in_at.present? ? l(user.last_sign_in_at, format: :"alchemy.default") : Alchemy.t(:unknown) %> + <% end %> + <% table.column :role, header: Alchemy::User.human_attribute_name(:alchemy_roles) do |user| %> + <%= user.human_roles_string %> + <% end %> + <% table.delete_button tooltip: Alchemy.t(:delete_user), confirm_message: Alchemy.t(:confirm_to_delete_user) %> + <% table.edit_button tooltip: Alchemy.t(:edit_user), dialog_size: "430x560" %> +<% end %> + +<%= paginate @users, theme: "alchemy" %> diff --git a/app/views/alchemy/admin/users/_table.html.erb b/app/views/alchemy/admin/users/_table.html.erb new file mode 100644 index 0000000..31cad89 --- /dev/null +++ b/app/views/alchemy/admin/users/_table.html.erb @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + <%= render partial: "user", collection: @users %> + +
+ <%= sort_link @query, :firstname, hide_indicator: true %> + + <%= sort_link @query, :lastname, hide_indicator: true %> + <%= Alchemy::User.human_attribute_name('language') %> + <%= sort_link @query, :last_sign_in_at, hide_indicator: true %> + <%= Alchemy::User.human_attribute_name('roles') %>
diff --git a/app/views/alchemy/admin/users/index.html.erb b/app/views/alchemy/admin/users/index.html.erb index 2b550bb..38b16be 100644 --- a/app/views/alchemy/admin/users/index.html.erb +++ b/app/views/alchemy/admin/users/index.html.erb @@ -20,37 +20,14 @@ <% end %>
- <%= render "alchemy/admin/resources/table_header" %> <% if @users.any? %> + <%= render "alchemy/admin/resources/table_header" %> - - - - - - - - - - - - - - - - <%= render partial: 'alchemy/admin/users/user', collection: @users %> - -
- <%= sort_link @query, :firstname, hide_indicator: true %> - - <%= sort_link @query, :lastname, hide_indicator: true %> - <%= Alchemy::User.human_attribute_name('language') %> - <%= sort_link @query, :last_sign_in_at, hide_indicator: true %> - <%= Alchemy::User.human_attribute_name('roles') %>
+ <% if Alchemy::Admin.const_defined?(:Resource) %> + <%= render "resource_table" %> + <% else %> + <%= render "table" %> + <% end %> <%= paginate @users, theme: 'alchemy' %> From 2bcec1dbe0a0d32c7869438ade153abc86521ab8 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 5 Sep 2024 18:19:30 +0200 Subject: [PATCH 2/6] Update Brakeman For better view_component support --- .github/workflows/brakeman-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/brakeman-analysis.yml b/.github/workflows/brakeman-analysis.yml index 05f210b..be64d44 100644 --- a/.github/workflows/brakeman-analysis.yml +++ b/.github/workflows/brakeman-analysis.yml @@ -29,7 +29,7 @@ jobs: - name: Setup Brakeman env: - BRAKEMAN_VERSION: "6.1" # SARIF support is provided in Brakeman version 4.10+ + BRAKEMAN_VERSION: "6.2.1" # SARIF support is provided in Brakeman version 4.10+ run: | gem install brakeman --version $BRAKEMAN_VERSION From 08008c50be2d57eb0562bd598ca38dd9bcb22ad9 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 5 Sep 2024 18:20:39 +0200 Subject: [PATCH 3/6] Allow latest version of sprockets-rails again The PR has been merge --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index 1b474e8..bd465c1 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,6 @@ gem "rails", "~> #{rails_version}.0" gem "listen", "~> 3.8" gem "puma", "~> 6.0" -gem "sprockets-rails", "< 3.5.0" - # Specify your gem's dependencies in alchemy-solidus.gemspec gemspec From 59fca9d04120612798a9381c13241ad1aa1e962e Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 5 Sep 2024 18:30:17 +0200 Subject: [PATCH 4/6] Use latest GH actions --- .github/workflows/brakeman-analysis.yml | 4 ++-- .github/workflows/ci.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/brakeman-analysis.yml b/.github/workflows/brakeman-analysis.yml index be64d44..01b1a5b 100644 --- a/.github/workflows/brakeman-analysis.yml +++ b/.github/workflows/brakeman-analysis.yml @@ -19,7 +19,7 @@ jobs: steps: # Checkout the repository to the GitHub Actions runner - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Customize the ruby version depending on your needs - name: Set up Ruby @@ -41,6 +41,6 @@ jobs: # Upload the SARIF file generated in the previous step - name: Upload SARIF - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@v3 with: sarif_file: output.sarif.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6c41d6..d7bb45c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: MYSQL_ROOT_PASSWORD: password options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: @@ -95,7 +95,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Ruby and gems uses: ruby/setup-ruby@v1 with: From 3708143e757463a4a0a46937d7ba673cca553b79 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 5 Sep 2024 18:32:40 +0200 Subject: [PATCH 5/6] fix(CI): Use Ruby 3.1 to lint code --- .github/workflows/ci.yml | 2 +- .rubocop.yml | 2 +- .standard.yml | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7bb45c..70ded54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: - name: Install Ruby and gems uses: ruby/setup-ruby@v1 with: - ruby-version: "3.0" + ruby-version: "3.1" bundler-cache: true - name: Lint Ruby files run: bundle exec standardrb diff --git a/.rubocop.yml b/.rubocop.yml index 6faf5db..2db2740 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ require: standard AllCops: - TargetRubyVersion: 3.0 + TargetRubyVersion: 3.1 inherit_gem: standard: config/base.yml diff --git a/.standard.yml b/.standard.yml index 4bd8331..6ab3913 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1,3 +1,4 @@ parallel: true +ruby_version: 3.1 ignore: - "spec/dummy/**/*" From 2fa5ffa167ca6aeef2aa797006f47bed3d9917dd Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 5 Sep 2024 18:33:46 +0200 Subject: [PATCH 6/6] CI: Test for Alchemy 7.2 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70ded54..e394c36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,8 @@ jobs: alchemy_branch: - "7.0-stable" - "7.1-stable" + - "7.2-stable" ruby: - - "3.0" - "3.1" - "3.2" - "3.3"