panda-core 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/builders/panda/core/form_builder.rb +163 -11
  3. data/app/components/panda/core/admin/button_component.rb +27 -12
  4. data/app/components/panda/core/admin/container_component.rb +13 -1
  5. data/app/components/panda/core/admin/heading_component.rb +22 -14
  6. data/app/components/panda/core/admin/slideover_component.rb +52 -22
  7. data/app/controllers/panda/core/admin/my_profile_controller.rb +8 -1
  8. data/app/helpers/panda/core/asset_helper.rb +2 -0
  9. data/app/javascript/panda/core/controllers/image_cropper_controller.js +158 -0
  10. data/app/javascript/panda/core/controllers/index.js +6 -0
  11. data/app/javascript/panda/core/controllers/navigation_toggle_controller.js +60 -0
  12. data/app/models/panda/core/user.rb +13 -2
  13. data/app/services/panda/core/attach_avatar_service.rb +4 -0
  14. data/app/views/layouts/panda/core/admin.html.erb +39 -14
  15. data/app/views/panda/core/admin/dashboard/_default_content.html.erb +1 -1
  16. data/app/views/panda/core/admin/dashboard/show.html.erb +3 -3
  17. data/app/views/panda/core/admin/sessions/new.html.erb +1 -1
  18. data/app/views/panda/core/admin/shared/_breadcrumbs.html.erb +14 -24
  19. data/app/views/panda/core/admin/shared/_sidebar.html.erb +61 -11
  20. data/app/views/panda/core/admin/shared/_slideover.html.erb +1 -1
  21. data/config/importmap.rb +5 -0
  22. data/config/routes.rb +1 -1
  23. data/lib/panda/core/asset_loader.rb +5 -2
  24. data/lib/panda/core/engine.rb +26 -25
  25. data/lib/panda/core/oauth_providers.rb +3 -3
  26. data/lib/panda/core/version.rb +1 -1
  27. metadata +3 -69
  28. data/lib/generators/panda/core/authentication/templates/reek_spec.rb +0 -43
  29. data/lib/generators/panda/core/dev_tools/USAGE +0 -24
  30. data/lib/generators/panda/core/dev_tools/templates/lefthook.yml +0 -13
  31. data/lib/generators/panda/core/dev_tools/templates/spec_support_panda_core_helpers.rb +0 -18
  32. data/lib/generators/panda/core/dev_tools_generator.rb +0 -143
  33. data/lib/generators/panda/core/install_generator.rb +0 -41
  34. data/lib/generators/panda/core/templates/README +0 -25
  35. data/lib/generators/panda/core/templates/initializer.rb +0 -44
  36. data/lib/generators/panda/core/templates_generator.rb +0 -27
  37. data/lib/panda/core/testing/capybara_config.rb +0 -70
  38. data/lib/panda/core/testing/omniauth_helpers.rb +0 -52
  39. data/lib/panda/core/testing/rspec_config.rb +0 -72
@@ -5,21 +5,21 @@ module Panda
5
5
  providers = []
6
6
 
7
7
  begin
8
- require "omniauth-github"
8
+ require "omniauth/strategies/github"
9
9
  providers << :github
10
10
  rescue LoadError
11
11
  # GitHub OAuth functionality not available
12
12
  end
13
13
 
14
14
  begin
15
- require "omniauth-google-oauth2"
15
+ require "omniauth/strategies/google_oauth2"
16
16
  providers << :google_oauth2
17
17
  rescue LoadError
18
18
  # Google OAuth functionality not available
19
19
  end
20
20
 
21
21
  begin
22
- require "omniauth-microsoft_graph"
22
+ require "omniauth/strategies/microsoft_graph"
23
23
  providers << :microsoft_graph
24
24
  rescue LoadError
25
25
  # Microsoft OAuth functionality not available
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Panda
4
4
  module Core
5
- VERSION = "0.6.0"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Otaina Limited
@@ -52,48 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: omniauth-google-oauth2
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: omniauth-github
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: omniauth-microsoft_graph
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
55
  - !ruby/object:Gem::Dependency
