Skip to content

Commit

Permalink
Merge pull request #758 from yast/backport_role_fix
Browse files Browse the repository at this point in the history
Backport the role fix
  • Loading branch information
lslezak committed Nov 6, 2018
2 parents b02e1f9 + 4bde750 commit fd44cc4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
6 changes: 6 additions & 0 deletions package/yast2-installation.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Nov 6 08:26:42 UTC 2018 - lslezak@suse.cz

- Remember the selected role (related to FATE#325834)
- 4.0.73

-------------------------------------------------------------------
Fri Nov 2 13:23:30 CET 2018 - schubi@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.0.72
Version: 4.0.73
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
21 changes: 8 additions & 13 deletions src/lib/installation/select_system_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ module Installation
class SelectSystemRole < ::UI::InstallationDialog
include UI::TextHelpers

class << self
# once the user selects a role, remember it in case they come back
attr_accessor :original_role_id
end

NON_OVERLAY_ATTRIBUTES = [
"additional_dialogs",
"id",
Expand All @@ -60,7 +55,7 @@ def run

if Yast::GetInstArgs.going_back
# If coming back, we have to run the additional dialogs first...
clients = additional_clients_for(self.class.original_role_id)
clients = additional_clients_for(SystemRole.current)
direction = run_clients(clients, going_back: true)
# ... and only run the main dialog (super) if we are *still* going back
return direction unless direction == :back
Expand All @@ -78,7 +73,7 @@ def help_text
end

def dialog_content
@selected_role_id = self.class.original_role_id
@selected_role_id = SystemRole.current
@selected_role_id ||= roles.first && roles.first.id if SystemRole.default?

HCenter(ReplacePoint(Id(:rp), role_buttons(selected_role_id: @selected_role_id)))
Expand All @@ -101,15 +96,13 @@ def next_handler
return
end

orig_role_id = self.class.original_role_id
if !orig_role_id.nil? && orig_role_id != role_id
if SystemRole.current && SystemRole.current != role_id
# A Continue-Cancel popup
msg = _("Changing the system role may undo adjustments you may have done.")
return unless Yast::Popup.ContinueCancel(msg)
end
self.class.original_role_id = role_id

apply_role(SystemRole.find(role_id))
apply_role(role_id)

result = run_clients(additional_clients_for(role_id))
# We show the main role dialog; but the additional clients have
Expand Down Expand Up @@ -192,8 +185,10 @@ def clear_role
end

# Applies given role to configuration
def apply_role(role)
log.info "Applying system role '#{role.id}'"
def apply_role(role_id)
log.info "Applying system role '#{role_id}'"

role = SystemRole.select(role_id)
role.overlay_features
adapt_services(role)

Expand Down
2 changes: 2 additions & 0 deletions src/lib/installation/system_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def raw_roles
# @see current
def select(role_id)
@current_role = find(role_id)
log.info("Selected role: #{current}")
current_role
end

# Returns the current role id
Expand Down
1 change: 1 addition & 0 deletions test/lib/clients/inst_system_analysis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
allow(storage).to receive(:activate).and_return activate_result
allow(storage).to receive(:probe).and_return probe_result
allow(Yast::Mode).to receive(:auto).and_return(auto)
allow(Yast::Execute).to receive(:locally!)
stub_const("Y2Autoinstallation::ActivateCallbacks", callbacks_class)
end

Expand Down
20 changes: 10 additions & 10 deletions test/select_system_role_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"Lorem Ipsum #{s}"
end

allow(Installation::SystemRole).to receive(:select)
allow(Yast::UI).to receive(:ChangeWidget)
allow(Yast::Language).to receive(:language).and_return("en_US")

Expand All @@ -21,12 +22,10 @@

describe "#run" do
before do
# reset previous test
subject.class.original_role_id = nil

allow(Yast::ProductFeatures).to receive(:ClearOverlay)
allow(Yast::ProductFeatures).to receive(:SetOverlay) # .with
allow(Yast::Packages).to receive(:SelectSystemPatterns)
allow(Installation::SystemRole).to receive(:current)
end

context "when no roles are defined" do
Expand All @@ -53,6 +52,10 @@
before do
allow(Yast::ProductControl).to receive(:system_roles)
.and_return(control_file_roles)
allow(Installation::SystemRole).to receive(:select).with("foo")
.and_return(Installation::SystemRole.new(id: "foo", order: 100))
allow(Installation::SystemRole).to receive(:select).with("bar")
.and_return(Installation::SystemRole.new(id: "bar", order: 200))
end

it "displays dialog, and sets ProductFeatures on Next" do
Expand Down Expand Up @@ -89,7 +92,7 @@
end

it "shows the last dialog when going back" do
subject.class.original_role_id = "bar"
allow(Installation::SystemRole).to receive(:current).and_return("bar")
allow(Yast::GetInstArgs).to receive(:going_back).and_return(true)
expect(Yast::Wizard).to_not receive(:SetContents)
expect(Yast::UI).to_not receive(:UserInput)
Expand All @@ -103,8 +106,7 @@

context "when re-selecting the same role" do
it "just proceeds without a popup" do
subject.class.original_role_id = "foo"

allow(Installation::SystemRole).to receive(:current).and_return("foo")
allow(Yast::Wizard).to receive(:SetContents)
allow(Yast::UI).to receive(:UserInput)
.and_return("foo", :next)
Expand All @@ -120,8 +122,7 @@

context "when re-selecting a different role" do
it "displays a popup, and proceeds if Continue is answered" do
subject.class.original_role_id = "bar"

allow(Installation::SystemRole).to receive(:current).and_return("bar")
allow(Yast::Wizard).to receive(:SetContents)
allow(Yast::UI).to receive(:UserInput)
.and_return("foo", :next)
Expand All @@ -136,8 +137,7 @@
end

it "displays a popup, and does not proceed if Cancel is answered" do
subject.class.original_role_id = "bar"

allow(Installation::SystemRole).to receive(:current).and_return("bar")
allow(Yast::Wizard).to receive(:SetContents)
allow(Yast::UI).to receive(:UserInput)
.and_return("foo", :next, :back)
Expand Down

0 comments on commit fd44cc4

Please sign in to comment.