1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'can_be_an_owner'
7 class User < ArvadosModel
10 include CommonApiTemplate
12 extend CurrentApiClient
14 serialize :prefs, Hash
15 has_many :api_client_authorizations
18 with: /\A[A-Za-z][A-Za-z0-9]*\z/,
19 message: "must begin with a letter and contain only alphanumerics",
23 validate :must_unsetup_to_deactivate
24 before_update :prevent_privilege_escalation
25 before_update :prevent_inactive_admin
26 before_update :verify_repositories_empty, :if => Proc.new { |user|
27 user.username.nil? and user.username_changed?
29 before_update :setup_on_activate
30 before_create :check_auto_admin
31 before_create :set_initial_username, :if => Proc.new { |user|
32 user.username.nil? and user.email
34 after_create :update_permissions
35 after_create :setup_on_activate
36 after_create :add_system_group_permission_link
37 after_create :auto_setup_new_user, :if => Proc.new { |user|
38 Rails.configuration.Users.AutoSetupNewUsers and
39 (user.uuid != system_user_uuid) and
40 (user.uuid != anonymous_user_uuid)
42 after_create :send_admin_notifications
43 after_update :update_permissions, :if => :owner_uuid_changed?
44 after_update :send_profile_created_notification
45 after_update :sync_repository_names, :if => Proc.new { |user|
46 (user.uuid != system_user_uuid) and
47 user.username_changed? and
48 (not user.username_was.nil?)
52 has_many :authorized_keys, :foreign_key => :authorized_user_uuid, :primary_key => :uuid
53 has_many :repositories, foreign_key: :owner_uuid, primary_key: :uuid
55 default_scope { where('redirect_to_user_uuid is null') }
57 api_accessible :user, extend: :common do |t|
71 ALL_PERMISSIONS = {read: true, write: true, manage: true}
73 # Map numeric permission levels (see lib/create_permission_view.sql)
74 # back to read/write/manage flags.
78 {read: true, write: true},
79 {read: true, write: true, manage: true}]
82 "#{first_name} #{last_name}".strip
87 Rails.configuration.Users.NewUsersAreActive ||
88 self.groups_i_can(:read).select { |x| x.match(/-f+$/) }.first)
91 def groups_i_can(verb)
92 my_groups = self.group_permissions.select { |uuid, mask| mask[verb] }.keys
94 my_groups << anonymous_group_uuid
100 return true if is_admin
101 actions.each do |action, target|
103 if target.respond_to? :uuid
104 target_uuid = target.uuid
107 target = ArvadosModel.find_by_uuid(target_uuid)
110 next if target_uuid == self.uuid
111 next if (group_permissions[target_uuid] and
112 group_permissions[target_uuid][action])
113 if target.respond_to? :owner_uuid
114 next if target.owner_uuid == self.uuid
115 next if (group_permissions[target.owner_uuid] and
116 group_permissions[target.owner_uuid][action])
118 sufficient_perms = case action
122 ['can_manage', 'can_write']
124 ['can_manage', 'can_write', 'can_read']
126 # (Skip this kind of permission opportunity
127 # if action is an unknown permission type)
130 # Check permission links with head_uuid pointing directly at
131 # the target object. If target is a Group, this is redundant
132 # and will fail except [a] if permission caching is broken or
133 # [b] during a race condition, where a permission link has
135 if Link.where(link_class: 'permission',
136 name: sufficient_perms,
137 tail_uuid: groups_i_can(action) + [self.uuid],
138 head_uuid: target_uuid).any?
147 def update_permissions
149 puts "Update permissions for #{uuid}"
151 select * from materialized_permissions where user_uuid='#{uuid}'
154 User.update_permissions self.owner_uuid, self.uuid, 3
158 select * from materialized_permissions where user_uuid='#{uuid}'
163 def self.printdump qr
164 q1 = ActiveRecord::Base.connection.exec_query qr
170 def recompute_permissions
171 ActiveRecord::Base.connection.execute("DELETE FROM #{PERMISSION_VIEW} where user_uuid='#{uuid}'")
172 ActiveRecord::Base.connection.execute %{
173 INSERT INTO #{PERMISSION_VIEW}
174 select '#{uuid}', g.target_uuid, g.val, g.traverse_owned
175 from search_permission_graph('#{uuid}', 3) as g
179 def self.update_permissions perm_origin_uuid, starting_uuid, perm_level
180 # Update a subset of the permission graph
181 # perm_level is the inherited permission
182 # perm_level is a number from 0-3
186 # call with perm_level=0 to revoke permissions
188 # 1. Compute set (group, permission) implied by traversing
189 # graph starting at this group
190 # 2. Find links from outside the graph that point inside
191 # 3. For each starting uuid, get the set of permissions from the
192 # materialized permission table
193 # 3. Delete permissions from table not in our computed subset.
194 # 4. Upsert each permission in our subset (user, group, val)
197 puts "__ update_permissions __"
198 puts "What's in there now for #{starting_uuid}"
200 select * from materialized_permissions where user_uuid='#{starting_uuid}'
203 puts "search_permission_graph #{perm_origin_uuid} #{starting_uuid}, #{perm_level}"
205 select '#{perm_origin_uuid}'::varchar as perm_origin_uuid, target_uuid, val, traverse_owned from search_permission_graph('#{starting_uuid}', #{perm_level})
211 # perm_from_start(perm_origin_uuid, target_uuid, val, traverse_owned) as (
212 # select '#{perm_origin_uuid}'::varchar, target_uuid, val, traverse_owned
213 # from search_permission_graph('#{starting_uuid}', #{perm_level}))
215 # (select materialized_permissions.user_uuid, u.target_uuid, max(least(materialized_permissions.perm_level, u.val)), bool_or(u.traverse_owned)
216 # from perm_from_start as u
217 # join materialized_permissions on (u.perm_origin_uuid = materialized_permissions.target_uuid)
218 # where materialized_permissions.traverse_owned
219 # group by materialized_permissions.user_uuid, u.target_uuid)
221 # select target_uuid as user_uuid, target_uuid, 3, true
222 # from perm_from_start where target_uuid like '_____-tpzed-_______________'
226 temptable_perms = "temp_perms_#{rand(2**64).to_s(10)}"
227 ActiveRecord::Base.connection.exec_query %{
228 create temporary table #{temptable_perms} on commit drop
229 as select * from compute_permission_subgraph($1, $2, $3)
231 'Group.search_permissions',
232 [[nil, perm_origin_uuid],
233 [nil, starting_uuid],
236 q1 = ActiveRecord::Base.connection.exec_query %{
237 select * from #{temptable_perms}
239 puts "recomputed perms was #{perm_origin_uuid} #{starting_uuid}, #{perm_level}"
245 ActiveRecord::Base.connection.exec_query %{
246 delete from materialized_permissions where
247 target_uuid in (select target_uuid from #{temptable_perms}) and
248 (user_uuid not in (select user_uuid from #{temptable_perms} where target_uuid=materialized_permissions.target_uuid)
249 or user_uuid in (select user_uuid from #{temptable_perms} where target_uuid=materialized_permissions.target_uuid and perm_level=0))
252 ActiveRecord::Base.connection.exec_query %{
253 insert into materialized_permissions (user_uuid, target_uuid, perm_level, traverse_owned)
254 select user_uuid, target_uuid, val as perm_level, traverse_owned from #{temptable_perms}
255 on conflict (user_uuid, target_uuid) do update set perm_level=EXCLUDED.perm_level, traverse_owned=EXCLUDED.traverse_owned;
258 # for testing only - make a copy of the table and compare it to the one generated
259 # using a full permission recompute
260 # temptable_compare = "compare_perms_#{rand(2**64).to_s(10)}"
261 # ActiveRecord::Base.connection.exec_query %{
262 # create temporary table #{temptable_compare} on commit drop as select * from materialized_permissions
265 # Ensure a new group can be accessed by the appropriate users
266 # immediately after being created.
267 #User.invalidate_permissions_cache
269 # q1 = ActiveRecord::Base.connection.exec_query %{
270 # select count(*) from materialized_permissions
272 # puts "correct version #{q1.first}"
274 # q2 = ActiveRecord::Base.connection.exec_query %{
275 # select count(*) from #{temptable_compare}
277 # puts "incremental update #{q2.first}"
280 # Return a hash of {user_uuid: group_perms}
281 def self.all_group_permissions
283 ActiveRecord::Base.connection.
284 exec_query("SELECT user_uuid, target_uuid, perm_level
285 FROM #{PERMISSION_VIEW}
286 WHERE traverse_owned",
287 # "name" arg is a query label that appears in logs:
288 "all_group_permissions",
289 ).rows.each do |user_uuid, group_uuid, max_p_val|
290 all_perms[user_uuid] ||= {}
291 all_perms[user_uuid][group_uuid] = PERMS_FOR_VAL[max_p_val.to_i]
296 # Return a hash of {group_uuid: perm_hash} where perm_hash[:read]
297 # and perm_hash[:write] are true if this user can read and write
298 # objects owned by group_uuid.
299 def group_permissions
300 group_perms = {self.uuid => {:read => true, :write => true, :manage => true}}
301 ActiveRecord::Base.connection.
302 exec_query("SELECT target_uuid, perm_level
303 FROM #{PERMISSION_VIEW}
306 # "name" arg is a query label that appears in logs:
307 "group_permissions_for_user",
308 # "binds" arg is an array of [col_id, value] for '$1' vars:
310 ).rows.each do |group_uuid, max_p_val|
311 group_perms[group_uuid] = PERMS_FOR_VAL[max_p_val.to_i]
317 def setup(repo_name: nil, vm_uuid: nil)
318 repo_perm = create_user_repo_link repo_name
319 vm_login_perm = create_vm_login_permission_link(vm_uuid, username) if vm_uuid
320 group_perm = create_user_group_link
322 return [repo_perm, vm_login_perm, group_perm, self].compact
325 # delete user signatures, login, repo, and vm perms, and mark as inactive
327 # delete oid_login_perms for this user
329 # note: these permission links are obsolete, they have no effect
330 # on anything and they are not created for new users.
331 Link.where(tail_uuid: self.email,
332 link_class: 'permission',
333 name: 'can_login').destroy_all
335 # delete repo_perms for this user
336 Link.where(tail_uuid: self.uuid,
337 link_class: 'permission',
338 name: 'can_manage').destroy_all
340 # delete vm_login_perms for this user
341 Link.where(tail_uuid: self.uuid,
342 link_class: 'permission',
343 name: 'can_login').destroy_all
345 # delete "All users" group read permissions for this user
346 group = Group.where(name: 'All users').select do |g|
347 g[:uuid].match(/-f+$/)
349 Link.where(tail_uuid: self.uuid,
350 head_uuid: group[:uuid],
351 link_class: 'permission',
352 name: 'can_read').destroy_all
354 # delete any signatures by this user
355 Link.where(link_class: 'signature',
356 tail_uuid: self.uuid).destroy_all
358 # delete user preferences (including profile)
361 # mark the user as inactive
362 self.is_active = false
366 def must_unsetup_to_deactivate
367 if self.is_active_changed? &&
368 self.is_active_was == true &&
371 group = Group.where(name: 'All users').select do |g|
372 g[:uuid].match(/-f+$/)
375 # When a user is set up, they are added to the "All users"
376 # group. A user that is part of the "All users" group is
377 # allowed to self-activate.
379 # It doesn't make sense to deactivate a user (set is_active =
380 # false) without first removing them from the "All users" group,
381 # because they would be able to immediately reactivate
384 # The 'unsetup' method removes the user from the "All users"
385 # group (and also sets is_active = false) so send a message
386 # explaining the correct way to deactivate a user.
388 if Link.where(tail_uuid: self.uuid,
389 head_uuid: group[:uuid],
390 link_class: 'permission',
391 name: 'can_read').any?
392 errors.add :is_active, "cannot be set to false directly, use the 'Deactivate' button on Workbench, or the 'unsetup' API call"
397 def set_initial_username(requested: false)
398 if !requested.is_a?(String) || requested.empty?
399 email_parts = email.partition("@")
400 local_parts = email_parts.first.partition("+")
401 if email_parts.any?(&:empty?)
403 elsif not local_parts.first.empty?
404 requested = local_parts.first
406 requested = email_parts.first
409 requested.sub!(/^[^A-Za-z]+/, "")
410 requested.gsub!(/[^A-Za-z0-9]/, "")
411 unless requested.empty?
412 self.username = find_usable_username_from(requested)
416 def update_uuid(new_uuid:)
417 if !current_user.andand.is_admin
418 raise PermissionDeniedError
420 if uuid == system_user_uuid || uuid == anonymous_user_uuid
421 raise "update_uuid cannot update system accounts"
423 if self.class != self.class.resource_class_for_uuid(new_uuid)
424 raise "invalid new_uuid #{new_uuid.inspect}"
426 transaction(requires_new: true) do
430 save!(validate: false)
431 change_all_uuid_refs(old_uuid: old_uuid, new_uuid: new_uuid)
435 # Move this user's (i.e., self's) owned items to new_owner_uuid and
436 # new_user_uuid (for things normally owned directly by the user).
438 # If redirect_auth is true, also reassign auth tokens and ssh keys,
439 # and redirect this account to redirect_to_user_uuid, i.e., when a
440 # caller authenticates to this account in the future, the account
441 # redirect_to_user_uuid account will be used instead.
443 # current_user must have admin privileges, i.e., the caller is
444 # responsible for checking permission to do this.
445 def merge(new_owner_uuid:, new_user_uuid:, redirect_to_new_user:)
446 raise PermissionDeniedError if !current_user.andand.is_admin
447 raise "Missing new_owner_uuid" if !new_owner_uuid
448 raise "Missing new_user_uuid" if !new_user_uuid
449 transaction(requires_new: true) do
451 raise "cannot merge an already merged user" if self.redirect_to_user_uuid
453 new_user = User.where(uuid: new_user_uuid).first
454 raise "user does not exist" if !new_user
455 raise "cannot merge to an already merged user" if new_user.redirect_to_user_uuid
457 # If 'self' is a remote user, don't transfer authorizations
458 # (i.e. ability to access the account) to the new user, because
459 # that gives the remote site the ability to access the 'new'
460 # user account that takes over the 'self' account.
462 # If 'self' is a local user, it is okay to transfer
463 # authorizations, even if the 'new' user is a remote account,
464 # because the remote site does not gain the ability to access an
465 # account it could not before.
467 if redirect_to_new_user and self.uuid[0..4] == Rails.configuration.ClusterID
468 # Existing API tokens and ssh keys are updated to authenticate
470 ApiClientAuthorization.
472 update_all(user_id: new_user.id)
475 [AuthorizedKey, :owner_uuid],
476 [AuthorizedKey, :authorized_user_uuid],
482 # Destroy API tokens and ssh keys associated with the old
484 ApiClientAuthorization.where(user_id: id).destroy_all
485 AuthorizedKey.where(owner_uuid: uuid).destroy_all
486 AuthorizedKey.where(authorized_user_uuid: uuid).destroy_all
493 # References to the old user UUID in the context of a user ID
494 # (rather than a "home project" in the project hierarchy) are
495 # updated to point to the new user.
496 user_updates.each do |klass, column|
497 klass.where(column => uuid).update_all(column => new_user.uuid)
500 # Need to update repository names to new username
502 old_repo_name_re = /^#{Regexp.escape(username)}\//
503 Repository.where(:owner_uuid => uuid).each do |repo|
504 repo.owner_uuid = new_user.uuid
505 repo_name_sub = "#{new_user.username}/"
506 name = repo.name.sub(old_repo_name_re, repo_name_sub)
507 while (conflict = Repository.where(:name => name).first) != nil
508 repo_name_sub += "migrated"
509 name = repo.name.sub(old_repo_name_re, repo_name_sub)
516 # References to the merged user's "home project" are updated to
517 # point to new_owner_uuid.
518 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |klass|
519 next if [ApiClientAuthorization,
523 Repository].include?(klass)
524 next if !klass.columns.collect(&:name).include?('owner_uuid')
525 klass.where(owner_uuid: uuid).update_all(owner_uuid: new_owner_uuid)
528 if redirect_to_new_user
529 update_attributes!(redirect_to_user_uuid: new_user.uuid, username: nil)
531 self.recompute_permissions
532 new_user.recompute_permissions
539 while (uuid = user.redirect_to_user_uuid)
541 nextuser = User.unscoped.find_by_uuid(uuid)
543 raise Exception.new("user uuid #{user.uuid} redirects to nonexistent uuid '#{uuid}'")
548 raise "Starting from #{self.uuid} redirect_to_user_uuid exceeded maximum number of redirects"
554 def self.register info
555 # login info expected fields, all can be optional but at minimum
556 # must supply either 'identity_url' or 'email'
568 identity_url = info['identity_url']
570 if identity_url && identity_url.length > 0
571 # Only local users can create sessions, hence uuid_like_pattern
573 user = User.unscoped.where('identity_url = ? and uuid like ?',
575 User.uuid_like_pattern).first
576 primary_user = user.redirects_to if user
580 # identity url is unset or didn't find matching record.
581 emails = [info['email']] + (info['alternate_emails'] || [])
582 emails.select! {|em| !em.nil? && !em.empty?}
584 User.unscoped.where('email in (?) and uuid like ?',
586 User.uuid_like_pattern).each do |user|
588 primary_user = user.redirects_to
589 elsif primary_user.uuid != user.redirects_to.uuid
590 raise "Ambiguous email address, directs to both #{primary_user.uuid} and #{user.redirects_to.uuid}"
596 # New user registration
597 primary_user = User.new(:owner_uuid => system_user_uuid,
599 :is_active => Rails.configuration.Users.NewUsersAreActive)
601 primary_user.set_initial_username(requested: info['username']) if info['username'] && !info['username'].blank?
602 primary_user.identity_url = info['identity_url'] if identity_url
605 primary_user.email = info['email'] if info['email']
606 primary_user.first_name = info['first_name'] if info['first_name']
607 primary_user.last_name = info['last_name'] if info['last_name']
609 if (!primary_user.email or primary_user.email.empty?) and (!primary_user.identity_url or primary_user.identity_url.empty?)
610 raise "Must have supply at least one of 'email' or 'identity_url' to User.register"
613 act_as_system_user do
622 def change_all_uuid_refs(old_uuid:, new_uuid:)
623 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |klass|
624 klass.columns.each do |col|
625 if col.name.end_with?('_uuid')
626 column = col.name.to_sym
627 klass.where(column => old_uuid).update_all(column => new_uuid)
633 def ensure_ownership_path_leads_to_user
637 def permission_to_update
638 if username_changed? || redirect_to_user_uuid_changed? || email_changed?
639 current_user.andand.is_admin
641 # users must be able to update themselves (even if they are
642 # inactive) in order to create sessions
643 self == current_user or super
647 def permission_to_create
648 current_user.andand.is_admin or
649 (self == current_user &&
650 self.redirect_to_user_uuid.nil? &&
651 self.is_active == Rails.configuration.Users.NewUsersAreActive)
655 return if self.uuid.end_with?('anonymouspublic')
656 if (User.where("email = ?",self.email).where(:is_admin => true).count == 0 and
657 !Rails.configuration.Users.AutoAdminUserWithEmail.empty? and self.email == Rails.configuration.Users["AutoAdminUserWithEmail"]) or
658 (User.where("uuid not like '%-000000000000000'").where(:is_admin => true).count == 0 and
659 Rails.configuration.Users.AutoAdminFirstUser)
661 self.is_active = true
665 def find_usable_username_from(basename)
666 # If "basename" is a usable username, return that.
667 # Otherwise, find a unique username "basenameN", where N is the
668 # smallest integer greater than 1, and return that.
669 # Return nil if a unique username can't be found after reasonable
671 quoted_name = self.class.connection.quote_string(basename)
672 next_username = basename
674 while Rails.configuration.Users.AutoSetupUsernameBlacklist[next_username]
676 next_username = "%s%i" % [basename, next_suffix]
678 0.upto(6).each do |suffix_len|
679 pattern = "%s%s" % [quoted_name, "_" * suffix_len]
681 where("username like '#{pattern}'").
683 order('username asc').
685 if other_user.username > next_username
687 elsif other_user.username == next_username
689 next_username = "%s%i" % [basename, next_suffix]
692 return next_username if (next_username.size <= pattern.size)
697 def prevent_privilege_escalation
698 if current_user.andand.is_admin
701 if self.is_active_changed?
702 if self.is_active != self.is_active_was
703 logger.warn "User #{current_user.uuid} tried to change is_active from #{self.is_active_was} to #{self.is_active} for #{self.uuid}"
704 self.is_active = self.is_active_was
707 if self.is_admin_changed?
708 if self.is_admin != self.is_admin_was
709 logger.warn "User #{current_user.uuid} tried to change is_admin from #{self.is_admin_was} to #{self.is_admin} for #{self.uuid}"
710 self.is_admin = self.is_admin_was
716 def prevent_inactive_admin
717 if self.is_admin and not self.is_active
718 # There is no known use case for the strange set of permissions
719 # that would result from this change. It's safest to assume it's
720 # a mistake and disallow it outright.
721 raise "Admin users cannot be inactive"
726 def search_permissions(start, graph, merged={}, upstream_mask=nil, upstream_path={})
727 nextpaths = graph[start]
728 return merged if !nextpaths
729 return merged if upstream_path.has_key? start
730 upstream_path[start] = true
731 upstream_mask ||= ALL_PERMISSIONS
732 nextpaths.each do |head, mask|
735 merged[head][k] ||= v if upstream_mask[k]
737 search_permissions(head, graph, merged, upstream_mask.select { |k,v| v && merged[head][k] }, upstream_path)
739 upstream_path.delete start
743 def create_user_repo_link(repo_name)
744 # repo_name is optional
746 logger.warn ("Repository name not given for #{self.uuid}.")
750 repo = Repository.where(owner_uuid: uuid, name: repo_name).first_or_create!
751 logger.info { "repo uuid: " + repo[:uuid] }
752 repo_perm = Link.where(tail_uuid: uuid, head_uuid: repo.uuid,
753 link_class: "permission",
754 name: "can_manage").first_or_create!
755 logger.info { "repo permission: " + repo_perm[:uuid] }
759 # create login permission for the given vm_uuid, if it does not already exist
760 def create_vm_login_permission_link(vm_uuid, repo_name)
761 # vm uuid is optional
762 return if vm_uuid == ""
764 vm = VirtualMachine.where(uuid: vm_uuid).first
766 logger.warn "Could not find virtual machine for #{vm_uuid.inspect}"
767 raise "No vm found for #{vm_uuid}"
770 logger.info { "vm uuid: " + vm[:uuid] }
772 tail_uuid: uuid, head_uuid: vm.uuid,
773 link_class: "permission", name: "can_login",
778 select { |link| link.properties["username"] == repo_name }.
782 create(login_attrs.merge(properties: {"username" => repo_name}))
784 logger.info { "login permission: " + login_perm[:uuid] }
788 # add the user to the 'All users' group
789 def create_user_group_link
790 #puts "In create_user_group_link"
791 return (Link.where(tail_uuid: self.uuid,
792 head_uuid: all_users_group[:uuid],
793 link_class: 'permission',
794 name: 'can_read').first or
795 Link.create(tail_uuid: self.uuid,
796 head_uuid: all_users_group[:uuid],
797 link_class: 'permission',
801 # Give the special "System group" permission to manage this user and
802 # all of this user's stuff.
803 def add_system_group_permission_link
804 return true if uuid == system_user_uuid
805 act_as_system_user do
806 Link.create(link_class: 'permission',
808 tail_uuid: system_group_uuid,
809 head_uuid: self.uuid)
813 # Send admin notifications
814 def send_admin_notifications
815 AdminNotifier.new_user(self).deliver_now
816 if not self.is_active then
817 AdminNotifier.new_inactive_user(self).deliver_now
821 # Automatically setup if is_active flag turns on
822 def setup_on_activate
823 return if [system_user_uuid, anonymous_user_uuid].include?(self.uuid)
824 if is_active && (new_record? || is_active_changed?)
829 # Automatically setup new user during creation
830 def auto_setup_new_user
833 create_vm_login_permission_link(Rails.configuration.Users.AutoSetupNewUsersWithVmUUID,
835 repo_name = "#{username}/#{username}"
836 if Rails.configuration.Users.AutoSetupNewUsersWithRepository and
837 Repository.where(name: repo_name).first.nil?
838 repo = Repository.create!(name: repo_name, owner_uuid: uuid)
839 Link.create!(tail_uuid: uuid, head_uuid: repo.uuid,
840 link_class: "permission", name: "can_manage")
845 # Send notification if the user saved profile for the first time
846 def send_profile_created_notification
847 if self.prefs_changed?
848 if self.prefs_was.andand.empty? || !self.prefs_was.andand['profile']
849 profile_notification_address = Rails.configuration.Users.UserProfileNotificationAddress
850 ProfileNotifier.profile_created(self, profile_notification_address).deliver_now if profile_notification_address and !profile_notification_address.empty?
855 def verify_repositories_empty
856 unless repositories.first.nil?
857 errors.add(:username, "can't be unset when the user owns repositories")
862 def sync_repository_names
863 old_name_re = /^#{Regexp.escape(username_was)}\//
864 name_sub = "#{username}/"
865 repositories.find_each do |repo|
866 repo.name = repo.name.sub(old_name_re, name_sub)