-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to change the default zone #85
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "cwm" | ||
require "y2firewall/firewalld" | ||
|
||
module Y2Firewall | ||
module Widgets | ||
# This button sets a zone as the default one | ||
class DefaultZoneButton < CWM::PushButton | ||
# @!attribute [r] zone | ||
# @return [Y2Firewall::Firewalld::Zone] Zone to set as 'default' | ||
attr_reader :zone | ||
|
||
# Constructor | ||
# | ||
# @param zone [Y2Firewall::Firewalld::Zone] Zone to set as 'default' | ||
def initialize(zone) | ||
textdomain "firewall" | ||
@zone = zone | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
def label | ||
_("Set As Default") | ||
end | ||
|
||
# Sets the zone to act on | ||
# | ||
# @note If the given zone is the default one then the button is disabled. | ||
# | ||
# @param zone [Y2Firewall::Firewalld::Zone] Zone to set as 'default' | ||
def zone=(zone) | ||
@zone = zone | ||
enable_or_disable | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
def handle | ||
firewall.default_zone = zone.name | ||
:redraw | ||
end | ||
|
||
private | ||
|
||
# Enables or disables the button depending whether the zone is the default one or not | ||
def enable_or_disable | ||
if firewall.default_zone == zone.name | ||
disable | ||
else | ||
enable | ||
end | ||
end | ||
|
||
# Return the current `Y2Firewall::Firewalld` instance | ||
# | ||
# This is just a convenience method. | ||
# | ||
# @return [Y2Firewall::Firewalld] | ||
def firewall | ||
Y2Firewall::Firewalld.instance | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env rspec | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../../../test_helper" | ||
|
||
require "cwm/rspec" | ||
require "y2firewall/widgets/default_zone_button" | ||
|
||
describe Y2Firewall::Widgets::DefaultZoneButton do | ||
include_examples "CWM::PushButton" | ||
|
||
subject(:widget) { described_class.new(zone) } | ||
|
||
let(:zone) do | ||
instance_double( | ||
Y2Firewall::Firewalld::Zone, name: "public", interfaces: [], remove_interface: nil | ||
) | ||
end | ||
|
||
describe "#zone=" do | ||
before do | ||
allow(Y2Firewall::Firewalld.instance).to receive(:default_zone).and_return(zone.name) | ||
end | ||
|
||
let(:other_zone) do | ||
instance_double(Y2Firewall::Firewalld::Zone, name: "dmz") | ||
end | ||
|
||
it "sets the given zone as the one to act on" do | ||
expect { widget.zone = other_zone }.to change { widget.zone }.to other_zone | ||
end | ||
|
||
context "when the given zone is not the default one" do | ||
let(:default_zone) { other_zone } | ||
|
||
it "enables the button" do | ||
expect(widget).to receive(:enable) | ||
widget.zone = other_zone | ||
end | ||
end | ||
|
||
context "when the given zone is the default one" do | ||
it "disables the button" do | ||
expect(widget).to receive(:disable) | ||
widget.zone = zone | ||
end | ||
end | ||
end | ||
|
||
describe "#handle" do | ||
before do | ||
allow(Y2Firewall::Firewalld.instance).to receive(:default_zone=) | ||
end | ||
|
||
it "sets the current zone as the default one" do | ||
expect(Y2Firewall::Firewalld.instance).to receive(:default_zone=).with(zone.name) | ||
widget.handle | ||
end | ||
|
||
it "returns :redraw in order to redraw the interface" do | ||
expect(widget.handle).to eq(:redraw) | ||
end | ||
end | ||
|
||
describe "#zone" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about having an extra column for it, but probably that is something for Ken, I would maybe prefer something like
public (default)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have something similar in the repository list, but it is a slightly different case. But we might append a "(default)" string if preferred.