Skip to content
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

Add a list of interfaces #81

Merged
merged 23 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6d7e948
Add an interfaces list
imobachgs Sep 12, 2018
f67a60b
Add interfaces page unit tests
imobachgs Sep 13, 2018
b6813d3
Add a UIState to keep UI state
teclator Sep 14, 2018
ec8e082
Add a zone to change the assigned zone
imobachgs Sep 17, 2018
a05e9a2
Add a button to open which allows to change the zone
imobachgs Sep 17, 2018
eb2d8f9
Integrate interfaces list with widgets to change the assigned zone
imobachgs Sep 17, 2018
fbe6b99
Allow to assign a interface to the default zone
imobachgs Sep 17, 2018
9c4cd28
Drop interfaces pages
imobachgs Sep 17, 2018
ab36f36
Add missing textdomain calls
imobachgs Sep 17, 2018
b8000e2
Fix ZoneOptions#initialize documentation
imobachgs Sep 17, 2018
f6e6982
Documentation fixes
imobachgs Sep 17, 2018
8a7680d
Y2Firewall::UIState inherits from CWM::UIState
imobachgs Sep 18, 2018
ba18814
Use a pop-up when changing an interface's zone
imobachgs Sep 18, 2018
c6d1994
Widgets::ZoneOptions takes care of modifying the zone
imobachgs Sep 18, 2018
9ac34af
Fix interfaces table default selection
imobachgs Sep 19, 2018
4f81442
ChangeZoneButton does not select the current row anymore
imobachgs Sep 19, 2018
b005e9b
Fix InterfacesTable documentation
imobachgs Sep 19, 2018
67a4b33
Adapted to the new Y2Firewall::Firewalld::Interface
imobachgs Sep 19, 2018
2c982d8
Bump yast2.rpm dependency
imobachgs Sep 19, 2018
f90c64f
Clean-up
imobachgs Sep 19, 2018
53a5cf5
Fix InterfacesTable test
imobachgs Sep 19, 2018
6b82ddb
Update from code review
imobachgs Sep 20, 2018
a8395d0
Update from code review
imobachgs Sep 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions package/yast2-firewall.spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ License: GPL-2.0
BuildRequires: perl-XML-Writer update-desktop-files yast2-testsuite
BuildRequires: yast2-devtools >= 3.1.10

# Extended firewalld API
# Y2Firewall::Firewalld.instance.current_service_names
BuildRequires: yast2 >= 4.0.91
# Y2Firewall::Firewalld::Interface
BuildRequires: yast2 >= 4.0.96
BuildRequires: rubygem(%rb_default_ruby_abi:yast-rake)
BuildRequires: rubygem(%rb_default_ruby_abi:rspec)

# Extended firewalld API
# Y2Firewall::Firewalld.instance.current_service_names
Requires: yast2 >= 4.0.91
# Y2Firewall::Firewalld::Interface
Requires: yast2 >= 4.0.96

# ButtonBox widget
Conflicts: yast2-ycp-ui-bindings < 2.17.3
Expand Down
63 changes: 63 additions & 0 deletions src/lib/y2firewall/dialogs/change_zone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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/popup"
require "y2firewall/widgets/zone_options"

module Y2Firewall
module Dialogs
# This dialog allows the user to select which zone should be an interface assigned to.
imobachgs marked this conversation as resolved.
Show resolved Hide resolved
class ChangeZone < ::CWM::Popup
# @!attribute [r] interface
# @return [Y2Firewall::Firewalld::Interface] Interface to act on
attr_reader :interface

# Constructor
#
# @param interface [Y2Firewall::Firewalld::Interface] Interface to act on
def initialize(interface)
textdomain "firewall"
@interface = interface
end

# @macro seeAbstractWidget
def title
_("Change Zone")
end

# @macro seeCustomWidget
def contents
VBox(zone_options)
end

private

# Returns a combobox to select the zone
#
# @note The widget is 'memoized'.
#
# @return [Y2Firewall::Widgets::ZoneOptions]
def zone_options
@zone_options ||= Y2Firewall::Widgets::ZoneOptions.new(interface)
end
end
end
end
60 changes: 60 additions & 0 deletions src/lib/y2firewall/ui_state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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/ui_state"

module Y2Firewall
# Singleton class to keep the position of the user in the UI and other similar
# information that needs to be rememberd across UI redraws to give the user a
# sense of continuity.
class UIState < CWM::UIState
# Method to be called when the user decides to visit a given page by
# clicking in one node of the general tree.
#
# It remembers the decision so the user is taken back to a sensible point of
# the tree (very often the last he decided to visit) after redrawing.
#
# @param [CWM::Page] page associated to the tree node
def go_to_tree_node(page)
super
self.candidate_nodes =
if page.respond_to?(:zone)
zone_page_candidates(page)
else
[page.label]
end
end

