Skip to content

Commit

Permalink
Merge pull request #96 from yast/services_validation
Browse files Browse the repository at this point in the history
Warn the user about unsaved changes (services selection)
  • Loading branch information
teclator committed Oct 9, 2018
2 parents 73cb27e + e78366d commit 593a1e2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions package/yast2-firewall.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Oct 9 08:55:56 UTC 2018 - knut.anderssen@suse.com

- Alert the user about unsaved changes when leaving the zone
services configuration without applying changes (fate#324662)
- 4.0.30

-------------------------------------------------------------------
Fri Oct 5 06:49:03 UTC 2018 - knut.anderssen@suse.com

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


Name: yast2-firewall
Version: 4.0.29
Version: 4.0.30
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
13 changes: 13 additions & 0 deletions src/lib/y2firewall/widgets/allowed_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def help
)
end

def validate
return true if selected_services.empty?
# TRANSLATORS: popup question
msg = _("The selection of services will be lost if you leave without\n" \
"applying the changes.\n\nDo you really want to continue?\n")

Yast::Popup.YesNo(msg)
end

private

# @!attribute [r] known_services_table
Expand Down Expand Up @@ -128,6 +137,10 @@ def refresh_services
allowed_services_table.services = zone.services.clone
end

def selected_services
known_services_table.selected_services + allowed_services_table.selected_services
end

# Return a list of buttons to add/remove elements
#
# @return [Array<Yast::Term>] Buttons set UI terms
Expand Down
26 changes: 26 additions & 0 deletions test/lib/y2firewall/widgets/allowed_services_test.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@
.with(widget_id: "allowed:#{zone.name}").and_return(allowed_svcs_table)
end

describe "#validate" do
context "when no service has been selected" do
before do
allow(available_svcs_table).to receive(:selected_services).and_return([])
allow(allowed_svcs_table).to receive(:selected_services).and_return([])
end

it "returns true" do
expect(widget.validate).to eq(true)
end
end

context "when some service has been selected" do
it "warns the user about unsaved changed and ask for continuing" do
expect(Yast::Popup).to receive("YesNo").with(/Do you really want to continue/)
widget.validate
end

it "returns whether the user wanted to continue or not" do
expect(Yast::Popup).to receive("YesNo").and_return(false, true)
expect(widget.validate).to eq(false)
expect(widget.validate).to eq(true)
end
end
end

describe "#handle" do
context "when it receives an event to add a service" do
let(:event) { { "ID" => :add } }
Expand Down

0 comments on commit 593a1e2

Please sign in to comment.