simpleadmin 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/app/controllers/simple_admin/base_controller.rb +11 -0
- data/app/controllers/simple_admin/entities_controller.rb +26 -0
- data/app/controllers/simple_admin/resources_controller.rb +100 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/simpleadmin.rb +5 -0
- data/lib/simpleadmin/engine.rb +6 -0
- data/lib/simpleadmin/routes.rb +24 -0
- data/lib/simpleadmin/version.rb +3 -0
- data/simpleadmin.gemspec +32 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 89bce08902d50cacab299ba5e5fa55b847de9be550caa8b4bad1d8ac58520f2d
|
4
|
+
data.tar.gz: '0671935bb1f9973b7dc908e400392a65f99701c1c4f52108c125295c5f8cdec8'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec2bb8cb67ca622ffe019bbc580018b7c8785884fec132e27f32948bb83eb6d38a00b6c4c000bd45fcab3cc45da0a118dd5efc49471d41553bf31f38a900f22d
|
7
|
+
data.tar.gz: ba41bf51917aef04c818f53ff37d1009a33126863bc471482c752c5262de9a9f83380e062bd000319b3d7cef6f37f8757174bb189018147fc72fb49552b7702c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dmitiry_strukov2011@mail.ru. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# SimpleAdmin
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/evil-raccoon/simple-admin.svg?branch=master)](https://travis-ci.org/evil-raccoon/simple-admin)
|
4
|
+
[![codecov](https://codecov.io/gh/evil-raccoon/simple_admin/branch/master/graph/badge.svg)](https://codecov.io/gh/evil-raccoon/simple_admin)
|
5
|
+
[![Inline docs](http://inch-ci.org/github/evil-raccoon/simple_admin.svg)](http://inch-ci.org/github/evil-raccoon/simple_admin)
|
6
|
+
|
7
|
+
https://getsimpleadmin.com
|
8
|
+
|
9
|
+
A small API library to connect your application with SimpleAdmin service and create admin dashboards in an instant.
|
10
|
+
|
11
|
+
## Getting started
|
12
|
+
|
13
|
+
![simple_admin](https://i.imgur.com/s1fGVRq.png)
|
14
|
+
|
15
|
+
Add SimpleAdmin to your Gemfile and run bundle:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'simple-admin'
|
19
|
+
```
|
20
|
+
|
21
|
+
After that, you need to mount simple admin built-in routes:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# config/routes.rb
|
25
|
+
Rails.application.routes.draw do
|
26
|
+
mount_for_simple_admin
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Create initializer, add your secret key and restart server
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# config/initializers/simpleadmin.rb
|
34
|
+
ENV['SIMPLE_ADMIN_SECRET_KEY'] = 'SECRET_KEY'
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( https://github.com/evil-raccoon/simple_admin/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create a new Pull Request
|
44
|
+
|
45
|
+
## Copyright
|
46
|
+
|
47
|
+
Released under MIT License.
|
48
|
+
|
49
|
+
Copyright © 2018 Evil Raccoon.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module SimpleAdmin
|
2
|
+
class BaseController < ActionController::API
|
3
|
+
before_action :verify_key_is_valid!
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def verify_key_is_valid!
|
8
|
+
return head(:forbidden) unless request.headers['SimpleAdmin-Secret-Key'] == ENV['SIMPLE_ADMIN_SECRET_KEY']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SimpleAdmin
|
2
|
+
class EntitiesController < BaseController
|
3
|
+
before_action :load_models
|
4
|
+
|
5
|
+
def index
|
6
|
+
render json: {
|
7
|
+
entities_names: ApplicationRecord.descendants.map { |model| model.name }
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
resource_klass = params[:id].capitalize.constantize
|
13
|
+
|
14
|
+
render json: {
|
15
|
+
name: resource_klass.name,
|
16
|
+
column_names: resource_klass.column_names
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def load_models
|
23
|
+
Rails.application.eager_load!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Api::V1
|
2
|
+
module SimpleAdmin
|
3
|
+
class ResourcesController < BaseController
|
4
|
+
def index
|
5
|
+
model_klass = params[:model_klass_name].constantize
|
6
|
+
model_fields = params[:model_fields]
|
7
|
+
|
8
|
+
per_page = params[:per_page].to_i
|
9
|
+
page = params[:page].to_i if params[:page].present?
|
10
|
+
total = model_klass.count
|
11
|
+
|
12
|
+
resources = model_klass.limit(per_page)
|
13
|
+
|
14
|
+
if params[:query].present?
|
15
|
+
search_result = search(params[:query], model_klass, params[:model_attributes])
|
16
|
+
|
17
|
+
resources = search_result[:resources]
|
18
|
+
total = search_result[:total]
|
19
|
+
end
|
20
|
+
|
21
|
+
resources = resources.offset((per_page * page) - per_page) if page.present?
|
22
|
+
resources = resources.order(params[:sort][:column_name] => params[:sort][:order]) if params[:sort].present?
|
23
|
+
|
24
|
+
resources = resources.map do |resource|
|
25
|
+
_resource = {}
|
26
|
+
|
27
|
+
resource.attributes.each do |attribute_name, attribute_value|
|
28
|
+
next unless model_fields.include?(attribute_name)
|
29
|
+
|
30
|
+
_resource[attribute_name] = attribute_value
|
31
|
+
end
|
32
|
+
|
33
|
+
_resource
|
34
|
+
end
|
35
|
+
|
36
|
+
render json: {
|
37
|
+
resources: resources,
|
38
|
+
total: total
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def show
|
43
|
+
model_klass = params[:model_klass_name].constantize
|
44
|
+
model_fields = params[:model_fields]
|
45
|
+
|
46
|
+
resource = model_klass.find(params[:id]).attributes.slice(*model_fields)
|
47
|
+
|
48
|
+
render json: resource
|
49
|
+
end
|
50
|
+
|
51
|
+
def create
|
52
|
+
model_klass = params[:model_klass_name].constantize
|
53
|
+
|
54
|
+
resource = model_klass.new(resource_params)
|
55
|
+
|
56
|
+
if resource.save
|
57
|
+
render json: resource
|
58
|
+
else
|
59
|
+
render json: resource.errors
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def update
|
64
|
+
model_klass = params[:model_klass_name].constantize
|
65
|
+
resource = model_klass.find(params[:id])
|
66
|
+
|
67
|
+
if resource.update(resource_params)
|
68
|
+
render json: resource
|
69
|
+
else
|
70
|
+
render json: resource.errors
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def destroy
|
75
|
+
model_klass = params[:model_klass_name].constantize
|
76
|
+
resource = model_klass.find(params[:id])
|
77
|
+
|
78
|
+
resource.destroy
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def search(search_query, model_klass, model_attributes)
|
84
|
+
return [] if model_attributes.empty?
|
85
|
+
|
86
|
+
query = model_attributes.map { |model_attribute| "#{model_attribute} LIKE ?" }.join(' OR ')
|
87
|
+
query_arguments = model_attributes.map { "%#{search_query}%" }
|
88
|
+
|
89
|
+
{
|
90
|
+
resources: model_klass.where(query, *query_arguments),
|
91
|
+
total: model_klass.where(query, *query_arguments).count
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def resource_params
|
96
|
+
params.require(:resource).permit!
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simpleadmin"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/simpleadmin.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
# Contain built-in routes
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
#
|
7
|
+
# # config/routes.rb
|
8
|
+
#
|
9
|
+
# Rails.application.routes.draw do
|
10
|
+
# mount_for_simple_admin
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# @since 1.0.0
|
14
|
+
|
15
|
+
def mount_simpleadmin
|
16
|
+
namespace :simple_admin do
|
17
|
+
resources :entities, only: [:index, :show]
|
18
|
+
resources :resources
|
19
|
+
|
20
|
+
post 'verify_key' => 'credentials#verify_key'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/simpleadmin.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "simpleadmin/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simpleadmin"
|
8
|
+
spec.version = Simpleadmin::VERSION
|
9
|
+
spec.authors = ["Dmitriy Strukov"]
|
10
|
+
spec.email = ["dmitiry_strukov2011@mail.ru"]
|
11
|
+
|
12
|
+
spec.summary = 'simple-admin'
|
13
|
+
spec.description = 'simple-admin'
|
14
|
+
spec.homepage = 'https://github.com/evil-raccoon/simple_admin'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'actionpack'
|
30
|
+
spec.add_development_dependency 'actionview'
|
31
|
+
spec.add_development_dependency 'activerecord'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simpleadmin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitriy Strukov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: actionpack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: actionview
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
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: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: simple-admin
|
98
|
+
email:
|
99
|
+
- dmitiry_strukov2011@mail.ru
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- app/controllers/simple_admin/base_controller.rb
|
112
|
+
- app/controllers/simple_admin/entities_controller.rb
|
113
|
+
- app/controllers/simple_admin/resources_controller.rb
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- lib/simpleadmin.rb
|
117
|
+
- lib/simpleadmin/engine.rb
|
118
|
+
- lib/simpleadmin/routes.rb
|
119
|
+
- lib/simpleadmin/version.rb
|
120
|
+
- simpleadmin.gemspec
|
121
|
+
homepage: https://github.com/evil-raccoon/simple_admin
|
122
|
+
licenses: []
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.7.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: simple-admin
|
144
|
+
test_files: []
|