Project

General

Profile

Defect #25416 ยป 0001-Fixed-SQL-99-reserved-word-admin-conflict.patch

Go MAEDA, 2017-03-26 06:03

View differences:

app/models/user.rb
147 147
    end
148 148
  }
149 149

  
150
  alias_attribute :admin, :is_admin
151

  
150 152
  def set_mail_notification
151 153
    self.mail_notification = Setting.default_notification_option if self.mail_notification.blank?
152 154
    true
......
707 709
  # Returns true if the user is allowed to delete the user's own account
708 710
  def own_account_deletable?
709 711
    Setting.unsubscribe? &&
710
      (!admin? || User.active.where("admin = ? AND id <> ?", true, id).exists?)
712
      (!admin? || User.active.where("is_admin = ? AND id <> ?", true, id).exists?)
711 713
  end
712 714

  
713 715
  safe_attributes 'firstname',
db/migrate/20170326023519_rename_admin_to_is_admin.rb
1
class RenameAdminToIsAdmin < ActiveRecord::Migration
2
  def change
3
    rename_column :users, :admin, :is_admin
4
  end
5
end
test/fixtures/users.yml
1
--- 
2
users_001: 
1
---
2
users_001:
3 3
  created_on: 2006-07-19 19:12:21 +02:00
4 4
  status: 1
5 5
  last_login_on: 2006-07-19 22:57:52 +02:00
......
8 8
  salt: 82090c953c4a0000a7db253b0691a6b4
9 9
  hashed_password: b5b6ff9543bf1387374cdfa27a54c96d236a7150
10 10
  updated_on: 2006-07-19 22:57:52 +02:00
11
  admin: true
11
  is_admin: true
12 12
  lastname: Admin
13 13
  firstname: Redmine
14 14
  id: 1
15
  auth_source_id: 
15
  auth_source_id:
16 16
  mail_notification: all
17 17
  login: admin
18 18
  type: User
19
users_002: 
19
users_002:
20 20
  created_on: 2006-07-19 19:32:09 +02:00
21 21
  status: 1
22 22
  last_login_on: 2006-07-19 22:42:15 +02:00
......
25 25
  salt: 67eb4732624d5a7753dcea7ce0bb7d7d
26 26
  hashed_password: bfbe06043353a677d0215b26a5800d128d5413bc
27 27
  updated_on: 2006-07-19 22:42:15 +02:00
28
  admin: false
28
  is_admin: false
29 29
  lastname: Smith
30 30
  firstname: John
31 31
  id: 2
32
  auth_source_id: 
32
  auth_source_id:
33 33
  mail_notification: all
34 34
  login: jsmith
35 35
  type: User
36
users_003: 
36
users_003:
37 37
  created_on: 2006-07-19 19:33:19 +02:00
38 38
  status: 1
39
  last_login_on: 
39
  last_login_on:
40 40
  language: en
41 41
  # password = foo
42 42
  salt: 7599f9963ec07b5a3b55b354407120c0
43 43
  hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed
44 44
  updated_on: 2006-07-19 19:33:19 +02:00
45
  admin: false
45
  is_admin: false
46 46
  lastname: Lopper
47 47
  firstname: Dave
48 48
  id: 3
49
  auth_source_id: 
49
  auth_source_id:
50 50
  mail_notification: all
51 51
  login: dlopper
52 52
  type: User
53
users_004: 
53
users_004:
54 54
  created_on: 2006-07-19 19:34:07 +02:00
55 55
  status: 1
56
  last_login_on: 
56
  last_login_on:
57 57
  language: en
58 58
  # password = foo
59 59
  salt: 3126f764c3c5ac61cbfc103f25f934cf
60 60
  hashed_password: 9e4dd7eeb172c12a0691a6d9d3a269f7e9fe671b
61 61
  updated_on: 2006-07-19 19:34:07 +02:00
62
  admin: false
62
  is_admin: false
63 63
  lastname: Hill
64 64
  firstname: Robert
65 65
  id: 4
66
  auth_source_id: 
66
  auth_source_id:
67 67
  mail_notification: all
68 68
  login: rhill
69 69
  type: User
70
users_005: 
70
users_005:
71 71
  id: 5
72 72
  created_on: 2006-07-19 19:33:19 +02:00
73 73
  # Locked
74 74
  status: 3
