mks_auth 1.0.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 (98) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/mks_auth_manifest.js +2 -0
  6. data/app/assets/javascripts/mks_auth/application.js +13 -0
  7. data/app/assets/stylesheets/mks_auth/application.css +15 -0
  8. data/app/controllers/mks/auth/access_controller.rb +51 -0
  9. data/app/controllers/mks/auth/application_controller.rb +25 -0
  10. data/app/controllers/mks/auth/application_modules_controller.rb +60 -0
  11. data/app/controllers/mks/auth/user_roles_controller.rb +52 -0
  12. data/app/controllers/mks/auth/users_controller.rb +67 -0
  13. data/app/helpers/mks/auth/access_helper.rb +47 -0
  14. data/app/helpers/mks/auth/application_helper.rb +10 -0
  15. data/app/jobs/mks_auth/application_job.rb +4 -0
  16. data/app/mailers/mks_auth/application_mailer.rb +6 -0
  17. data/app/models/mks/auth/application_module.rb +13 -0
  18. data/app/models/mks/auth/application_record.rb +7 -0
  19. data/app/models/mks/auth/menu.rb +12 -0
  20. data/app/models/mks/auth/user.rb +24 -0
  21. data/app/models/mks/auth/user_role.rb +11 -0
  22. data/config/routes.rb +32 -0
  23. data/db/migrate/20161029065810_create_mks_auth_application_modules.rb +10 -0
  24. data/db/migrate/20161029065959_create_mks_auth_users.rb +16 -0
  25. data/db/migrate/20161029070807_create_mks_auth_user_roles.rb +9 -0
  26. data/db/migrate/20161029071047_create_mks_users_user_roles.rb +11 -0
  27. data/db/migrate/20161029072256_create_mks_auth_menus.rb +17 -0
  28. data/db/migrate/20161029074023_create_mks_menus_user_roles.rb +11 -0
  29. data/lib/mks/auth.rb +4 -0
  30. data/lib/mks/auth/engine.rb +28 -0
  31. data/lib/mks/auth/version.rb +5 -0
  32. data/lib/mks_auth.rb +2 -0
  33. data/lib/tasks/mks_auth_tasks.rake +4 -0
  34. data/spec/controllers/mks/auth/users_controller_spec.rb +20 -0
  35. data/spec/dummy/Rakefile +6 -0
  36. data/spec/dummy/app/assets/config/manifest.js +5 -0
  37. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  38. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  39. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  40. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  41. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  44. data/spec/dummy/app/jobs/application_job.rb +2 -0
  45. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  46. data/spec/dummy/app/models/application_record.rb +3 -0
  47. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  48. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  49. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  50. data/spec/dummy/bin/bundle +3 -0
  51. data/spec/dummy/bin/rails +4 -0
  52. data/spec/dummy/bin/rake +4 -0
  53. data/spec/dummy/bin/setup +34 -0
  54. data/spec/dummy/bin/update +29 -0
  55. data/spec/dummy/config.ru +5 -0
  56. data/spec/dummy/config/application.rb +23 -0
  57. data/spec/dummy/config/boot.rb +5 -0
  58. data/spec/dummy/config/cable.yml +9 -0
  59. data/spec/dummy/config/database.yml +23 -0
  60. data/spec/dummy/config/environment.rb +5 -0
  61. data/spec/dummy/config/environments/development.rb +54 -0
  62. data/spec/dummy/config/environments/production.rb +86 -0
  63. data/spec/dummy/config/environments/test.rb +42 -0
  64. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  65. data/spec/dummy/config/initializers/assets.rb +11 -0
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  69. data/spec/dummy/config/initializers/inflections.rb +16 -0
  70. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  71. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  72. data/spec/dummy/config/initializers/session_store.rb +3 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/spec/dummy/config/locales/en.yml +23 -0
  75. data/spec/dummy/config/puma.rb +47 -0
  76. data/spec/dummy/config/routes.rb +3 -0
  77. data/spec/dummy/config/secrets.yml +22 -0
  78. data/spec/dummy/config/spring.rb +6 -0
  79. data/spec/dummy/db/schema.rb +75 -0
  80. data/spec/dummy/log/development.log +3 -0
  81. data/spec/dummy/public/404.html +67 -0
  82. data/spec/dummy/public/422.html +67 -0
  83. data/spec/dummy/public/500.html +66 -0
  84. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  85. data/spec/dummy/public/apple-touch-icon.png +0 -0
  86. data/spec/dummy/public/favicon.ico +0 -0
  87. data/spec/factories/application_modules.rb +6 -0
  88. data/spec/factories/menus.rb +10 -0
  89. data/spec/factories/user_roles.rb +17 -0
  90. data/spec/factories/users.rb +28 -0
  91. data/spec/models/mks/auth/application_module_spec.rb +36 -0
  92. data/spec/models/mks/auth/menu_spec.rb +16 -0
  93. data/spec/models/mks/auth/user_role_spec.rb +32 -0
  94. data/spec/models/mks/auth/user_spec.rb +46 -0
  95. data/spec/rails_helper.rb +57 -0
  96. data/spec/spec_helper.rb +109 -0
  97. data/spec/support/factory_girl.rb +5 -0
  98. metadata +302 -0
