Skip to content

Commit

Permalink
WIP: continue outlining #update_root_aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid authored and joseivanlopez committed Sep 21, 2021
1 parent a7638b5 commit 56347d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/lib/y2users/linux/users_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ def write
# FIXME
def update_root_aliases
wrong_users_ids = @wrong_users.map(&:id)
added_or_updated_users = config.users.without(wrong_users_ids).to_a # FIXME
not_updated_users = initial_config.users.select { |u| wrong_users_ids.include?(u.id) }
root_aliases = (not_updated_users + added_or_updated_users).select(&:receive_system_mail)

# Collect all users not included in the issues list
users = config.users.without(wrong_users_ids)
# and add those that couldn't be updated
initial_config.users.each { |u| users.add(u) if wrong_users_ids.include?(u.id) }

root_aliases = users.select(&:receive_system_mail).map(&:name).join(", ")

with_issues do |issues|
result = Yast::MailAliases.SetRootAlias(root_aliases.map(&:name).join(", "))
result = Yast::MailAliases.SetRootAlias(root_aliases)

unless result
issues << Y2Issues::Issue.new(_("Something was wrong while adding root mail aliases"))
Expand Down
11 changes: 5 additions & 6 deletions test/lib/y2users/linux/writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@
end

context "whose receive_system_mail flag has changed" do
let(:current_user) { config.users.by_id(user.id) }
let(:receive_system_mail) { false }

before do
Expand All @@ -406,9 +405,9 @@
context "and it was set for receiving system mails" do
let(:receive_system_mail) { true }

it "sets new user name as root alias" do
it "sets it as root alias" do
expect(Yast::MailAliases).to receive(:SetRootAlias).with(kind_of(String)) do |arg|
expect(arg).to include(current_user.name)
expect(arg).to include(user.name)
end

writer.write
Expand All @@ -418,9 +417,9 @@
context "and it was set for receiving system mails" do
let(:receive_system_mail) { false }

it "does not set new user name as root alias" do
it "does not set it as root alias" do
expect(Yast::MailAliases).to receive(:SetRootAlias).with(kind_of(String)) do |arg|
expect(arg).to_not include(current_user.name)
expect(arg).to_not include(user.name)
end

writer.write
Expand Down Expand Up @@ -593,7 +592,7 @@
end
end

context "and it didn't receive modifications to that regard" do
context "and it was intended to continue not receiving them" do
before { current_user.receive_system_mail = false }

it "does not include the user as root alias" do
Expand Down

0 comments on commit 56347d4

Please sign in to comment.