98
56
  name: propshaft
99
57
  requirement: !ruby/object:Gem::Requirement
@@ -150,20 +108,6 @@ dependencies:
150
108
  - - ">="
151
109
  - !ruby/object:Gem::Version
152
110
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: view_component
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :runtime
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
111
  - !ruby/object:Gem::Dependency
168
112
  name: phlex
169
113
  requirement: !ruby/object:Gem::Requirement
@@ -477,7 +421,9 @@ files:
477
421
  - app/helpers/panda/core/sessions_helper.rb
478
422
  - app/javascript/panda/core/application.js
479
423
  - app/javascript/panda/core/controllers/alert_controller.js
424
+ - app/javascript/panda/core/controllers/image_cropper_controller.js
480
425
  - app/javascript/panda/core/controllers/index.js
426
+ - app/javascript/panda/core/controllers/navigation_toggle_controller.js
481
427
  - app/javascript/panda/core/controllers/theme_form_controller.js
482
428
  - app/javascript/panda/core/controllers/toggle_controller.js
483
429
  - app/javascript/panda/core/tailwindcss-stimulus-components.js
@@ -508,15 +454,6 @@ files:
508
454
  - db/migrate/20250809000001_create_panda_core_users.rb
509
455
  - db/migrate/20250810120000_add_current_theme_to_panda_core_users.rb
510
456
  - db/migrate/20250811120000_add_oauth_avatar_url_to_panda_core_users.rb
511
- - lib/generators/panda/core/authentication/templates/reek_spec.rb
512
- - lib/generators/panda/core/dev_tools/USAGE
513
- - lib/generators/panda/core/dev_tools/templates/lefthook.yml
514
- - lib/generators/panda/core/dev_tools/templates/spec_support_panda_core_helpers.rb
515
- - lib/generators/panda/core/dev_tools_generator.rb
516
- - lib/generators/panda/core/install_generator.rb
517
- - lib/generators/panda/core/templates/README
518
- - lib/generators/panda/core/templates/initializer.rb
519
- - lib/generators/panda/core/templates_generator.rb
520
457
  - lib/panda/core.rb
521
458
  - lib/panda/core/asset_loader.rb
522
459
  - lib/panda/core/authentication.rb
@@ -533,9 +470,6 @@ files:
533
470
  - lib/panda/core/services/base_service.rb
534
471
  - lib/panda/core/sluggable.rb
535
472
  - lib/panda/core/subscribers/authentication_subscriber.rb
536
- - lib/panda/core/testing/capybara_config.rb
537
- - lib/panda/core/testing/omniauth_helpers.rb
538
- - lib/panda/core/testing/rspec_config.rb
539
473
  - lib/panda/core/version.rb
540
474
  - lib/tasks/assets.rake
541
475
  - lib/tasks/panda/core/migrations.rake
