mks_auth 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00f9566b714b149aae36355605a02e5c977f54e76653f1a735a2c6addaaccda9
4
- data.tar.gz: 6339491d2b5f75d1aee38ee24f0191c582a37bf1a4efff8e1be3aaa2a9b1b82b
3
+ metadata.gz: 4bdc0cf512e5d2a6de283112393abb047c798ebef5d266f60229e2ec121cf22a
4
+ data.tar.gz: 9a00a2b3526c773f56d591125d4d9d55c79193182b0e352360275a8842fdf94e
5
5
  SHA512:
6
- metadata.gz: 147a3f580662304eea9ffb66849df3ad20b04d66bc48e0461764f6f23acaf4ff04f69472888c70be0dab879a77cda4ba3bd4b76a72ec9186dd886cd555958d01
7
- data.tar.gz: 447220a79f6bb24a9ecf30aab5f3330bea8cf8707c498c1682c9ff2783134689ebb3e78aa9cc4e5ccb0951038a235fa056525a95d72dec6af6337489914b3eae
6
+ metadata.gz: 5e6d94b2e805928d8b9502811a3adf8b10379ef7ea3180e081b279753318c65b1fe59716739e97aa54e6163c41dd9c1a293116d4dba24fb7ad5901c935b0bd5e
7
+ data.tar.gz: bc573590f04e6135a4dbcc067b74d90e5a44a2378767ffe8c307868140411f997eb1e589686b92d8c0eb8bb7587c7d9b221a14e88c67e7ccf98bbb84afdaa204
@@ -1,4 +1,5 @@
1
1
  require 'mks/auth/token_auth'
2
+ require 'mks/common/methodresponse'
2
3
 
3
4
  module Mks
4
5
  module Auth
@@ -35,22 +35,18 @@ module Mks
35
35
  app_module = ApplicationModule.find_by(code: app_code)
36
36
  @user.application_modules = [app_module]
37
37
  if @user.save
38
- response = { success: true, message: 'User saved successfully' }
38
+ render json: Mks::Common::MethodResponse.success_response(@user)
39
39
  else
40
- errors = Mks::Common::Util.error_messages @user, 'User'
41
- response = { success: false, errors: errors }
40
+ render json: Mks::Common::MethodResponse.failure_response(@user), status: :uprocessable_entity
42
41
  end
43
- render json: response
44
42
  end
45
43
 
46
44
  def update
47
45
  if @user.update(user_params)
48
- response = { success: true, message: 'User updated successfully' }
46
+ render json: Mks::Common::MethodResponse.success_response(@user)
49
47
  else
50
- errors = Mks::Common::Util.error_messages @user, 'User'
51
- response = { success: false, errors: errors }
48
+ render json: Mks::Common::MethodResponse.failure_response(@user), status: :unprocessable_entity
52
49
  end
53
- render json: response
54
50
  end
55
51
 
56
52
  def login
@@ -1,5 +1,5 @@
1
1
  module Mks
2
2
  module Auth
3
- VERSION = '1.0.7'.freeze
3
+ VERSION = '1.0.8'.freeze
4
4
  end
5
5
  end
@@ -39,6 +39,29 @@ module Mks
39
39
  end
40
40
  end
41
41
 
42
+ describe 'POST #create' do
43
+ it 'creates a new user' do
44
+ app_module = create(:application_module, code: 'DUMMY')
45
+ u = create(:user, application_modules: [app_module])
46
+ token = Mks::Auth::TokenAuth.issue(name: u.full_name, email: u.email, id: u.id)
47
+ request.headers['Authorization'] = "Bearer #{token}"
48
+
49
+ user = {
50
+ first_name: 'test user',
51
+ last_name: 'test user',
52
+ email: 'test@test.com',
53
+ password: 'test123',
54
+ password_confirmation: 'test123'
55
+ }
56
+
57
+ count = User.count
58
+ post :create, params: { user: user }
59
+ result = JSON(response.body)
60
+ expect(result['success']).to be_truthy
61
+ expect(User.count).to eq count + 1
62
+ end
63
+ end
64
+
42
65
  describe 'POST #save_selected_roles' do
43
66
  it 'saves selected user roles' do
44
67
  app_module = create(:application_module, code: 'DUMMY')
@@ -14008,3 +14008,175 @@ FOREIGN KEY ("user_id")
14008
14008
   (0.5ms) BEGIN