75
  last_login_on: 
75
  last_login_on:
76 76
  language: en
77 77
  hashed_password: 1
78 78
  updated_on: 2006-07-19 19:33:19 +02:00
79
  admin: false
79
  is_admin: false
80 80
  lastname: Lopper2
81 81
  firstname: Dave2
82
  auth_source_id: 
82
  auth_source_id:
83 83
  mail_notification: all
84 84
  login: dlopper2
85 85
  type: User
86
users_006: 
86
users_006:
87 87
  id: 6
88 88
  created_on: 2006-07-19 19:33:19 +02:00
89 89
  status: 0
90
  last_login_on: 
90
  last_login_on:
91 91
  language: ''
92 92
  hashed_password: 1
93 93
  updated_on: 2006-07-19 19:33:19 +02:00
94
  admin: false
94
  is_admin: false
95 95
  lastname: Anonymous
96 96
  firstname: ''
97
  auth_source_id: 
97
  auth_source_id:
98 98
  mail_notification: only_my_events
99 99
  login: ''
100 100
  type: AnonymousUser
101
users_007: 
101
users_007:
102 102
  # A user who does not belong to any project
103 103
  id: 7
104 104
  created_on: 2006-07-19 19:33:19 +02:00
105 105
  status: 1
106
  last_login_on: 
106
  last_login_on:
107 107
  language: 'en'
108 108
  # password = foo
109 109
  salt: 7599f9963ec07b5a3b55b354407120c0
110 110
  hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed
111 111
  updated_on: 2006-07-19 19:33:19 +02:00
112
  admin: false
112
  is_admin: false
113 113
  lastname: One
114 114
  firstname: Some
115
  auth_source_id: 
115
  auth_source_id:
116 116
  mail_notification: only_my_events
117 117
  login: someone
118 118
  type: User
119
users_008: 
119
users_008:
120 120
  id: 8
121 121
  created_on: 2006-07-19 19:33:19 +02:00
122 122
  status: 1
123
  last_login_on: 
123
  last_login_on:
124 124
  language: 'it'
125 125
  # password = foo
126 126
  salt: 7599f9963ec07b5a3b55b354407120c0
127 127
  hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed
128 128
  updated_on: 2006-07-19 19:33:19 +02:00
129
  admin: false
129
  is_admin: false
130 130
  lastname: Misc
131 131
  firstname: User
132
  auth_source_id: 
132
  auth_source_id:
133 133
  mail_notification: only_my_events
134 134
  login: miscuser8
135 135
  type: User
136
users_009: 
136
users_009:
137 137
  id: 9
138 138
  created_on: 2006-07-19 19:33:19 +02:00
139 139
  status: 1
140
  last_login_on: 
140
  last_login_on:
141 141
  language: 'it'
142 142
  hashed_password: 1
143 143
  updated_on: 2006-07-19 19:33:19 +02:00
144
  admin: false
144
  is_admin: false
145 145
  lastname: Misc
146 146
  firstname: User
147
  auth_source_id: 
147
  auth_source_id:
148 148
  mail_notification: only_my_events
149 149
  login: miscuser9
150 150
  type: User
151
groups_010: 
151
groups_010:
152 152
  id: 10
153 153
  lastname: A Team
154 154
  type: Group
155 155
  status: 1
156
groups_011: 
156
groups_011:
157 157
  id: 11
158 158
  lastname: B Team
159 159
  type: Group
160 160
  status: 1
161
groups_non_member: 
161
groups_non_member:
162 162
  id: 12
163 163
  lastname: Non member users
164 164
  type: GroupNonMember
165 165
  status: 1
166
groups_anonymous: 
166
groups_anonymous:
167 167
  id: 13
168 168
  lastname: Anonymous users
169 169
  type: GroupAnonymous
170 170
  status: 1
171

  
test/unit/user_test.rb
1049 1049
  end
1050 1050

  
1051 1051
  def test_own_account_deletable_should_be_false_for_a_single_admin
1052
    User.where(["admin = ? AND id <> ?", true, 1]).delete_all
1052
    User.where(["is_admin = ? AND id <> ?", true, 1]).delete_all
1053 1053

  
1054 1054
    with_settings :unsubscribe => '1' do
1055 1055
      assert_equal false, User.find(1).own_account_deletable?
    (1-1/1)