"Fossies" - the Fresh Open Source Software Archive

Member "discourse-2.8.3/db/fixtures/009_users.rb" (14 Apr 2022, 1581 Bytes) of package /linux/www/discourse-2.8.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 
    3 # kind of odd, but we need it, we also need to nuke usage of User from inside migrations
    4 #  very poor form
    5 user = User.find_by("id <> -1 and username_lower = 'system'")
    6 if user
    7   user.username = UserNameSuggester.suggest("system")
    8   user.save
    9 end
   10 
   11 UserEmail.seed do |ue|
   12   ue.id = -1
   13   ue.email = "no_email"
   14   ue.primary = true
   15   ue.user_id = -1
   16 end
   17 
   18 User.seed do |u|
   19   u.id = -1
   20   u.name = "system"
   21   u.username = "system"
   22   u.username_lower = "system"
   23   u.password = SecureRandom.hex
   24   u.active = true
   25   u.admin = true
   26   u.moderator = true
   27   u.approved = true
   28   u.trust_level = TrustLevel[4]
   29 end
   30 
   31 UserOption.where(user_id: -1).update_all(
   32   email_messages_level: UserOption.email_level_types[:never],
   33   email_level: UserOption.email_level_types[:never]
   34 )
   35 
   36 Group.user_trust_level_change!(-1, TrustLevel[4])
   37 
   38 # User for the smoke tests
   39 if ENV["SMOKE"] == "1"
   40   UserEmail.seed do |ue|
   41     ue.id = 0
   42     ue.email = "smoke_user@discourse.org"
   43     ue.primary = true
   44     ue.user_id = 0
   45   end
   46 
   47   smoke_user = User.seed do |u|
   48     u.id = 0
   49     u.name = "smoke_user"
   50     u.username = "smoke_user"
   51     u.username_lower = "smoke_user"
   52     u.password = "P4ssw0rd"
   53     u.active = true
   54     u.approved = true
   55     u.approved_at = Time.now
   56     u.trust_level = TrustLevel[3]
   57   end.first
   58 
   59   UserOption.where(user_id: smoke_user.id).update_all(
   60     email_digests: false,
   61     email_messages_level: UserOption.email_level_types[:never],
   62     email_level: UserOption.email_level_types[:never]
   63   )
   64 
   65   EmailToken.where(user_id: smoke_user.id).update_all(confirmed: true)
   66 end