administrate-field-active_storage 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +36 -14
- data/administrate-field-active_storage.gemspec +1 -1
- data/app/views/fields/active_storage/_form.html.erb +7 -0
- data/app/views/fields/active_storage/_item.html.erb +34 -1
- data/app/views/fields/active_storage/_items.html.erb +25 -0
- data/app/views/fields/active_storage/_show.html.erb +2 -8
- data/contribute.md +5 -1
- data/example-project/.gitignore +30 -0
- data/example-project/.ruby-version +1 -0
- data/example-project/Gemfile +66 -0
- data/example-project/Gemfile.lock +263 -0
- data/example-project/README.md +24 -0
- data/example-project/Rakefile +6 -0
- data/example-project/app/assets/config/manifest.js +3 -0
- data/example-project/app/assets/images/.keep +0 -0
- data/example-project/app/assets/javascripts/application.js +16 -0
- data/example-project/app/assets/javascripts/cable.js +13 -0
- data/example-project/app/assets/javascripts/channels/.keep +0 -0
- data/example-project/app/assets/stylesheets/application.css +15 -0
- data/example-project/app/channels/application_cable/channel.rb +4 -0
- data/example-project/app/channels/application_cable/connection.rb +4 -0
- data/example-project/app/controllers/admin/application_controller.rb +21 -0
- data/example-project/app/controllers/admin/users_controller.rb +21 -0
- data/example-project/app/controllers/application_controller.rb +2 -0
- data/example-project/app/controllers/concerns/.keep +0 -0
- data/example-project/app/controllers/users_controller.rb +7 -0
- data/example-project/app/dashboards/user_dashboard.rb +58 -0
- data/example-project/app/helpers/application_helper.rb +2 -0
- data/example-project/app/jobs/application_job.rb +2 -0
- data/example-project/app/mailers/application_mailer.rb +4 -0
- data/example-project/app/models/application_record.rb +3 -0
- data/example-project/app/models/concerns/.keep +0 -0
- data/example-project/app/models/user.rb +3 -0
- data/example-project/app/views/layouts/application.html.erb +15 -0
- data/example-project/app/views/layouts/mailer.html.erb +13 -0
- data/example-project/app/views/layouts/mailer.text.erb +1 -0
- data/example-project/bin/bundle +3 -0
- data/example-project/bin/rails +9 -0
- data/example-project/bin/rake +9 -0
- data/example-project/bin/setup +36 -0
- data/example-project/bin/spring +17 -0
- data/example-project/bin/update +31 -0
- data/example-project/bin/yarn +11 -0
- data/example-project/config.ru +5 -0
- data/example-project/config/application.rb +19 -0
- data/example-project/config/boot.rb +4 -0
- data/example-project/config/cable.yml +10 -0
- data/example-project/config/credentials.yml.enc +1 -0
- data/example-project/config/database.yml +25 -0
- data/example-project/config/environment.rb +5 -0
- data/example-project/config/environments/development.rb +61 -0
- data/example-project/config/environments/production.rb +94 -0
- data/example-project/config/environments/test.rb +46 -0
- data/example-project/config/initializers/application_controller_renderer.rb +8 -0
- data/example-project/config/initializers/assets.rb +14 -0
- data/example-project/config/initializers/backtrace_silencers.rb +7 -0
- data/example-project/config/initializers/content_security_policy.rb +25 -0
- data/example-project/config/initializers/cookies_serializer.rb +5 -0
- data/example-project/config/initializers/filter_parameter_logging.rb +4 -0
- data/example-project/config/initializers/inflections.rb +16 -0
- data/example-project/config/initializers/mime_types.rb +4 -0
- data/example-project/config/initializers/wrap_parameters.rb +14 -0
- data/example-project/config/locales/en.yml +33 -0
- data/example-project/config/puma.rb +34 -0
- data/example-project/config/routes.rb +9 -0
- data/example-project/config/spring.rb +6 -0
- data/example-project/config/storage.yml +34 -0
- data/example-project/db/migrate/20181013145025_create_users.rb +9 -0
- data/example-project/db/migrate/20181221134334_create_active_storage_tables.active_storage.rb +26 -0
- data/example-project/db/schema.rb +42 -0
- data/example-project/db/seeds.rb +7 -0
- data/example-project/lib/assets/.keep +0 -0
- data/example-project/lib/tasks/.keep +0 -0
- data/example-project/log/.keep +0 -0
- data/example-project/package.json +5 -0
- data/example-project/public/404.html +67 -0
- data/example-project/public/422.html +67 -0
- data/example-project/public/500.html +66 -0
- data/example-project/public/apple-touch-icon-precomposed.png +0 -0
- data/example-project/public/apple-touch-icon.png +0 -0
- data/example-project/public/favicon.ico +0 -0
- data/example-project/public/robots.txt +1 -0
- data/example-project/test/application_system_test_case.rb +5 -0
- data/example-project/test/controllers/.keep +0 -0
- data/example-project/test/fixtures/.keep +0 -0
- data/example-project/test/fixtures/files/.keep +0 -0
- data/example-project/test/fixtures/users.yml +7 -0
- data/example-project/test/helpers/.keep +0 -0
- data/example-project/test/integration/.keep +0 -0
- data/example-project/test/mailers/.keep +0 -0
- data/example-project/test/models/.keep +0 -0
- data/example-project/test/models/user_test.rb +7 -0
- data/example-project/test/system/.keep +0 -0
- data/example-project/test/test_helper.rb +10 -0
- data/example-project/tmp/.keep +0 -0
- data/example-project/vendor/.keep +0 -0
- data/lib/administrate/field/active_storage.rb +15 -0
- metadata +92 -2
@@ -0,0 +1,9 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
namespace :admin do
|
3
|
+
resources :users
|
4
|
+
|
5
|
+
root to: "users#index"
|
6
|
+
end
|
7
|
+
delete "custom_active_record_remove", to: 'users#remove_avatar'
|
8
|
+
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
9
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
test:
|
2
|
+
service: Disk
|
3
|
+
root: <%= Rails.root.join("tmp/storage") %>
|
4
|
+
|
5
|
+
local:
|
6
|
+
service: Disk
|
7
|
+
root: <%= Rails.root.join("storage") %>
|
8
|
+
|
9
|
+
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
|
10
|
+
# amazon:
|
11
|
+
# service: S3
|
12
|
+
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
|
13
|
+
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
|
14
|
+
# region: us-east-1
|
15
|
+
# bucket: your_own_bucket
|
16
|
+
|
17
|
+
# Remember not to checkin your GCS keyfile to a repository
|
18
|
+
# google:
|
19
|
+
# service: GCS
|
20
|
+
# project: your_project
|
21
|
+
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
|
22
|
+
# bucket: your_own_bucket
|
23
|
+
|
24
|
+
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
|
25
|
+
# microsoft:
|
26
|
+
# service: AzureStorage
|
27
|
+
# storage_account_name: your_account_name
|
28
|
+
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
|
29
|
+
# container: your_container_name
|
30
|
+
|
31
|
+
# mirror:
|
32
|
+
# service: Mirror
|
33
|
+
# primary: local
|
34
|
+
# mirrors: [ amazon, google, microsoft ]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This migration comes from active_storage (originally 20170806125915)
|
2
|
+
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
|
3
|
+
def change
|
4
|
+
create_table :active_storage_blobs do |t|
|
5
|
+
t.string :key, null: false
|
6
|
+
t.string :filename, null: false
|
7
|
+
t.string :content_type
|
8
|
+
t.text :metadata
|
9
|
+
t.bigint :byte_size, null: false
|
10
|
+
t.string :checksum, null: false
|
11
|
+
t.datetime :created_at, null: false
|
12
|
+
|
13
|
+
t.index [ :key ], unique: true
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :active_storage_attachments do |t|
|
17
|
+
t.string :name, null: false
|
18
|
+
t.references :record, null: false, polymorphic: true, index: false
|
19
|
+
t.references :blob, null: false
|
20
|
+
|
21
|
+
t.datetime :created_at, null: false
|
22
|
+
|
23
|
+
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 2018_12_21_134334) do
|
14
|
+
|
15
|
+
create_table "active_storage_attachments", force: :cascade do |t|
|
16
|
+
t.string "name", null: false
|
17
|
+
t.string "record_type", null: false
|
18
|
+
t.integer "record_id", null: false
|
19
|
+
t.integer "blob_id", null: false
|
20
|
+
t.datetime "created_at", null: false
|
21
|
+
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
|
22
|
+
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table "active_storage_blobs", force: :cascade do |t|
|
26
|
+
t.string "key", null: false
|
27
|
+
t.string "filename", null: false
|
28
|
+
t.string "content_type"
|
29
|
+
t.text "metadata"
|
30
|
+
t.bigint "byte_size", null: false
|
31
|
+
t.string "checksum", null: false
|
32
|
+
t.datetime "created_at", null: false
|
33
|
+
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table "users", force: :cascade do |t|
|
37
|
+
t.string "name"
|
38
|
+
t.datetime "created_at", null: false
|
39
|
+
t.datetime "updated_at", null: false
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
|
7
|
+
# Character.create(name: 'Luke', movie: movies.first)
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
require_relative '../config/environment'
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
7
|
+
fixtures :all
|
8
|
+
|
9
|
+
# Add more helper methods to be used by all tests here...
|
10
|
+
end
|
File without changes
|
File without changes
|
@@ -11,11 +11,19 @@ module Administrate
|
|
11
11
|
options.fetch(:url_only, false)
|
12
12
|
end
|
13
13
|
|
14
|
+
def destroyable?
|
15
|
+
options.key?(:destroy_path)
|
16
|
+
end
|
17
|
+
|
14
18
|
def many?
|
15
19
|
# find a way to use instance_of
|
16
20
|
data.class.name == "ActiveStorage::Attached::Many"
|
17
21
|
end
|
18
22
|
|
23
|
+
# def destroy_path?
|
24
|
+
# options.fetch(:destroy_path, false).present?
|
25
|
+
# end
|
26
|
+
|
19
27
|
# currently we are using Rails.application.routes.url_helpers
|
20
28
|
# without including the namespace because it runs into an
|
21
29
|
# exception
|
@@ -33,6 +41,13 @@ module Administrate
|
|
33
41
|
def blob_url(attachment)
|
34
42
|
Rails.application.routes.url_helpers.rails_blob_path(attachment, disposition: :attachment, only_path: true)
|
35
43
|
end
|
44
|
+
|
45
|
+
def destroy_path(field, attachment)
|
46
|
+
destroy_path_helper = options.fetch(:destroy_path)
|
47
|
+
record_id = field.data.record.id
|
48
|
+
attachment_id = attachment.id
|
49
|
+
Rails.application.routes.url_helpers.send(destroy_path_helper, {:record_id => record_id, :attachment_id => attachment_id})
|
50
|
+
end
|
36
51
|
|
37
52
|
delegate :attached?, to: :data
|
38
53
|
delegate :attachments, to: :data
|