protected

# @see CWM::UIState#textdomain_name
def textdomain_name
"firewall"
end

# List of candidate nodes to go back after opening a zone view in the tree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same than above

def zone_page_candidates(page)
zone = page.zone

[zone.name]
end
end
end
55 changes: 55 additions & 0 deletions src/lib/y2firewall/widgets/change_zone_button.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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/dialogs/change_zone"
require "y2firewall/ui_state"

module Y2Firewall
module Widgets
# This button opens a dialog to change the zone for a given interface
class ChangeZoneButton < CWM::PushButton
# @!attribute [r] interface
# @return [Y2Firewall::Firewalld::Interface] Interface to act on
attr_accessor :interface

# Constructor
#
# @param interface [Y2Firewall::Firewalld::Interface] Interface to act on
def initialize(interface)
textdomain "firewall"
@interface = interface
end

# @see seeAbstractWidget
def label
_("Change Zone")
end

# @see seeAbstractWidget
def handle
return nil unless interface
result = Dialogs::ChangeZone.run(interface)
result == :ok ? :redraw : nil
end
end
end
end
100 changes: 100 additions & 0 deletions src/lib/y2firewall/widgets/interfaces_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 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 "cwm/table"
require "y2firewall/ui_state"

module Y2Firewall
module Widgets
# A table with all {Y2Firewall::Firewalld::Interface}s.
class InterfacesTable < ::CWM::Table
DEFAULT_ZONE_NAME = "default".freeze

# @!attribute [r] interfaces
# @return [Array<Y2Firewall::Firewalld::Interface>] Interfaces
attr_reader :interfaces

# Constructor
#
# @param interfaces [Array<Y2Firewall::Firewalld::Interfaces>] Interfaces to list
# @param change_zone_button [Y2Firewall::Widgets::ChangeZoneButton] Button to change assigned
# zone
def initialize(interfaces, change_zone_button)
textdomain "firewall"
@interfaces = interfaces
@change_zone_button = change_zone_button
end

# @macro seeAbstractWidget
def opt
[:notify, :immediate]
end

# @macro seeAbstractWidget
def init
interface = Y2Firewall::UIState.instance.row_id
if interface && interfaces.map(&:id).include?(interface)
self.value = interface
end
change_zone_button.interface = selected_interface
end

# @see CWM::Table#header
def header
[
_("Device"),
_("Zone"),
_("Name")
]
end

# @see CWM::Table#items
def items
interfaces.map do |iface|
[
iface.id,
iface.name,
iface.zone ? iface.zone.name : DEFAULT_ZONE_NAME,
iface.device_name
]
end
end

# @macro seeAbstractWidget
def handle(event)
return nil unless event["EventReason"] == "SelectionChanged"
UIState.instance.select_row(value)
change_zone_button.interface = selected_interface
nil
end

def selected_interface
interfaces.find { |i| i.id == value }
end

private

# @return [Y2Firewalld::Widgets::ChangeZoneButton] Button to change the assigned zone
attr_reader :change_zone_button
end
end
end
22 changes: 14 additions & 8 deletions src/lib/y2firewall/widgets/overview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require "cwm/tree_pager"
require "y2firewall/widgets/pages"
require "y2firewall/helpers/interfaces"
require "y2firewall/ui_state"

module Y2Firewall
module Widgets
Expand Down Expand Up @@ -71,6 +72,19 @@ def items
]
end

# Overrides default behavior of TreePager to register the new state with
# {UIState} before jumping to the tree node
def switch_page(page)
UIState.instance.go_to_tree_node(page)
super
end

# Ensures the tree is properly initialized according to {UIState} after
# a redraw.
def initial_page
UIState.instance.find_tree_node(@pages) || super
end

private

# @return [CWM::PagerTreeItem]
Expand All @@ -81,15 +95,7 @@ def startup_item

# @return [CWM::PagerTreeItem]
def interfaces_item
ifcs = known_interfaces
children = ifcs.map { |i| interface_item(i) }
page = Pages::Interfaces.new(self)
CWM::PagerTreeItem.new(page, children: children)
end

# @return [CWM::PagerTreeItem]
def interface_item(i)
page = Pages::Interface.new(i, self)
CWM::PagerTreeItem.new(page)
end

Expand Down