rails_admin_tokens 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 638b9a3acb9637b5b520f965bd4915cf9c3521c5001cdaaffb7da05ef472a71d
4
+ data.tar.gz: 5698ead82ade0724bd3a45dc1b2471e33cfb071deaad6f38a2c32c5599cab26c
5
+ SHA512:
6
+ metadata.gz: 4bbbe40bdacf32cc4a39bc8a8d73a779b60d47d121fde7d7393168519c5836ddd5f83a66e06bdaa15b75901d26adc58f3339f21d13e540d35aca9cf71dfbd380
7
+ data.tar.gz: 79ae4cf3ee38d59f04027a050626dff2602c2f6580ff4909c07d0db86523f05c95f024d60174120da1477fa6bef06d831cbe4589fb57ed2d8a76c78efba3f919
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Dinis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # RailsAdminTokens
2
+ This Rails Admin action allows you to configure an action to be called on the object.
3
+ The motivation behind this was to manually update oauth2 tokens but can be used to call any action on the object.
4
+
5
+ ## Usage
6
+ After adding this gem to your bundle, you can setup your rails_admin initializer to include tokens, like so:
7
+ ```ruby
8
+ # config/initializers/rails_admin.rb
9
+ config.actions do
10
+ dashboard # mandatory
11
+ index # mandatory
12
+ # ...
13
+
14
+ tokens do
15
+ only ['MyTargetUser']
16
+ end
17
+ end
18
+ ```
19
+ Customize your view:
20
+ ````ruby
21
+ # views/rails_admin/main/tokens.html.erb
22
+ ````
23
+
24
+ ## Installation
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem "rails_admin_tokens"
29
+ ```
30
+
31
+ And then execute:
32
+ ```bash
33
+ $ bundle
34
+ ```
35
+
36
+ Or install it yourself as:
37
+ ```bash
38
+ $ gem install rails_admin_tokens
39
+ ```
40
+
41
+ ## Contributing
42
+ Contribution directions go here.
43
+
44
+ ## License
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/setup"
2
+
3
+ load "rails/tasks/statistics.rake"
4
+
5
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ <h4>
2
+ <%= t("admin.token.do_you_want_to_refresh_access_token", model_name: @abstract_model.pretty_name.downcase) %>
3
+ </h4>
4
+ <h4><%= t('admin.token.current_tokens_title') %></h4>
5
+ <p><%= t('admin.token.refresh_token_label') %>: <%= @object.refresh_token %></p>
6
+ <p><%= t('admin.token.access_token_label') %>: <%= @object.access_token %></p>
7
+ <%= form_for(@object, url: tokens_path(model_name: @abstract_model.to_param, id: @object.id), html: {method: "put"}) do %>
8
+ <input name="return_to" type="<%= :hidden %>" value="<%= (params[:return_to].presence || request.referer) %>" />
9
+ <div class="form-actions">
10
+ <button class="btn btn-info" data-disable-with="<%= t("admin.form.confirmation") %>" name="_refresh" type="submit">
11
+ <i class="fas fa-sync"></i>
12
+ <%= t("admin.form.refresh") %>
13
+ </button>
14
+ <button class="btn" data-disable-with="<%= t("admin.form.cancel") %>" name="_continue" type="submit">
15
+ <i class="fas fa-times"></i>
16
+ <%= t("admin.form.cancel") %>
17
+ </button>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,11 @@
1
+
2
+ en:
3
+ admin:
4
+ actions:
5
+ tokens:
6
+ title: "Tokens"
7
+ menu: "Tokens for %{model_label} '%{object_label}'"
8
+ breadcrumb: "Tokens"
9
+ link: "Tokens"
10
+ bulk_link: "Tokens selected %{model_label_plural}"
11
+ done: "Tokensed"
@@ -0,0 +1,4 @@
1
+ module RailsAdminTokens
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminTokens
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,67 @@
1
+ require "rails_admin_tokens/version"
2
+ require "rails_admin_tokens/engine"
3
+
4
+ module RailsAdminTokens
5
+ # Your code goes here...
6
+ end
7
+
8
+ require 'rails_admin/config/actions'
9
+
10
+ module RailsAdmin
11
+ module Config
12
+ module Actions
13
+ class Tokens < Base
14
+ RailsAdmin::Config::Actions.register(self)
15
+
16
+ register_instance_option :refresh_method do
17
+ :refresh_token_if_expired
18
+ end
19
+ register_instance_option :member do
20
+ true
21
+ end
22
+
23
+ register_instance_option :route_fragment do
24
+ 'tokens'
25
+ end
26
+
27
+ register_instance_option :http_methods do
28
+ %i[get put]
29
+ end
30
+
31
+ register_instance_option :controller do
32
+ proc do
33
+ if request.get? # Tokens
34
+
35
+ respond_to do |format|
36
+ format.html { render @action.template_name }
37
+ format.js { render @action.template_name, layout: 'rails_admin/modal', content_type: Mime[:html].to_s }
38
+ end
39
+
40
+ elsif request.put? # Refresh Tokens
41
+ @authorization_adapter&.authorize(:update, @abstract_model, @object)
42
+ if @object.send(@action.refresh_method)
43
+ changes = @object.changes
44
+ @object.save
45
+ @auditing_adapter&.update_object(@object, @abstract_model, _current_user, changes)
46
+ respond_to do |format|
47
+ format.html { render @action.template_name }
48
+ format.json { render json: { id: @object.id.to_s, label: @model_config.with(object: @object).object_label } }
49
+ end
50
+ else
51
+ flash.now[:notice] = I18n.t('admin.flash.noaction')
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ register_instance_option :link_icon do
58
+ 'fas fa-sync'
59
+ end
60
+
61
+ register_instance_option :writable? do
62
+ !(bindings[:object] && bindings[:object].readonly?)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_tokens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dinis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ description: Setup an action to be called for the configured object.
28
+ email:
29
+ - dinis@lage.pw
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/views/rails_admin/main/tokens.html.erb
38
+ - config/locales/tokens.en.yml
39
+ - lib/rails_admin_tokens.rb
40
+ - lib/rails_admin_tokens/engine.rb
41
+ - lib/rails_admin_tokens/version.rb
42
+ homepage: https://lage.pw
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ allowed_push_host: https://rubygems.org
47
+ homepage_uri: https://lage.pw
48
+ source_code_uri: https://github.com/dlage/rails_admin_tokens
49
+ changelog_uri: https://github.com/dlage/rails_admin_tokens
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.3.19
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Rails Admin action to call a custom method on object.
69
+ test_files: []