ezii-postgres 0.0.1
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 +7 -0
- data/ezii-postgres.gemspec +13 -0
- data/natural-backend/Capfile +50 -0
- data/natural-backend/Gemfile +63 -0
- data/natural-backend/Gemfile.lock +233 -0
- data/natural-backend/LICENSE +21 -0
- data/natural-backend/Procfile +2 -0
- data/natural-backend/README.md +51 -0
- data/natural-backend/Rakefile +6 -0
- data/natural-backend/app.json +28 -0
- data/natural-backend/app/channels/application_cable/channel.rb +4 -0
- data/natural-backend/app/channels/application_cable/connection.rb +4 -0
- data/natural-backend/app/commands/base_command.rb +31 -0
- data/natural-backend/app/commands/create_new_or_authenticate_user.rb +60 -0
- data/natural-backend/app/commands/create_project_authentication_token_command.rb +25 -0
- data/natural-backend/app/commands/decode_authentication_command.rb +50 -0
- data/natural-backend/app/commands/decode_project_authentication_token_command.rb +51 -0
- data/natural-backend/app/controllers/application_controller.rb +3 -0
- data/natural-backend/app/controllers/authentication_controller.rb +17 -0
- data/natural-backend/app/controllers/columns_controller.rb +51 -0
- data/natural-backend/app/controllers/concerns/token_authenticatable.rb +26 -0
- data/natural-backend/app/controllers/databases_controller.rb +51 -0
- data/natural-backend/app/controllers/ember_controller.rb +6 -0
- data/natural-backend/app/controllers/projects_controller.rb +51 -0
- data/natural-backend/app/controllers/queries_controller.rb +59 -0
- data/natural-backend/app/controllers/row_values_controller.rb +51 -0
- data/natural-backend/app/controllers/rows_controller.rb +56 -0
- data/natural-backend/app/controllers/tables_controller.rb +55 -0
- data/natural-backend/app/jobs/application_job.rb +2 -0
- data/natural-backend/app/jobs/create_column_job.rb +10 -0
- data/natural-backend/app/jobs/create_database_job.rb +11 -0
- data/natural-backend/app/jobs/create_database_user_job.rb +8 -0
- data/natural-backend/app/jobs/create_table_job.rb +21 -0
- data/natural-backend/app/jobs/delete_row_job.rb +12 -0
- data/natural-backend/app/jobs/delete_value_job.rb +10 -0
- data/natural-backend/app/jobs/destroy_column_job.rb +10 -0
- data/natural-backend/app/jobs/destroy_database_job.rb +8 -0
- data/natural-backend/app/jobs/destroy_database_user_job.rb +8 -0
- data/natural-backend/app/jobs/destroy_table_job.rb +9 -0
- data/natural-backend/app/jobs/insert_value_job.rb +11 -0
- data/natural-backend/app/jobs/run_query_job.rb +35 -0
- data/natural-backend/app/jobs/sync_db_job.rb +80 -0
- data/natural-backend/app/jobs/update_column_type_job.rb +10 -0
- data/natural-backend/app/jobs/update_value_job.rb +10 -0
- data/natural-backend/app/mailers/application_mailer.rb +4 -0
- data/natural-backend/app/models/application_record.rb +3 -0
- data/natural-backend/app/models/column.rb +43 -0
- data/natural-backend/app/models/database.rb +37 -0
- data/natural-backend/app/models/project.rb +31 -0
- data/natural-backend/app/models/query.rb +20 -0
- data/natural-backend/app/models/row.rb +15 -0
- data/natural-backend/app/models/row_value.rb +30 -0
- data/natural-backend/app/models/table.rb +32 -0
- data/natural-backend/app/models/user.rb +10 -0
- data/natural-backend/app/serializers/column_serializer.rb +5 -0
- data/natural-backend/app/serializers/database_serializer.rb +6 -0
- data/natural-backend/app/serializers/project_serializer.rb +4 -0
- data/natural-backend/app/serializers/query_serializer.rb +3 -0
- data/natural-backend/app/serializers/row_serializer.rb +5 -0
- data/natural-backend/app/serializers/row_value_serializer.rb +5 -0
- data/natural-backend/app/serializers/table_serializer.rb +8 -0
- data/natural-backend/app/services/jwt_service.rb +17 -0
- data/natural-backend/app/views/layouts/mailer.html.erb +13 -0
- data/natural-backend/app/views/layouts/mailer.text.erb +1 -0
- data/natural-backend/bin/bundle +3 -0
- data/natural-backend/bin/rails +9 -0
- data/natural-backend/bin/rake +9 -0
- data/natural-backend/bin/run_migrations.sh +3 -0
- data/natural-backend/bin/setup +35 -0
- data/natural-backend/bin/spring +17 -0
- data/natural-backend/bin/update +29 -0
- data/natural-backend/config.ru +5 -0
- data/natural-backend/config/application.rb +33 -0
- data/natural-backend/config/boot.rb +3 -0
- data/natural-backend/config/cable.yml +10 -0
- data/natural-backend/config/database.yml +21 -0
- data/natural-backend/config/deploy.rb +36 -0
- data/natural-backend/config/deploy/production.rb +61 -0
- data/natural-backend/config/deploy/staging.rb +61 -0
- data/natural-backend/config/environment.rb +5 -0
- data/natural-backend/config/environments/development.rb +47 -0
- data/natural-backend/config/environments/production.rb +83 -0
- data/natural-backend/config/environments/test.rb +42 -0
- data/natural-backend/config/initializers/application_controller_renderer.rb +8 -0
- data/natural-backend/config/initializers/backtrace_silencers.rb +7 -0
- data/natural-backend/config/initializers/bugsnag.rb +3 -0
- data/natural-backend/config/initializers/cors.rb +16 -0
- data/natural-backend/config/initializers/filter_parameter_logging.rb +4 -0
- data/natural-backend/config/initializers/inflections.rb +16 -0
- data/natural-backend/config/initializers/json_api.rb +5 -0
- data/natural-backend/config/initializers/load_commands.rb +4 -0
- data/natural-backend/config/initializers/load_lib.rb +6 -0
- data/natural-backend/config/initializers/mime_types.rb +4 -0
- data/natural-backend/config/initializers/redis_classy.rb +1 -0
- data/natural-backend/config/initializers/sidekiq.rb +1 -0
- data/natural-backend/config/initializers/wrap_parameters.rb +14 -0
- data/natural-backend/config/locales/en.yml +33 -0
- data/natural-backend/config/puma.rb +56 -0
- data/natural-backend/config/routes.rb +14 -0
- data/natural-backend/config/schedule.rb +18 -0
- data/natural-backend/config/secrets.yml +32 -0
- data/natural-backend/config/spring.rb +6 -0
- data/natural-backend/db/migrate/20180408155000_create_projects.rb +9 -0
- data/natural-backend/db/migrate/20180408155011_create_databases.rb +10 -0
- data/natural-backend/db/migrate/20180409174859_create_tables.rb +9 -0
- data/natural-backend/db/migrate/20180409174916_create_columns.rb +11 -0
- data/natural-backend/db/migrate/20180409175800_create_rows.rb +9 -0
- data/natural-backend/db/migrate/20180409214650_create_row_values.rb +11 -0
- data/natural-backend/db/migrate/20180411110745_add_db_username_to_projects.rb +5 -0
- data/natural-backend/db/migrate/20180411145722_add_dbpw_to_projects.rb +5 -0
- data/natural-backend/db/migrate/20180411185924_add_database_identifier_to_databases.rb +6 -0
- data/natural-backend/db/migrate/20180412002908_add_dbid_to_rows.rb +5 -0
- data/natural-backend/db/migrate/20180412012433_create_queries.rb +11 -0
- data/natural-backend/db/migrate/20180429151758_create_users.rb +10 -0
- data/natural-backend/db/migrate/20180430094604_add_user_ref_to_projects.rb +5 -0
- data/natural-backend/db/migrate/20180430102945_add_user_ref_to_databases.rb +5 -0
- data/natural-backend/db/migrate/20180430102955_add_user_ref_to_tables.rb +5 -0
- data/natural-backend/db/migrate/20180430103004_add_user_ref_to_rows.rb +5 -0
- data/natural-backend/db/migrate/20180430103015_add_user_ref_to_columns.rb +5 -0
- data/natural-backend/db/migrate/20180430103024_add_user_ref_to_row_values.rb +5 -0
- data/natural-backend/db/migrate/20180430141537_add_api_token_projects.rb +5 -0
- data/natural-backend/db/schema.rb +112 -0
- data/natural-backend/db/seeds.rb +7 -0
- data/natural-backend/lib/database_manager/database_manager.rb +59 -0
- data/natural-backend/lib/database_manager/lib/connection.rb +49 -0
- data/natural-backend/lib/database_manager/lib/database.rb +65 -0
- data/natural-backend/lib/database_manager/lib/database_user.rb +46 -0
- data/natural-backend/lib/database_manager/lib/table.rb +129 -0
- data/natural-backend/public/assets/natural-frontend-598145a86019fc7faa2e0386ec6cb276.css +6 -0
- data/natural-backend/public/assets/natural-frontend-8e453ff9db7fc3a47e6d9e3de45aa19e.js +31 -0
- data/natural-backend/public/assets/vendor-7ffaee0528b64f886e9d1860fc719b5a.js +7359 -0
- data/natural-backend/public/assets/vendor-8bd8fa913b4f7f8b27f086c7bfd98b7f.css +1 -0
- data/natural-backend/public/index.html +26 -0
- data/natural-backend/public/robots.txt +3 -0
- data/natural-backend/roadmap.md +25 -0
- data/natural-backend/test/controllers/authentication_controller_test.rb +7 -0
- data/natural-backend/test/controllers/columns_controller_test.rb +38 -0
- data/natural-backend/test/controllers/databases_controller_test.rb +38 -0
- data/natural-backend/test/controllers/ember_controller_test.rb +7 -0
- data/natural-backend/test/controllers/projects_controller_test.rb +38 -0
- data/natural-backend/test/controllers/queries_controller_test.rb +38 -0
- data/natural-backend/test/controllers/row_values_controller_test.rb +38 -0
- data/natural-backend/test/controllers/rows_controller_test.rb +38 -0
- data/natural-backend/test/controllers/tables_controller_test.rb +38 -0
- data/natural-backend/test/fixtures/columns.yml +11 -0
- data/natural-backend/test/fixtures/databases.yml +9 -0
- data/natural-backend/test/fixtures/projects.yml +7 -0
- data/natural-backend/test/fixtures/queries.yml +9 -0
- data/natural-backend/test/fixtures/row_values.yml +11 -0
- data/natural-backend/test/fixtures/rows.yml +7 -0
- data/natural-backend/test/fixtures/tables.yml +7 -0
- data/natural-backend/test/fixtures/users.yml +9 -0
- data/natural-backend/test/jobs/add_column_job_test.rb +7 -0
- data/natural-backend/test/jobs/create_database_job_test.rb +7 -0
- data/natural-backend/test/jobs/create_database_user_job_test.rb +7 -0
- data/natural-backend/test/jobs/create_table_job_test.rb +7 -0
- data/natural-backend/test/jobs/delete_row_job_test.rb +7 -0
- data/natural-backend/test/jobs/delete_value_job_test.rb +7 -0
- data/natural-backend/test/jobs/destroy_database_job_test.rb +7 -0
- data/natural-backend/test/jobs/destroy_database_user_job_test.rb +7 -0
- data/natural-backend/test/jobs/destroy_table_job_test.rb +7 -0
- data/natural-backend/test/jobs/insert_value_job_test.rb +7 -0
- data/natural-backend/test/jobs/run_query_job_test.rb +7 -0
- data/natural-backend/test/jobs/sync_db_job_test.rb +7 -0
- data/natural-backend/test/jobs/update_value_job_test.rb +7 -0
- data/natural-backend/test/lib/database_manager/database_manager_test.rb +21 -0
- data/natural-backend/test/lib/database_manager/lib/database_test.rb +28 -0
- data/natural-backend/test/lib/database_manager/lib/database_user_test.rb +43 -0
- data/natural-backend/test/lib/database_manager/lib/table_test.rb +46 -0
- data/natural-backend/test/models/column_test.rb +7 -0
- data/natural-backend/test/models/database_test.rb +7 -0
- data/natural-backend/test/models/project_test.rb +7 -0
- data/natural-backend/test/models/query_test.rb +7 -0
- data/natural-backend/test/models/row_test.rb +7 -0
- data/natural-backend/test/models/row_value_test.rb +7 -0
- data/natural-backend/test/models/table_test.rb +7 -0
- data/natural-backend/test/models/user_test.rb +7 -0
- data/natural-backend/test/test_helper.rb +10 -0
- data/natural-frontend/LICENSE +21 -0
- data/natural-frontend/README.md +3 -0
- data/natural-frontend/app/adapters/application.js +33 -0
- data/natural-frontend/app/app.js +18 -0
- data/natural-frontend/app/components/column-editor.js +41 -0
- data/natural-frontend/app/components/row-editor.js +21 -0
- data/natural-frontend/app/components/row-value-editor.js +49 -0
- data/natural-frontend/app/controllers/application.js +11 -0
- data/natural-frontend/app/controllers/authenticate.js +16 -0
- data/natural-frontend/app/controllers/databases.js +22 -0
- data/natural-frontend/app/controllers/projects.js +18 -0
- data/natural-frontend/app/controllers/table.js +12 -0
- data/natural-frontend/app/controllers/table/rows.js +23 -0
- data/natural-frontend/app/controllers/tables.js +22 -0
- data/natural-frontend/app/helpers/plus-one.js +8 -0
- data/natural-frontend/app/index.html +25 -0
- data/natural-frontend/app/mixins/application-route-auth-mixin.js +8 -0
- data/natural-frontend/app/mixins/authenticated-route-mixin.js +10 -0
- data/natural-frontend/app/models/column.js +9 -0
- data/natural-frontend/app/models/database.js +9 -0
- data/natural-frontend/app/models/project.js +8 -0
- data/natural-frontend/app/models/row-value.js +8 -0
- data/natural-frontend/app/models/row.js +8 -0
- data/natural-frontend/app/models/table.js +9 -0
- data/natural-frontend/app/resolver.js +4 -0
- data/natural-frontend/app/router.js +22 -0
- data/natural-frontend/app/routes/application.js +5 -0
- data/natural-frontend/app/routes/authenticate.js +4 -0
- data/natural-frontend/app/routes/databases.js +15 -0
- data/natural-frontend/app/routes/function.js +20 -0
- data/natural-frontend/app/routes/functions.js +22 -0
- data/natural-frontend/app/routes/index.js +9 -0
- data/natural-frontend/app/routes/projects.js +8 -0
- data/natural-frontend/app/routes/table.js +17 -0
- data/natural-frontend/app/routes/table/rows.js +19 -0
- data/natural-frontend/app/routes/tables.js +16 -0
- data/natural-frontend/app/serializers/application.js +10 -0
- data/natural-frontend/app/services/authentication.js +38 -0
- data/natural-frontend/app/styles/app.scss +58 -0
- data/natural-frontend/app/templates/application.hbs +32 -0
- data/natural-frontend/app/templates/authenticate.hbs +7 -0
- data/natural-frontend/app/templates/components/api-usage-documentation.hbs +36 -0
- data/natural-frontend/app/templates/components/column-editor.hbs +37 -0
- data/natural-frontend/app/templates/components/row-editor.hbs +21 -0
- data/natural-frontend/app/templates/components/row-value-editor.hbs +1 -0
- data/natural-frontend/app/templates/databases.hbs +37 -0
- data/natural-frontend/app/templates/function.hbs +9 -0
- data/natural-frontend/app/templates/functions.hbs +30 -0
- data/natural-frontend/app/templates/index.hbs +15 -0
- data/natural-frontend/app/templates/projects.hbs +37 -0
- data/natural-frontend/app/templates/table.hbs +10 -0
- data/natural-frontend/app/templates/table/rows.hbs +23 -0
- data/natural-frontend/app/templates/tables.hbs +32 -0
- data/natural-frontend/config/environment.js +61 -0
- data/natural-frontend/config/targets.js +19 -0
- data/natural-frontend/deploy_rails_public.sh +6 -0
- data/natural-frontend/ember-cli-build.js +42 -0
- data/natural-frontend/package-lock.json +13288 -0
- data/natural-frontend/package.json +59 -0
- data/natural-frontend/public/robots.txt +3 -0
- data/natural-frontend/testem.js +20 -0
- data/natural-frontend/tests/index.html +33 -0
- data/natural-frontend/tests/integration/components/column-editor-test.js +27 -0
- data/natural-frontend/tests/integration/components/row-editor-test.js +27 -0
- data/natural-frontend/tests/integration/components/row-value-editor-test.js +27 -0
- data/natural-frontend/tests/integration/helpers/humanization-test.js +18 -0
- data/natural-frontend/tests/test-helper.js +9 -0
- data/natural-frontend/tests/unit/controllers/databases-test.js +13 -0
- data/natural-frontend/tests/unit/controllers/projects-test.js +13 -0
- data/natural-frontend/tests/unit/controllers/table-test.js +13 -0
- data/natural-frontend/tests/unit/controllers/table/rows-test.js +12 -0
- data/natural-frontend/tests/unit/controllers/tables-test.js +13 -0
- data/natural-frontend/tests/unit/models/column-test.js +15 -0
- data/natural-frontend/tests/unit/models/database-test.js +15 -0
- data/natural-frontend/tests/unit/models/project-test.js +15 -0
- data/natural-frontend/tests/unit/models/row-test.js +15 -0
- data/natural-frontend/tests/unit/models/rwo-value-test.js +15 -0
- data/natural-frontend/tests/unit/models/table-test.js +15 -0
- data/natural-frontend/tests/unit/routes/authenticate-test.js +11 -0
- data/natural-frontend/tests/unit/routes/databases-test.js +12 -0
- data/natural-frontend/tests/unit/routes/projects-test.js +12 -0
- data/natural-frontend/tests/unit/routes/table-test.js +12 -0
- data/natural-frontend/tests/unit/routes/table/rows-test.js +11 -0
- data/natural-frontend/tests/unit/routes/tables-test.js +12 -0
- metadata +303 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "NaturalDB",
|
|
3
|
+
"description": "PostgreSQL Server",
|
|
4
|
+
"repository": "https://github.com/LemonAndroid/natural-backend",
|
|
5
|
+
"keywords": ["postgresql", "ember", "ruby", "rubyonrails", "rails"],
|
|
6
|
+
"scripts": {
|
|
7
|
+
"postdeploy": "./bin/run_migrations.sh"
|
|
8
|
+
},
|
|
9
|
+
"addons": [
|
|
10
|
+
"heroku-redis",
|
|
11
|
+
{
|
|
12
|
+
"plan": "heroku-postgresql",
|
|
13
|
+
"options": {
|
|
14
|
+
"version": "9.5"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"formation": {
|
|
19
|
+
"web": {
|
|
20
|
+
"quantity": 1,
|
|
21
|
+
"size": "free"
|
|
22
|
+
},
|
|
23
|
+
"worker": {
|
|
24
|
+
"quantity": 1,
|
|
25
|
+
"size": "free"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class BaseCommand
|
|
2
|
+
attr_reader :result, :status
|
|
3
|
+
|
|
4
|
+
def self.call(*args)
|
|
5
|
+
new(*args).call
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def call
|
|
9
|
+
@result = nil
|
|
10
|
+
run
|
|
11
|
+
self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def success?
|
|
15
|
+
errors.empty?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def errors
|
|
19
|
+
@errors ||= ActiveModel::Errors.new(self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def initialize(*_)
|
|
25
|
+
not_implemented
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run
|
|
29
|
+
not_implemented
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Authentication implementation mostly copied and slightly adapted from
|
|
2
|
+
# https://paweljw.github.io/2017/07/rails-5.1-api-app-part-4-authentication-and-authorization/
|
|
3
|
+
# Big thanks!
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CreateNewOrAuthenticateUser < BaseCommand
|
|
7
|
+
class UserNotPersistedError < StandardError;end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
attr_reader :email, :password
|
|
12
|
+
|
|
13
|
+
def initialize(email, password)
|
|
14
|
+
@email = email
|
|
15
|
+
@password = password
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def user
|
|
19
|
+
@user ||= find_or_create_user
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def find_or_create_user
|
|
23
|
+
u = User.find_or_initialize_by(email: email)
|
|
24
|
+
|
|
25
|
+
if u.new_record?
|
|
26
|
+
persist_user(u)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
u
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def persist_user(u)
|
|
33
|
+
u.password = @password
|
|
34
|
+
unless u.save
|
|
35
|
+
self.errors += u.errors
|
|
36
|
+
self.status = 500
|
|
37
|
+
raise UserNotPersistedError
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def password_valid?
|
|
42
|
+
user && user.authenticate(password)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def run
|
|
46
|
+
if password_valid?
|
|
47
|
+
@result = JwtService.encode(content)
|
|
48
|
+
else
|
|
49
|
+
errors.add(:base, "Invalid credentials")
|
|
50
|
+
end
|
|
51
|
+
rescue UserNotPersistedError
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def content
|
|
55
|
+
{
|
|
56
|
+
user_id: user.id,
|
|
57
|
+
exp: 24.hours.from_now.to_i
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Authentication implementation mostly copied and slightly adapted from
|
|
2
|
+
# https://paweljw.github.io/2017/07/rails-5.1-api-app-part-4-authentication-and-authorization/
|
|
3
|
+
# Big thanks!
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CreateProjectAuthenticationTokenCommand < BaseCommand
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
attr_reader :project
|
|
10
|
+
|
|
11
|
+
def initialize(project)
|
|
12
|
+
@project = project
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def run
|
|
16
|
+
@result = JwtService.encode(content)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def content
|
|
20
|
+
{
|
|
21
|
+
project_id: project.id,
|
|
22
|
+
exp: 1.year.from_now.to_i
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Authentication implementation mostly copied and slightly adapted from
|
|
2
|
+
# https://paweljw.github.io/2017/07/rails-5.1-api-app-part-4-authentication-and-authorization/
|
|
3
|
+
# Big thanks!
|
|
4
|
+
|
|
5
|
+
class DecodeAuthenticationCommand < BaseCommand
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
attr_reader :headers
|
|
9
|
+
|
|
10
|
+
def initialize(headers)
|
|
11
|
+
@headers = headers
|
|
12
|
+
@user = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def run
|
|
16
|
+
return unless token_present?
|
|
17
|
+
@result = user if user
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def user
|
|
21
|
+
@user ||= User.find_by(id: decoded_id)
|
|
22
|
+
@user || errors.add(:token, "Token invalid") && nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def token_present?
|
|
26
|
+
token.present? && token_contents.present?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def token
|
|
30
|
+
return authentication_header.split(' ').last if authentication_header.present?
|
|
31
|
+
errors.add(:token, "Token missing")
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def authentication_header
|
|
36
|
+
headers['Authentication']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def token_contents
|
|
40
|
+
@token_contents ||= begin
|
|
41
|
+
decoded = JwtService.decode(token)
|
|
42
|
+
errors.add(:token, "Token expired") unless decoded
|
|
43
|
+
decoded
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def decoded_id
|
|
48
|
+
token_contents['user_id']
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Authentication implementation mostly copied and slightly adapted from
|
|
2
|
+
# https://paweljw.github.io/2017/07/rails-5.1-api-app-part-4-authentication-and-authorization/
|
|
3
|
+
# Big thanks!
|
|
4
|
+
|
|
5
|
+
class DecodeProjectAuthenticationTokenCommand < BaseCommand
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
attr_reader :headers
|
|
9
|
+
|
|
10
|
+
def initialize(headers)
|
|
11
|
+
@headers = headers
|
|
12
|
+
@project = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def run
|
|
16
|
+
return unless token_present?
|
|
17
|
+
@result = project if project
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def project
|
|
21
|
+
@project ||= Project.find_by(id: decoded_id)
|
|
22
|
+
@project || errors.add(:token, "Token invalid") && nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def token_present?
|
|
26
|
+
token.present? && token_contents.present?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def token
|
|
30
|
+
return authentication_header.split(' ').last if authentication_header.present?
|
|
31
|
+
errors.add(:token, "Token missing")
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def authentication_header
|
|
36
|
+
headers['Authentication']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def token_contents
|
|
40
|
+
@token_contents ||= begin
|
|
41
|
+
decoded = JwtService.decode(token)
|
|
42
|
+
Rails.logger.info(decoded)
|
|
43
|
+
errors.add(:token, "Token expired") unless decoded
|
|
44
|
+
decoded
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def decoded_id
|
|
49
|
+
token_contents['project_id']
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Authentication implementation mostly copied and slightly adapted from
|
|
2
|
+
# https://paweljw.github.io/2017/07/rails-5.1-api-app-part-4-authentication-and-authorization/
|
|
3
|
+
# Big thanks!
|
|
4
|
+
|
|
5
|
+
class AuthenticationController < ApplicationController
|
|
6
|
+
skip_before_action :authenticate_user
|
|
7
|
+
|
|
8
|
+
def authenticate
|
|
9
|
+
token_command = CreateNewOrAuthenticateUser.call(*params.slice(:email, :password).values)
|
|
10
|
+
|
|
11
|
+
if token_command.success?
|
|
12
|
+
render json: { token: token_command.result }
|
|
13
|
+
else
|
|
14
|
+
render json: { error: token_command.errors }, status: token_command.status
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class ColumnsController < ApplicationController
|
|
2
|
+
before_action :set_column, only: [:show, :update, :destroy]
|
|
3
|
+
|
|
4
|
+
# GET /columns
|
|
5
|
+
def index
|
|
6
|
+
@columns = current_user.columns.all
|
|
7
|
+
|
|
8
|
+
render json: @columns
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# GET /columns/1
|
|
12
|
+
def show
|
|
13
|
+
render json: @column
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# POST /columns
|
|
17
|
+
def create
|
|
18
|
+
@column = current_user.columns.build(column_params)
|
|
19
|
+
|
|
20
|
+
if @column.save
|
|
21
|
+
render json: @column, status: :created, location: @column
|
|
22
|
+
else
|
|
23
|
+
render json: @column.errors, status: :unprocessable_entity
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# PATCH/PUT /columns/1
|
|
28
|
+
def update
|
|
29
|
+
if @column.update(column_params)
|
|
30
|
+
render json: @column
|
|
31
|
+
else
|
|
32
|
+
render json: @column.errors, status: :unprocessable_entity
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# DELETE /columns/1
|
|
37
|
+
def destroy
|
|
38
|
+
@column.destroy
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
43
|
+
def set_column
|
|
44
|
+
@column = current_user.columns.find(params[:id])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Only allow a trusted parameter "white list" through.
|
|
48
|
+
def column_params
|
|
49
|
+
ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [:table, :name, :type])
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Authentication implementation mostly copied and slightly adapted from
|
|
2
|
+
# https://paweljw.github.io/2017/07/rails-5.1-api-app-part-4-authentication-and-authorization/
|
|
3
|
+
# Big thanks!
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NotAuthenticatedException < StandardError; end
|
|
7
|
+
|
|
8
|
+
module TokenAuthenticatable
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
included do
|
|
12
|
+
attr_reader :current_user
|
|
13
|
+
|
|
14
|
+
before_action :authenticate_user
|
|
15
|
+
|
|
16
|
+
rescue_from NotAuthenticatedException, with: -> { render json: { error: 'Not Authenticated' }, status: 403 }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def authenticate_user
|
|
22
|
+
decode_authentication_command = DecodeAuthenticationCommand.call(request.headers)
|
|
23
|
+
@current_user = decode_authentication_command.result
|
|
24
|
+
raise NotAuthenticatedException unless @current_user
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class DatabasesController < ApplicationController
|
|
2
|
+
before_action :set_database, only: [:show, :update, :destroy]
|
|
3
|
+
|
|
4
|
+
# GET /databases
|
|
5
|
+
def index
|
|
6
|
+
@databases = current_user.databases.all
|
|
7
|
+
|
|
8
|
+
render json: @databases
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# GET /databases/1
|
|
12
|
+
def show
|
|
13
|
+
render json: @database
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# POST /databases
|
|
17
|
+
def create
|
|
18
|
+
@database = current_user.databases.build(database_params)
|
|
19
|
+
|
|
20
|
+
if @database.save
|
|
21
|
+
render json: @database, status: :created, location: @database
|
|
22
|
+
else
|
|
23
|
+
render json: @database.errors, status: :unprocessable_entity
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# PATCH/PUT /databases/1
|
|
28
|
+
def update
|
|
29
|
+
if @database.update(database_params)
|
|
30
|
+
render json: @database
|
|
31
|
+
else
|
|
32
|
+
render json: @database.errors, status: :unprocessable_entity
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# DELETE /databases/1
|
|
37
|
+
def destroy
|
|
38
|
+
@database.destroy
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
43
|
+
def set_database
|
|
44
|
+
@database = current_user.databases.find(params[:id])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Only allow a trusted parameter "white list" through.
|
|
48
|
+
def database_params
|
|
49
|
+
ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [:name, :project])
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class ProjectsController < ApplicationController
|
|
2
|
+
before_action :set_project, only: [:show, :update, :destroy]
|
|
3
|
+
|
|
4
|
+
# GET /projects
|
|
5
|
+
def index
|
|
6
|
+
@projects = current_user.projects.all
|
|
7
|
+
|
|
8
|
+
render json: @projects
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# GET /projects/1
|
|
12
|
+
def show
|
|
13
|
+
render json: @project
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# POST /projects
|
|
17
|
+
def create
|
|
18
|
+
@project = current_user.projects.build(project_params)
|
|
19
|
+
|
|
20
|
+
if @project.save
|
|
21
|
+
render json: @project, status: :created, location: @project
|
|
22
|
+
else
|
|
23
|
+
render json: @project.errors, status: :unprocessable_entity
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# PATCH/PUT /projects/1
|
|
28
|
+
def update
|
|
29
|
+
if @project.update(project_params)
|
|
30
|
+
render json: @project
|
|
31
|
+
else
|
|
32
|
+
render json: @project.errors, status: :unprocessable_entity
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# DELETE /projects/1
|
|
37
|
+
def destroy
|
|
38
|
+
@project.destroy
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
43
|
+
def set_project
|
|
44
|
+
@project = current_user.projects.find(params[:id])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Only allow a trusted parameter "white list" through.
|
|
48
|
+
def project_params
|
|
49
|
+
ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [:name])
|
|
50
|
+
end
|
|
51
|
+
end
|