Skip to content

Commit

Permalink
Merge 6b82ddb into d67c998
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 20, 2018
2 parents d67c998 + 6b82ddb commit 4fd07e5
Show file tree
Hide file tree
Showing 13 changed files with 800 additions and 58 deletions.
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.
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
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

0 comments on commit 4fd07e5

Please sign in to comment.