has_many :api_client_authorizations
validates(:username,
format: {
- with: /^[A-Za-z][A-Za-z0-9]*$/,
+ with: /\A[A-Za-z][A-Za-z0-9]*\z/,
message: "must begin with a letter and contain only alphanumerics",
},
uniqueness: true,
ALL_PERMISSIONS = {read: true, write: true, manage: true}
+ # Map numeric permission levels (see lib/create_permission_view.sql)
+ # back to read/write/manage flags.
+ PERMS_FOR_VAL =
+ [{},
+ {read: true},
+ {read: true, write: true},
+ {read: true, write: true, manage: true}]
+
def full_name
"#{first_name} #{last_name}".strip
end
self.class.transaction do
# Check whether the temporary view has already been created
# during this connection. If not, create it.
- conn.execute 'SAVEPOINT check_permission_view'
+ conn.exec_query 'SAVEPOINT check_permission_view'
begin
- conn.execute('SELECT 1 FROM permission_view LIMIT 0')
+ conn.exec_query('SELECT 1 FROM permission_view LIMIT 0')
rescue
- conn.execute 'ROLLBACK TO SAVEPOINT check_permission_view'
+ conn.exec_query 'ROLLBACK TO SAVEPOINT check_permission_view'
sql = File.read(Rails.root.join('lib', 'create_permission_view.sql'))
conn.exec_query(sql)
- else
- conn.execute 'RELEASE SAVEPOINT check_permission_view'
+ ensure
+ conn.exec_query 'RELEASE SAVEPOINT check_permission_view'
end
end
group_perms = {}
- perms_for_val =
- [{},
- {read: true},
- {read: true, write: true},
- {read: true, write: true, manage: true}]
conn.exec_query('SELECT target_owner_uuid, max(perm_level)
- FROM permission_view
- WHERE user_uuid = $1
- AND target_owner_uuid IS NOT NULL
- GROUP BY target_owner_uuid',
- "group_permissions for #{uuid}",
- [[nil, uuid]]).rows.each do |group_uuid, max_p_val|
- group_perms[group_uuid] = perms_for_val[max_p_val.to_i]
+ FROM permission_view
+ WHERE user_uuid = $1
+ AND target_owner_uuid IS NOT NULL
+ GROUP BY target_owner_uuid',
+ # "name" arg is a query label that appears in logs:
+ "group_permissions for #{uuid}",
+ # "binds" arg is an array of [col_id, value] for '$1' vars:
+ [[nil, uuid]],
+ ).rows.each do |group_uuid, max_p_val|
+ group_perms[group_uuid] = PERMS_FOR_VAL[max_p_val.to_i]
end
Rails.cache.write "groups_for_user_#{self.uuid}", group_perms
group_perms
# Send admin notifications
def send_admin_notifications
- AdminNotifier.new_user(self).deliver
+ AdminNotifier.new_user(self).deliver_now
if not self.is_active then
- AdminNotifier.new_inactive_user(self).deliver
+ AdminNotifier.new_inactive_user(self).deliver_now
end
end
if self.prefs_changed?
if self.prefs_was.andand.empty? || !self.prefs_was.andand['profile']
profile_notification_address = Rails.configuration.user_profile_notification_address
- ProfileNotifier.profile_created(self, profile_notification_address).deliver if profile_notification_address
+ ProfileNotifier.profile_created(self, profile_notification_address).deliver_now if profile_notification_address
end
end
end