Skip to content

Commit e6a3dfc

Browse files
committed
Assign admin user to all providers
1 parent e8181fc commit e6a3dfc

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

lib/autorequire/data_import.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def self.import_all
1919
# import_branches
2020
# import_contributors
2121
import_topics
22-
restore_default_admin
22+
restore_default_users
2323
end
2424

2525
def self.file_path(file_name)
@@ -101,17 +101,27 @@ def self.import_topics
101101
# uid: uid,
102102
state: row["Topic_Archived"].to_i,
103103
)
104-
puts "#{topic.id} - #{topic.uid} - #{row["Topic_UID"]}"
105-
topic.save!
106104
puts "#{topic.title} #{topic.new_record? ? "created" : "already exists"}"
105+
topic.save!
107106
end
108107
end
109108

110-
def self.restore_default_admin
109+
def self.restore_default_users
111110
return if User.find_by_email("admin@email.com")
112111

113-
User.create(email: "admin@mail.com", password: "test123", is_admin: true)
114-
me = User.create(email: "me@mail.com", password: "test123")
115-
Provider.first.users << me
112+
admin = User.find_by(email: "admin@mail.com")
113+
if admin.nil?
114+
User.create!(email: "admin@mail.com", password: "test123", is_admin: true)
115+
end
116+
Provider.all.each do |provider|
117+
provider.users << admin unless provider.users.include?(admin)
118+
end
119+
120+
me = User.find_by(email: "me@mail.com")
121+
if me.nil?
122+
me = User.create!(email: "me@mail.com", password: "test123")
123+
end
124+
125+
Provider.first.users << me unless Provider.first.users.include?(me)
116126
end
117127
end

0 commit comments

Comments
 (0)