@@ -0,0 +1,4 @@
1
+ module MksAuth
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module MksAuth
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module Mks
2
+ module Auth
3
+ class ApplicationModule < ApplicationRecord
4
+ #self.table_name = 'mks_application_modules'
5
+
6
+ validates :code, presence: true
7
+ validates :code, presence: true, uniqueness: true
8
+
9
+ has_many :users, class_name: 'Mks::Auth::User'
10
+ has_many :menus, class_name: 'Mks::Auth::Menu'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Mks
2
+ module Auth
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Mks
2
+ module Auth
3
+ class Menu < ApplicationRecord
4
+ # self.table_name = 'mks_menus'
5
+
6
+ belongs_to :application_module, class_name: 'Mks::Auth::ApplicationModule'
7
+ belongs_to :parent, class_name: 'Mks::Auth::Menu', optional: true
8
+ has_many :children, class_name: 'Mks::Auth::Menu', :foreign_key => 'parent_id'
9
+ has_and_belongs_to_many :roles, class_name: 'Mks::Auth::UserRole', :join_table => :mks_auth_menus_user_roles
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module Mks
2
+ module Auth
3
+ class User < ApplicationRecord
4
+ # self.table_name = 'mks_users'
5
+
6
+ belongs_to :application_module, class_name: 'Mks::Auth::ApplicationModule'
7
+ has_and_belongs_to_many :roles, class_name: 'Mks::Auth::UserRole', join_table: :mks_auth_users_user_roles
8
+ has_secure_password
9
+
10
+ before_save { email.downcase! }
11
+
12
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
13
+ validates :first_name, presence: true, length: {maximum: 30}
14
+ validates :last_name, presence: true, length: {maximum: 30}
15
+ validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: {case_sensitive: false}
16
+ validates :password, length: { minimum: 6 }
17
+ validates :active, presence: true
18
+
19
+ def full_name
20
+ "#{first_name} #{last_name}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Mks
2
+ module Auth
3
+ class UserRole < ApplicationRecord
4
+ # self.table_name = 'mks_user_roles'
5
+
6
+ validates :name, presence: true, uniqueness: true
7
+ has_and_belongs_to_many :users, :join_table => :mks_auth_users_user_roles
8
+ has_and_belongs_to_many :menus, :join_table => :mks_auth_menus_user_roles
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ Mks::Auth::Engine.routes.draw do
2
+ get '/csrf_token', to: 'access#csrf_token'
3
+
4
+ get '/attempt_login', to: 'access#attempt_login'
5
+
6
+ get '/logout', to: 'access#logout'
7
+
8
+ get '/menu', to: 'access#menu'
9
+
10
+ get '/check_login', to: 'access#check_login'
11
+
12
+ post '/login', to: 'access#attempt_login'
13
+
14
+ resources :application_modules
15
+
16
+ # get '/users', to: 'users#index'
17
+
18
+ resources :users, except: [:new, :edit, :show, :destroy]
19
+
20
+ get '/users/roles', controller: :users, action: :roles
21
+
22
+ get '/users/fetch_by_role', to: 'users#fetch_by_role'
23
+
24
+ # get '/user_roles', to: 'user_roles#index'
25
+
26
+ resources :user_roles, except: [:new, :edit, :show, :destroy]
27
+
28
+ post '/assign_roles', to: 'user_roles#assign_roles'
29
+
30
+ get '/assigned_roles/:user_id', to: 'user_roles#get_assigned_roles'
31
+
32
+ end
@@ -0,0 +1,10 @@
1
+ class CreateMksAuthApplicationModules < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :mks_auth_application_modules do |t|
4
+ t.string :code, unique: true, null: false
5
+ t.string :name, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ class CreateMksAuthUsers < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :mks_auth_users do |t|
4
+ t.string :first_name, null: false
5
+ t.string :last_name, null: false
6
+ t.string :email, null: false
7
+ t.boolean :active, null: false, default: true
8
+ t.references :application_module, index: true
9
+ t.string :password_digest
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_foreign_key :mks_auth_users, :mks_auth_application_modules, :column => :application_module_id
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ class CreateMksAuthUserRoles < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :mks_auth_user_roles do |t|
4
+ t.string :name, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateMksUsersUserRoles < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :mks_auth_users_user_roles, id: false do |t|
4
+ t.references :user, index: false
5
+ t.references :user_role, index: false
6
+ end
7
+ add_index :mks_auth_users_user_roles, [:user_id, :user_role_id]
8
+ add_foreign_key :mks_auth_users_user_roles, :mks_auth_users, :column => :user_id
9
+ add_foreign_key :mks_auth_users_user_roles, :mks_auth_user_roles, :column => :user_role_id
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ class CreateMksAuthMenus < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :mks_auth_menus do |t|
4
+ t.string :text, null: false
5
+ t.string :icon_cls
6
+ t.string :class_name
7
+ t.string :location
8
+ t.integer :parent_id, index: true
9
+ t.references :application_module, index: true
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_foreign_key :mks_auth_menus, :mks_auth_menus, :column => :parent_id
15
+ add_foreign_key :mks_auth_menus, :mks_auth_application_modules, :column => :application_module_id
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class CreateMksMenusUserRoles < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :mks_auth_menus_user_roles do |t|
4
+ t.references :menu, index: false
5
+ t.references :user_role, index: false
6
+ end
7
+ add_index :mks_auth_menus_user_roles, [:menu_id, :user_role_id]
8
+ add_foreign_key :mks_auth_menus_user_roles, :mks_auth_menus, :column => :menu_id
9
+ add_foreign_key :mks_auth_menus_user_roles, :mks_auth_user_roles, :column => :user_role_id
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Mks
2
+ module Auth
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ module Mks
2
+ module Auth
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Mks::Auth
5
+
6
+ initializer :append_migrations do |app|
7
+ unless app.root.to_s.match root.to_s
8
+ if app.config.app_code == 'PSH'
9
+ config.paths['db/migrate'].expanded.each do |expanded_path|
10
+ app.config.paths['db/migrate'] << expanded_path
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ initializer 'mks_auth.factories', :after => 'factory_girl.set_factory_paths' do
17
+ FactoryGirl.definition_file_paths << File.expand_path('../../../../spec/factories', __FILE__) if defined?(FactoryGirl)
18
+ end
19
+
20
+ config.generators do |g|
21
+ g.test_framework :rspec, :fixture => false
22
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
23
+ g.assets false
24
+ g.helper false
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Mks
2
+ module Auth
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'mks/auth'
2
+ require 'mks/auth/engine'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :mks_auth do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,20 @@
1
+ require 'rails_helper'
2
+
3
+ module Mks
4
+ module Auth
5
+ RSpec.describe UsersController, type: :controller do
6
+ routes { Mks::Auth::Engine.routes }
7
+
8
+ describe 'GET #roles' do
9
+ it 'gets roles of a user' do
10
+ u = create(:user)
11
+ roles = [create(:user_role), create(:user_role)]
12
+ u.roles << roles
13
+ get :roles, session: { user_id: u.id }
14
+ result = JSON(response.body)
15
+ expect(result['data'].count).to eq 2
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,5 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
5
+ //= link mks_auth_manifest.js
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # puts "\n== Copying sample files =="
22
+ # unless File.exist?('config/database.yml')
23
+ # cp 'config/database.yml.sample', 'config/database.yml'
24
+ # end
25
+
26
+ puts "\n== Preparing database =="
27
+ system! 'bin/rails db:setup'
28
+
29
+ puts "\n== Removing old logs and tempfiles =="
30
+ system! 'bin/rails log:clear tmp:clear'
31
+
32
+ puts "\n== Restarting application server =="
33
+ system! 'bin/rails restart'
34
+ end