@@ -1,43 +0,0 @@
1
- require "spec_helper"
2
-
3
- RUBY_FILE_PATTERN = File.expand_path("../../**/*.rb", __dir__)
4
- EXCLUDED_PATHS = [
5
- "db/schema.rb",
6
- "bin/",
7
- "script/",
8
- "log/",
9
- "public/",
10
- "tmp/",
11
- "doc/",
12
- "vendor/",
13
- "storage/",
14
- "node_modules/",
15
- ".git/",
16
- "spec/dummy/"
17
- ].freeze
18
-
19
- RSpec.describe "Reek" do
20
- it "contains no code smells" do
21
- failures = []
22
-
23
- Dir.glob(RUBY_FILE_PATTERN).each do |file|
24
- next if EXCLUDED_PATHS.any? { |path| file.include?(path) }
25
-
26
- IO.popen(["bundle", "exec", "reek", file], err: [:child, :out]) do |io|
27
- output = io.read
28
- next if output.empty?
29
-
30
- failures << {file: file, output: output}
31
- end
32
- end
33
-
34
- failures.each do |failure|
35
- puts "\nCode smells found in #{failure[:file]}:"
36
- puts failure[:output]
37
- end
38
-
39
- failures.each do |failure|
40
- expect(failure).to be_nil, "Found code smells in #{failure[:file]}"
41
- end
42
- end
43
- end
@@ -1,24 +0,0 @@
1
- Description:
2
- Sets up or updates Panda Core development tools in your gem or Rails application.
3
- This includes linting configurations, testing helpers, and CI/CD workflows.
4
-
5
- Example:
6
- # Initial setup
7
- rails generate panda:core:dev_tools
8
-
9
- # Force update (overwrites existing files)
10
- rails generate panda:core:dev_tools --force
11
-
12
- # Skip adding dependencies to Gemfile
13
- rails generate panda:core:dev_tools --skip-dependencies
14
-
15
- This will:
16
- - Copy .standard.yml, .yamllint, and .rspec configurations
17
- - Set up GitHub Actions workflows for CI and releases
18
- - Add development dependencies to your Gemfile
19
- - Create testing helper configuration
20
- - Add rake tasks for linting and security checks
21
- - Track version for future updates
22
-
23
- To check for updates later:
24
- bundle exec rake panda:check_updates
@@ -1,13 +0,0 @@
1
- ---
2
- assert_lefthook_installed: true
3
- colors: true
4
- pre-commit:
5
- parallel: true
6
- jobs:
7
- - name: bundle-audit
8
- run: bundle exec bundle-audit --update
9
- - name: bundle-outdated
10
- run: bundle outdated --strict
11
- - name: standardrb
12
- run: bundle exec standardrb --fix {all_files}
13
- glob: "**/*.rb"
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "panda/core/testing/rspec_config"
4
- require "panda/core/testing/omniauth_helpers"
5
- require "panda/core/testing/capybara_config"
6
-
7
- RSpec.configure do |config|
8
- # Apply Panda Core RSpec configuration
9
- Panda::Core::Testing::RSpecConfig.configure(config)
10
- Panda::Core::Testing::RSpecConfig.setup_matchers
11
-
12
- # Configure Capybara
13
- Panda::Core::Testing::CapybaraConfig.configure
14
-
15
- # Include helpers
16
- config.include Panda::Core::Testing::OmniAuthHelpers, type: :system
17
- config.include Panda::Core::Testing::CapybaraConfig::Helpers, type: :system
18
- end
@@ -1,143 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators"
4
-
5
- module Panda
6
- module Core
7
- module Generators
8
- class DevToolsGenerator < Rails::Generators::Base
9
- source_root File.expand_path("dev_tools/templates", __dir__)
10
-
11
- desc "Set up or update Panda Core development tools in your gem/application"
12
-
13
- class_option :force, type: :boolean, default: false,
14
- desc: "Overwrite existing files"
15
- class_option :skip_dependencies, type: :boolean, default: false,
16
- desc: "Skip adding dependencies to Gemfile"
17
-
18
- VERSION_FILE = ".panda-dev-tools-version"
19
- CURRENT_VERSION = "1.0.0"
20
-
21
- def check_for_updates
22
- if File.exist?(VERSION_FILE)
23
- installed_version = File.read(VERSION_FILE).strip
24
- if installed_version != CURRENT_VERSION
25
- say "Updating Panda Core dev tools from #{installed_version} to #{CURRENT_VERSION}", :yellow
26
- @updating = true
27
- else
28
- say "Panda Core dev tools are up to date (#{CURRENT_VERSION})", :green
29
- unless options[:force]
30
- say "Use --force to reinstall anyway"
31
- nil
32
- end
33
- end
34
- else
35
- say "Installing Panda Core dev tools #{CURRENT_VERSION}", :green
36
- @updating = false
37
- end
38
- end
39
-
40
- def copy_linting_configs
41
- say "Copying linting configurations..."
42
- copy_file ".standard.yml", force: options[:force] || @updating
43
- copy_file ".yamllint", force: options[:force] || @updating
44
- copy_file ".rspec", force: options[:force] || @updating
45
- copy_file "lefthook.yml", force: options[:force] || @updating
46
- end
47
-
48
- def copy_github_workflows
49
- say "Copying GitHub Actions workflows..."
50
- directory ".github", ".github", force: options[:force] || @updating
51
- end
52
-
53
- def create_version_file
54
- create_file VERSION_FILE, CURRENT_VERSION, force: true
55
- end
56
-
57
- def add_development_dependencies
58
- say "Adding development dependencies to gemspec..."
59
-
60
- if File.exist?("Gemfile")
61
- append_to_file "Gemfile" do
62
- <<~RUBY
63
-
64
- group :development, :test do
65
- # Panda Core development tools
66
- gem "standard"
67
- gem "brakeman"
68
- gem "bundler-audit"
69
- gem "yamllint"
70
- end
71
- RUBY
72
- end
73
- end
74
- end
75
-
76
- def create_spec_helper
77
- say "Creating spec helper with Panda Core testing configuration..."
78
-
79
- create_file "spec/support/panda_core_helpers.rb" do
80
- <<~RUBY
81
- # frozen_string_literal: true
82
-
83
- require 'panda/core/testing/rspec_config'
84
- require 'panda/core/testing/omniauth_helpers'
85
- require 'panda/core/testing/capybara_config'
86
-
87
- RSpec.configure do |config|
88
- # Apply Panda Core RSpec configuration
89
- Panda::Core::Testing::RSpecConfig.configure(config)
90
- Panda::Core::Testing::RSpecConfig.setup_matchers
91
-
92
- # Configure Capybara
93
- Panda::Core::Testing::CapybaraConfig.configure
94
-
95
- # Include helpers
96
- config.include Panda::Core::Testing::OmniAuthHelpers, type: :system
97
- config.include Panda::Core::Testing::CapybaraConfig::Helpers, type: :system
98
- end
99
- RUBY
100
- end
101
- end
102
-
103
- def add_rake_tasks
104
- say "Adding Panda Core rake tasks..."
105
-
106
- append_to_file "Rakefile" do
107
- <<~RUBY
108
-
109
- # Panda Core development tasks
110
- namespace :panda do
111
- desc "Run all linters"
112
- task :lint do
113
- sh "bundle exec standardrb"
114
- sh "yamllint -c .yamllint ."
115
- end
116
-
117
- desc "Run security checks"
118
- task :security do
119
- sh "bundle exec brakeman --quiet"
120
- sh "bundle exec bundle-audit --update"
121
- end
122
-
123
- desc "Run all quality checks"
124
- task quality: [:lint, :security]
125
- end
126
- RUBY
127
- end
128
- end
129
-
130
- def display_instructions
131
- say "\n✅ Panda Core development tools have been set up!", :green
132
- say "\nNext steps:"
133
- say " 1. Run 'bundle install' to install new dependencies"
134
- say " 2. Run 'bundle exec rake panda:quality' to check code quality"
135
- say " 3. Customize .github/workflows for your gem's needs"
136
- say " 4. Add 'require' statements to your spec_helper.rb or rails_helper.rb:"
137
- say " require 'support/panda_core_helpers'"
138
- say "\nFor more information, see: docs/development_tools.md"
139
- end
140
- end
141
- end
142
- end
143
- end
@@ -1,41 +0,0 @@
1
- module Panda
2
- module Core
3
- class InstallGenerator < Rails::Generators::Base
4
- include Rails::Generators::Migration
5
-
6
- source_root File.expand_path("templates", __dir__)
7
-
8
- namespace "panda:core:install"
9
-
10
- # Allow incompatible default types for Thor options
11
- def self.allow_incompatible_default_type!
12
- true
13
- end
14
-
15
- class_option :skip_migrations, type: :boolean, default: false,
16
- desc: "Skip migrations installation"
17
- class_option :orm, type: :string, default: "active_record",
18
- desc: "ORM to be used for migrations"
19
-
20
- def self.next_migration_number(dirname)
21
- next_migration_number = current_migration_number(dirname) + 1
22
- ActiveRecord::Migration.next_migration_number(next_migration_number)
23
- end
24
-
25
- def create_initializer
26
- template "initializer.rb", "config/initializers/panda.rb"
27
- end
28
-
29
- def mount_engine
30
- routes_file = File.join(destination_root, "config/routes.rb")
31
- return unless File.exist?(routes_file)
32
-
33
- route 'mount Panda::Core::Engine => "/"'
34
- end
35
-
36
- def show_readme
37
- readme "README" if behavior == :invoke
38
- end
39
- end
40
- end
41
- end
@@ -1,25 +0,0 @@
1
- ===============================================================================
2
-
3
- Panda Core has been installed!
4
-
5
- Next steps:
6
-
7
- 1. Install and run migrations:
8
-
9
- rails panda:core:install:migrations
10
- rails db:migrate
11
-
12
- 2. Configure authentication providers in config/initializers/panda.rb
13
- (Uncomment and configure the providers you want to use)
14
-
15
- 3. Add the required OAuth gems to your Gemfile:
16
-
17
- gem 'omniauth-google-oauth2' # For Google authentication
18
- gem 'omniauth-microsoft_graph' # For Microsoft authentication
19
- gem 'omniauth-github' # For GitHub authentication
20
-
21
- 4. Configure your OAuth credentials in Rails credentials:
22
-
23
- rails credentials:edit
24
-
25
- ===============================================================================
@@ -1,44 +0,0 @@
1
- Panda::Core.configure do |config|
2
- config.admin_path = "/admin"
3
-
4
- config.login_page_title = "Panda Admin"
5
- config.admin_title = "Panda Admin"
6
-
7
- # Configure authentication providers
8
- # Uncomment and configure the providers you want to use
9
- # Don't forget to add the corresponding gems (e.g., omniauth-google-oauth2)
10
- #
11
- # config.authentication_providers = {
12
- # google_oauth2: {
13
- # enabled: true,
14
- # name: "Google", # Display name for the button
15
- # icon: "google", # FontAwesome icon name (optional, auto-detected if not specified)
16
- # client_id: Rails.application.credentials.dig(:google, :client_id),
17
- # client_secret: Rails.application.credentials.dig(:google, :client_secret),
18
- # options: {
19
- # scope: "email,profile",
20
- # prompt: "select_account",
21
- # hd: "yourdomain.com" # Specify your domain here if you want to restrict admin logins
22
- # }
23
- # }
24
- # }
25
-
26
- # Configure the session token cookie name
27
- config.session_token_cookie = :panda_session
28
-
29
- # Configure the user class for the application
30
- config.user_class = "Panda::Core::User"
31
-
32
- # Configure the user identity class for the application
33
- config.user_identity_class = "Panda::Core::UserIdentity"
34
-
35
- # Configure the storage provider (default: :active_storage)
36
- # config.storage_provider = :active_storage
37
-
38
- # Configure the cache store (default: :memory_store)
39
- # config.cache_store = :memory_store
40
-
41
- # Configure EditorJS tools (optional)
42
- # config.editor_js_tools = []
43
- # config.editor_js_tool_config = {}
44
- end
@@ -1,27 +0,0 @@
1
- require "rails/generators"
2
- require "fileutils"
3
- require "pathname"
4
-
5
- module Panda
6
- module Core
7
- module Generators
8
- class TemplatesGenerator < Rails::Generators::Base
9
- include Thor::Actions
10
-
11
- desc "Copies shared configuration templates from panda_core"
12
-
13
- source_root File.expand_path("templates", __dir__)
14
-
15
- def copy_templates
16
- Dir.glob(File.join(self.class.source_root, "**/{.*,*}"), File::FNM_DOTMATCH).each do |file|
17
- next if File.directory?(file)
18
- next if File.basename(file) == "." || File.basename(file) == ".."
19
-
20
- relative_path = Pathname.new(file).relative_path_from(Pathname.new(self.class.source_root)).to_s
21
- copy_file relative_path
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "capybara/rspec"
4
-
5
- module Panda
6
- module Core
7
- module Testing
8
- module CapybaraConfig
9
- def self.configure
10
- Capybara.server = :puma, {Silent: true}
11
- Capybara.default_max_wait_time = 5
12
- Capybara.disable_animation = true
13
-
14
- # Register Chrome driver with sensible defaults
15
- if defined?(Cuprite)
16
- Capybara.register_driver :panda_chrome do |app|
17
- Cuprite::Driver.new(
18
- app,
19
- window_size: [1400, 1400],
20
- browser_options: {
21
- "no-sandbox": nil,
22
- "disable-gpu": nil,
23
- "disable-dev-shm-usage": nil
24
- },
25
- inspector: ENV["INSPECTOR"] == "true",
26
- headless: ENV["HEADLESS"] != "false"
27
- )
28
- end
29
-
30
- Capybara.javascript_driver = :panda_chrome
31
- Capybara.default_driver = :rack_test
32
- end
33
- end
34
-
35
- # Helper methods for system tests
36
- module Helpers
37
- def wait_for_ajax
38
- Timeout.timeout(Capybara.default_max_wait_time) do
39
- loop until page.evaluate_script("jQuery.active").zero?
40
- end
41
- rescue Timeout::Error
42
- # Ajax didn't finish, but continue anyway
43
- end
44
-
45
- def wait_for_turbo
46
- has_css?("html", wait: 0.1)
47
- return unless page.evaluate_script("typeof Turbo !== 'undefined'")
48
-
49
- page.evaluate_script("Turbo.session.drive = false")
50
- yield if block_given?
51
- page.evaluate_script("Turbo.session.drive = true")
52
- end
53
-
54
- def take_screenshot_on_failure
55
- return unless page.driver.respond_to?(:save_screenshot)
56
-
57
- timestamp = Time.now.strftime("%Y%m%d_%H%M%S")
58
- filename = "screenshot_#{timestamp}_#{example.description.parameterize}.png"
59
- path = Rails.root.join("tmp", "screenshots", filename)
60
-
61
- FileUtils.mkdir_p(File.dirname(path))
62
- page.driver.save_screenshot(path)
63
-
64
- puts "\nScreenshot saved: #{path}"
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Panda
4
- module Core
5
- module Testing
6
- module OmniAuthHelpers
7
- def mock_omniauth_login(email: "admin@example.com", name: "Test User", provider: :google_oauth2, uid: "123456789", is_admin: true)
8
- OmniAuth.config.test_mode = true
9
- OmniAuth.config.mock_auth[provider] = OmniAuth::AuthHash.new(
10
- provider: provider.to_s,
11
- uid: uid,
12
- info: {
13
- email: email,
14
- name: name,
15
- image: "https://example.com/avatar.jpg"
16
- }
17
- )
18
-
19
- # Create or update the user in the test database
20
- Panda::Core::User.find_or_create_by(email: email) do |u|
21
- # Split name into firstname and lastname
22
- parts = name.split(" ", 2)
23
- u.firstname = parts[0] || name
24
- u.lastname = parts[1] || ""
25
- u.admin = is_admin
26
- end
27
- end
28
-
29
- def login_as_admin(email: "admin@example.com", name: "Admin User")
30
- user = mock_omniauth_login(email: email, name: name, is_admin: true)
31
- visit "/admin/auth/google_oauth2"
32
- user
33
- end
34
-
35
- def login_as_user(email: "user@example.com", name: "Regular User")
36
- user = mock_omniauth_login(email: email, name: name, is_admin: false)
37
- visit "/admin/auth/google_oauth2"
38
- user
39
- end
40
-
41
- def logout
42
- visit "/admin/logout"
43
- end
44
-
45
- def mock_omniauth_failure(message = "Authentication failed")
46
- OmniAuth.config.test_mode = true
47
- OmniAuth.config.mock_auth[:google_oauth2] = :invalid_credentials
48
- end
49
- end
50
- end
51
- end
52
- end