From 7bf4fe5c24331a54257777ec7bfd0fd3f2e738c9 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Sun, 26 Mar 2017 12:54:06 +0900 Subject: [PATCH] Fixed SQL-99 reserved word "admin" conflict. --- app/models/user.rb | 4 +- .../20170326023519_rename_admin_to_is_admin.rb | 5 ++ test/fixtures/users.yml | 79 +++++++++++----------- test/unit/user_test.rb | 2 +- 4 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 db/migrate/20170326023519_rename_admin_to_is_admin.rb diff --git a/app/models/user.rb b/app/models/user.rb index 150cc27..cea3045 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -147,6 +147,8 @@ class User < Principal end } + alias_attribute :admin, :is_admin + def set_mail_notification self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? true @@ -707,7 +709,7 @@ class User < Principal # Returns true if the user is allowed to delete the user's own account def own_account_deletable? Setting.unsubscribe? && - (!admin? || User.active.where("admin = ? AND id <> ?", true, id).exists?) + (!admin? || User.active.where("is_admin = ? AND id <> ?", true, id).exists?) end safe_attributes 'firstname', diff --git a/db/migrate/20170326023519_rename_admin_to_is_admin.rb b/db/migrate/20170326023519_rename_admin_to_is_admin.rb new file mode 100644 index 0000000..85e28b8 --- /dev/null +++ b/db/migrate/20170326023519_rename_admin_to_is_admin.rb @@ -0,0 +1,5 @@ +class RenameAdminToIsAdmin < ActiveRecord::Migration + def change + rename_column :users, :admin, :is_admin + end +end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 986ed5d..4efff3d 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,5 +1,5 @@ ---- -users_001: +--- +users_001: created_on: 2006-07-19 19:12:21 +02:00 status: 1 last_login_on: 2006-07-19 22:57:52 +02:00 @@ -8,15 +8,15 @@ users_001: salt: 82090c953c4a0000a7db253b0691a6b4 hashed_password: b5b6ff9543bf1387374cdfa27a54c96d236a7150 updated_on: 2006-07-19 22:57:52 +02:00 - admin: true + is_admin: true lastname: Admin firstname: Redmine id: 1 - auth_source_id: + auth_source_id: mail_notification: all login: admin type: User -users_002: +users_002: created_on: 2006-07-19 19:32:09 +02:00 status: 1 last_login_on: 2006-07-19 22:42:15 +02:00 @@ -25,147 +25,146 @@ users_002: salt: 67eb4732624d5a7753dcea7ce0bb7d7d hashed_password: bfbe06043353a677d0215b26a5800d128d5413bc updated_on: 2006-07-19 22:42:15 +02:00 - admin: false + is_admin: false lastname: Smith firstname: John id: 2 - auth_source_id: + auth_source_id: mail_notification: all login: jsmith type: User -users_003: +users_003: created_on: 2006-07-19 19:33:19 +02:00 status: 1 - last_login_on: + last_login_on: language: en # password = foo salt: 7599f9963ec07b5a3b55b354407120c0 hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed updated_on: 2006-07-19 19:33:19 +02:00 - admin: false + is_admin: false lastname: Lopper firstname: Dave id: 3 - auth_source_id: + auth_source_id: mail_notification: all login: dlopper type: User -users_004: +users_004: created_on: 2006-07-19 19:34:07 +02:00 status: 1 - last_login_on: + last_login_on: language: en # password = foo salt: 3126f764c3c5ac61cbfc103f25f934cf hashed_password: 9e4dd7eeb172c12a0691a6d9d3a269f7e9fe671b updated_on: 2006-07-19 19:34:07 +02:00 - admin: false + is_admin: false lastname: Hill firstname: Robert id: 4 - auth_source_id: + auth_source_id: mail_notification: all login: rhill type: User -users_005: +users_005: id: 5 created_on: 2006-07-19 19:33:19 +02:00 # Locked status: 3 - last_login_on: + last_login_on: language: en hashed_password: 1 updated_on: 2006-07-19 19:33:19 +02:00 - admin: false + is_admin: false lastname: Lopper2 firstname: Dave2 - auth_source_id: + auth_source_id: mail_notification: all login: dlopper2 type: User -users_006: +users_006: id: 6 created_on: 2006-07-19 19:33:19 +02:00 status: 0 - last_login_on: + last_login_on: language: '' hashed_password: 1 updated_on: 2006-07-19 19:33:19 +02:00 - admin: false + is_admin: false lastname: Anonymous firstname: '' - auth_source_id: + auth_source_id: mail_notification: only_my_events login: '' type: AnonymousUser -users_007: +users_007: # A user who does not belong to any project id: 7 created_on: 2006-07-19 19:33:19 +02:00 status: 1 - last_login_on: + last_login_on: language: 'en' # password = foo salt: 7599f9963ec07b5a3b55b354407120c0 hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed updated_on: 2006-07-19 19:33:19 +02:00 - admin: false + is_admin: false lastname: One firstname: Some - auth_source_id: + auth_source_id: mail_notification: only_my_events login: someone type: User -users_008: +users_008: id: 8 created_on: 2006-07-19 19:33:19 +02:00 status: 1 - last_login_on: + last_login_on: language: 'it' # password = foo salt: 7599f9963ec07b5a3b55b354407120c0 hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed updated_on: 2006-07-19 19:33:19 +02:00 - admin: false + is_admin: false lastname: Misc firstname: User - auth_source_id: + auth_source_id: mail_notification: only_my_events login: miscuser8 type: User -users_009: +users_009: id: 9 created_on: 2006-07-19 19:33:19 +02:00 status: 1 - last_login_on: + last_login_on: language: 'it' hashed_password: 1 updated_on: 2006-07-19 19:33:19 +02:00 - admin: false + is_admin: false lastname: Misc firstname: User - auth_source_id: + auth_source_id: mail_notification: only_my_events login: miscuser9 type: User -groups_010: +groups_010: id: 10 lastname: A Team type: Group status: 1 -groups_011: +groups_011: id: 11 lastname: B Team type: Group status: 1 -groups_non_member: +groups_non_member: id: 12 lastname: Non member users type: GroupNonMember status: 1 -groups_anonymous: +groups_anonymous: id: 13 lastname: Anonymous users type: GroupAnonymous status: 1 - diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index ebc7d65..40c6893 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1049,7 +1049,7 @@ class UserTest < ActiveSupport::TestCase end def test_own_account_deletable_should_be_false_for_a_single_admin - User.where(["admin = ? AND id <> ?", true, 1]).delete_all + User.where(["is_admin = ? AND id <> ?", true, 1]).delete_all with_settings :unsubscribe => '1' do assert_equal false, User.find(1).own_account_deletable? -- 2.10.1 (Apple Git-78)