14009
14009
  ActiveRecord::InternalMetadata Update (0.8ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2018-07-27 07:48:39.435950"], ["key", "environment"]]
14010
14010
   (1.3ms) COMMIT
14011
+  (1.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14012
+  (0.7ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
14013
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14014
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
14015
+  (0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14016
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
14017
+  (119.9ms) DROP DATABASE IF EXISTS "construction_test"
14018
+  (354.6ms) CREATE DATABASE "construction_test" ENCODING = 'utf8'
14019
+ SQL (0.6ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
14020
+  (0.8ms) DROP TABLE IF EXISTS "mks_auth_application_modules" CASCADE
14021
+  (11.9ms) CREATE TABLE "mks_auth_application_modules" ("id" bigserial primary key, "code" character varying NOT NULL, "name" character varying NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14022
+  (0.5ms) DROP TABLE IF EXISTS "mks_auth_menus" CASCADE
14023
+  (7.0ms) CREATE TABLE "mks_auth_menus" ("id" bigserial primary key, "text" character varying NOT NULL, "icon_cls" character varying, "class_name" character varying, "location" character varying, "parent_id" integer, "application_module_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14024
+  (3.5ms) CREATE INDEX "index_mks_auth_menus_on_application_module_id" ON "mks_auth_menus" ("application_module_id")
14025
+  (5.4ms) CREATE INDEX "index_mks_auth_menus_on_parent_id" ON "mks_auth_menus" ("parent_id")
14026
+  (0.9ms) DROP TABLE IF EXISTS "mks_auth_menus_user_roles" CASCADE
14027
+  (5.2ms) CREATE TABLE "mks_auth_menus_user_roles" ("id" bigserial primary key, "menu_id" bigint, "user_role_id" bigint)
14028
+  (3.7ms) CREATE INDEX "index_mks_auth_menus_user_roles_on_menu_id_and_user_role_id" ON "mks_auth_menus_user_roles" ("menu_id", "user_role_id")
14029
+  (0.5ms) DROP TABLE IF EXISTS "mks_auth_user_roles" CASCADE
14030
+  (6.4ms) CREATE TABLE "mks_auth_user_roles" ("id" bigserial primary key, "name" character varying NOT NULL, "application_module_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14031
+  (3.4ms) CREATE INDEX "index_mks_auth_user_roles_on_application_module_id" ON "mks_auth_user_roles" ("application_module_id")
14032
+  (0.6ms) DROP TABLE IF EXISTS "mks_auth_users" CASCADE
14033
+  (6.8ms) CREATE TABLE "mks_auth_users" ("id" bigserial primary key, "first_name" character varying NOT NULL, "last_name" character varying NOT NULL, "email" character varying NOT NULL, "active" boolean DEFAULT TRUE NOT NULL, "password_digest" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14034
+  (0.6ms) DROP TABLE IF EXISTS "mks_auth_users_application_modules" CASCADE
14035
+  (1.8ms) CREATE TABLE "mks_auth_users_application_modules" ("user_id" bigint, "application_module_id" bigint)
14036
+  (3.3ms) CREATE INDEX "am_on_users_indx" ON "mks_auth_users_application_modules" ("user_id", "application_module_id")
14037
+  (0.5ms) DROP TABLE IF EXISTS "mks_auth_users_user_roles" CASCADE
14038
+  (1.8ms) CREATE TABLE "mks_auth_users_user_roles" ("user_id" bigint, "user_role_id" bigint)
14039
+  (4.8ms) CREATE INDEX "index_mks_auth_users_user_roles_on_user_id_and_user_role_id" ON "mks_auth_users_user_roles" ("user_id", "user_role_id")
14040
+  (3.2ms) ALTER TABLE "mks_auth_menus" ADD CONSTRAINT "fk_rails_e5dd25fcb5"
14041
+ FOREIGN KEY ("application_module_id")
14042
+ REFERENCES "mks_auth_application_modules" ("id")
14043
+ 
14044
+  (2.3ms) ALTER TABLE "mks_auth_menus" ADD CONSTRAINT "fk_rails_826b2757bc"
14045
+ FOREIGN KEY ("parent_id")
14046
+ REFERENCES "mks_auth_menus" ("id")
14047
+ 
14048
+  (2.3ms) ALTER TABLE "mks_auth_menus_user_roles" ADD CONSTRAINT "fk_rails_1807c05e36"
14049
+ FOREIGN KEY ("menu_id")
14050
+ REFERENCES "mks_auth_menus" ("id")
14051
+ 
14052
+  (2.4ms) ALTER TABLE "mks_auth_menus_user_roles" ADD CONSTRAINT "fk_rails_c24fca59c0"
14053
+ FOREIGN KEY ("user_role_id")
14054
+ REFERENCES "mks_auth_user_roles" ("id")
14055
+ 
14056
+  (2.1ms) ALTER TABLE "mks_auth_user_roles" ADD CONSTRAINT "fk_rails_b0b293e4e2"
14057
+ FOREIGN KEY ("application_module_id")
14058
+ REFERENCES "mks_auth_application_modules" ("id")
14059
+ 
14060
+  (2.2ms) ALTER TABLE "mks_auth_users_application_modules" ADD CONSTRAINT "fk_rails_b100f8542c"
14061
+ FOREIGN KEY ("application_module_id")
14062
+ REFERENCES "mks_auth_application_modules" ("id")
14063
+ 
14064
+  (2.4ms) ALTER TABLE "mks_auth_users_application_modules" ADD CONSTRAINT "fk_rails_1010e0182a"
14065
+ FOREIGN KEY ("user_id")
14066
+ REFERENCES "mks_auth_users" ("id")
14067
+ 
14068
+  (2.1ms) ALTER TABLE "mks_auth_users_user_roles" ADD CONSTRAINT "fk_rails_3dae904cd8"
14069
+ FOREIGN KEY ("user_role_id")
14070
+ REFERENCES "mks_auth_user_roles" ("id")
14071
+ 
14072
+  (2.1ms) ALTER TABLE "mks_auth_users_user_roles" ADD CONSTRAINT "fk_rails_7cc19890aa"
14073
+ FOREIGN KEY ("user_id")
14074
+ REFERENCES "mks_auth_users" ("id")
14075
+ 
14076
+  (7.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
14077
+  (1.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14078
+  (2.1ms) INSERT INTO "schema_migrations" (version) VALUES (20180201104912)
14079
+  (1.6ms) INSERT INTO "schema_migrations" (version) VALUES
14080
+ (20161029065810),
14081
+ (20161029065959),
14082
+ (20161029070807),
14083
+ (20161029071047),
14084
+ (20161029072256),
14085
+ (20161029074023);
14086
+
14087
+ 
14088
+  (8.6ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14089
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
14090
+  (0.6ms) BEGIN
14091
+ ActiveRecord::InternalMetadata Create (1.0ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2018-07-27 08:13:53.659484"], ["updated_at", "2018-07-27 08:13:53.659484"]]
14092
+  (1.2ms) COMMIT
14093
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
14094
+  (0.6ms) BEGIN
14095
+ ActiveRecord::InternalMetadata Update (0.8ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2018-07-27 08:13:53.666723"], ["key", "environment"]]
14096
+  (1.3ms) COMMIT
14097
+  (1.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14098
+  (0.7ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
14099
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14100
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
14101
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14102
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
14103
+  (123.8ms) DROP DATABASE IF EXISTS "construction_test"
14104
+  (328.1ms) CREATE DATABASE "construction_test" ENCODING = 'utf8'
14105
+ SQL (0.7ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
14106
+  (0.8ms) DROP TABLE IF EXISTS "mks_auth_application_modules" CASCADE
14107
+  (11.0ms) CREATE TABLE "mks_auth_application_modules" ("id" bigserial primary key, "code" character varying NOT NULL, "name" character varying NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14108
+  (0.7ms) DROP TABLE IF EXISTS "mks_auth_menus" CASCADE
14109
+  (7.0ms) CREATE TABLE "mks_auth_menus" ("id" bigserial primary key, "text" character varying NOT NULL, "icon_cls" character varying, "class_name" character varying, "location" character varying, "parent_id" integer, "application_module_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14110
+  (3.3ms) CREATE INDEX "index_mks_auth_menus_on_application_module_id" ON "mks_auth_menus" ("application_module_id")
14111
+  (3.7ms) CREATE INDEX "index_mks_auth_menus_on_parent_id" ON "mks_auth_menus" ("parent_id")
14112
+  (0.6ms) DROP TABLE IF EXISTS "mks_auth_menus_user_roles" CASCADE
14113
+  (6.2ms) CREATE TABLE "mks_auth_menus_user_roles" ("id" bigserial primary key, "menu_id" bigint, "user_role_id" bigint)
14114
+  (3.1ms) CREATE INDEX "index_mks_auth_menus_user_roles_on_menu_id_and_user_role_id" ON "mks_auth_menus_user_roles" ("menu_id", "user_role_id")
14115
+  (0.6ms) DROP TABLE IF EXISTS "mks_auth_user_roles" CASCADE
14116
+  (6.3ms) CREATE TABLE "mks_auth_user_roles" ("id" bigserial primary key, "name" character varying NOT NULL, "application_module_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14117
+  (3.2ms) CREATE INDEX "index_mks_auth_user_roles_on_application_module_id" ON "mks_auth_user_roles" ("application_module_id")
14118
+  (0.7ms) DROP TABLE IF EXISTS "mks_auth_users" CASCADE
14119
+  (6.4ms) CREATE TABLE "mks_auth_users" ("id" bigserial primary key, "first_name" character varying NOT NULL, "last_name" character varying NOT NULL, "email" character varying NOT NULL, "active" boolean DEFAULT TRUE NOT NULL, "password_digest" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14120
+  (0.6ms) DROP TABLE IF EXISTS "mks_auth_users_application_modules" CASCADE
14121
+  (1.9ms) CREATE TABLE "mks_auth_users_application_modules" ("user_id" bigint, "application_module_id" bigint)
14122
+  (3.7ms) CREATE INDEX "am_on_users_indx" ON "mks_auth_users_application_modules" ("user_id", "application_module_id")
14123
+  (0.6ms) DROP TABLE IF EXISTS "mks_auth_users_user_roles" CASCADE
14124
+  (1.7ms) CREATE TABLE "mks_auth_users_user_roles" ("user_id" bigint, "user_role_id" bigint)
14125
+  (3.3ms) CREATE INDEX "index_mks_auth_users_user_roles_on_user_id_and_user_role_id" ON "mks_auth_users_user_roles" ("user_id", "user_role_id")
14126
+  (3.2ms) ALTER TABLE "mks_auth_menus" ADD CONSTRAINT "fk_rails_e5dd25fcb5"
14127
+ FOREIGN KEY ("application_module_id")
14128
+ REFERENCES "mks_auth_application_modules" ("id")
14129
+ 
14130
+  (3.8ms) ALTER TABLE "mks_auth_menus" ADD CONSTRAINT "fk_rails_826b2757bc"
14131
+ FOREIGN KEY ("parent_id")
14132
+ REFERENCES "mks_auth_menus" ("id")
14133
+ 
14134
+  (2.8ms) ALTER TABLE "mks_auth_menus_user_roles" ADD CONSTRAINT "fk_rails_1807c05e36"
14135
+ FOREIGN KEY ("menu_id")
14136
+ REFERENCES "mks_auth_menus" ("id")
14137
+ 
14138
+  (2.6ms) ALTER TABLE "mks_auth_menus_user_roles" ADD CONSTRAINT "fk_rails_c24fca59c0"
14139
+ FOREIGN KEY ("user_role_id")
14140
+ REFERENCES "mks_auth_user_roles" ("id")
14141
+ 
14142
+  (2.5ms) ALTER TABLE "mks_auth_user_roles" ADD CONSTRAINT "fk_rails_b0b293e4e2"
14143
+ FOREIGN KEY ("application_module_id")
14144
+ REFERENCES "mks_auth_application_modules" ("id")
14145
+ 
14146
+  (2.4ms) ALTER TABLE "mks_auth_users_application_modules" ADD CONSTRAINT "fk_rails_b100f8542c"
14147
+ FOREIGN KEY ("application_module_id")
14148
+ REFERENCES "mks_auth_application_modules" ("id")
14149
+ 
14150
+  (2.6ms) ALTER TABLE "mks_auth_users_application_modules" ADD CONSTRAINT "fk_rails_1010e0182a"
14151
+ FOREIGN KEY ("user_id")
14152
+ REFERENCES "mks_auth_users" ("id")
14153
+ 
14154
+  (2.5ms) ALTER TABLE "mks_auth_users_user_roles" ADD CONSTRAINT "fk_rails_3dae904cd8"
14155
+ FOREIGN KEY ("user_role_id")
14156
+ REFERENCES "mks_auth_user_roles" ("id")
14157
+ 
14158
+  (2.2ms) ALTER TABLE "mks_auth_users_user_roles" ADD CONSTRAINT "fk_rails_7cc19890aa"
14159
+ FOREIGN KEY ("user_id")
14160
+ REFERENCES "mks_auth_users" ("id")
14161
+ 
14162
+  (6.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
14163
+  (1.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14164
+  (1.6ms) INSERT INTO "schema_migrations" (version) VALUES (20180201104912)
14165
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES
14166
+ (20161029065810),
14167
+ (20161029065959),
14168
+ (20161029070807),
14169
+ (20161029071047),
14170
+ (20161029072256),
14171
+ (20161029074023);
14172
+
14173
+ 
14174
+  (5.8ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
14175
+ ActiveRecord::InternalMetadata Load (0.7ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
14176
+  (0.9ms) BEGIN
14177
+ ActiveRecord::InternalMetadata Create (1.1ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2018-07-27 08:21:59.090286"], ["updated_at", "2018-07-27 08:21:59.090286"]]
14178
+  (1.4ms) COMMIT
14179
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
14180
+  (0.7ms) BEGIN
14181
+ ActiveRecord::InternalMetadata Update (0.9ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2018-07-27 08:21:59.098379"], ["key", "environment"]]
14182
+  (1.4ms) COMMIT