Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from yast/system-role
System Role (FATE#317481)
- Loading branch information
Showing
10 changed files
with
251 additions
and
8 deletions.
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
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,2 @@ | ||
require "installation/select_system_role" | ||
Installation::SelectSystemRole.new.run |
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,112 @@ | ||
# Copyright (c) 2016 SUSE LLC. | ||
# All Rights Reserved. | ||
|
||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of version 2 or 3 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 about this file by physical or electronic mail, | ||
# you may find current contact information at www.suse.com | ||
|
||
require "yast" | ||
require "ui/installation_dialog" | ||
Yast.import "ProductControl" | ||
Yast.import "ProductFeatures" | ||
|
||
module Installation | ||
class SelectSystemRole < ::UI::InstallationDialog | ||
def initialize | ||
super | ||
|
||
textdomain "installation" | ||
end | ||
|
||
def run | ||
if raw_roles.empty? | ||
log.info "No roles defined, skipping their dialog" | ||
return :auto # skip forward or backward | ||
end | ||
|
||
super | ||
end | ||
|
||
def dialog_title | ||
_("System Role") | ||
end | ||
|
||
def help_text | ||
"" # no Help, besides the descriptions in dialog body | ||
end | ||
|
||
def dialog_content | ||
ui_roles = role_attributes.each_with_object(VBox()) do |r, vbox| | ||
vbox << Left(RadioButton(Id(r[:id]), r[:label])) | ||
vbox << HBox( | ||
HSpacing(4), | ||
Left(Label(r[:description])) | ||
) | ||
vbox << VSpacing(2) | ||
end | ||
|
||
RadioButtonGroup(Id(:roles), ui_roles) | ||
end | ||
|
||
def create_dialog | ||
clear_role | ||
ok = super | ||
Yast::UI.ChangeWidget(Id(:roles), :CurrentButton, role_attributes.first[:id]) | ||
ok | ||
end | ||
|
||
def next_handler | ||
role_id = Yast::UI.QueryWidget(Id(:roles), :CurrentButton) | ||
apply_role(role_id) | ||
|
||
super | ||
end | ||
|
||
private | ||
|
||
def clear_role | ||
Yast::ProductFeatures.ClearOverlay | ||
end | ||
|
||
def apply_role(role_id) | ||
log.info "Applying system role '#{role_id}'" | ||
features = raw_roles.find { |r| r["id"] == role_id } | ||
features = features.dup | ||
features.delete("id") | ||
Yast::ProductFeatures.SetOverlay(features) | ||
end | ||
|
||
# the contents is an overlay for ProductFeatures sections | ||
# [ | ||
# { "id" => "foo", "partitioning" => ... }, | ||
# { "id" => "bar", "partitioning" => ... , "software" => ...}, | ||
# ] | ||
# @return [Array<Hash{String => Object}>] | ||
def raw_roles | ||
Yast::ProductControl.productControl.fetch("system_roles", []) | ||
end | ||
|
||
def role_attributes | ||
raw_roles.map do |r| | ||
id = r["id"] | ||
|
||
{ | ||
id: id, | ||
label: Yast::ProductControl.GetTranslatedText(id), | ||
description: Yast::ProductControl.GetTranslatedText(id + "_description") | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#! /usr/bin/env rspec | ||
|
||
require_relative "./test_helper" | ||
|
||
require "installation/select_system_role" | ||
Yast.import "ProductControl" | ||
|
||
describe ::Installation::SelectSystemRole do | ||
subject { Installation::SelectSystemRole.new } | ||
|
||
before do | ||
allow(Yast::ProductControl).to receive(:GetTranslatedText) do |s| | ||
"Lorem Ipsum #{s}" | ||
end | ||
|
||
allow(Yast::UI).to receive(:ChangeWidget) | ||
end | ||
|
||
describe "#run" do | ||
context "when no roles are defined" do | ||
before do | ||
allow(Yast::ProductControl).to receive(:productControl) | ||
.and_return("system_roles" => []) | ||
end | ||
|
||
it "does not display dialog, and returns :auto" do | ||
expect(Yast::Wizard).to_not receive(:SetContents) | ||
expect(subject.run).to eq(:auto) | ||
end | ||
end | ||
|
||
context "when some roles are defined" do | ||
let(:control_file_roles) do | ||
[ | ||
{ "id" => "foo", "partitioning" => { "format" => true } }, | ||
{ "id" => "bar", "software" => { "desktop" => "knome" } } | ||
] | ||
end | ||
|
||
before do | ||
allow(Yast::ProductControl).to receive(:productControl) | ||
.and_return("system_roles" => control_file_roles) | ||
end | ||
|
||
it "displays dialog, and sets ProductFeatures on Next" do | ||
allow(Yast::Wizard).to receive(:SetContents) | ||
allow(Yast::UI).to receive(:UserInput) | ||
.and_return(:next) | ||
allow(Yast::UI).to receive(:QueryWidget) | ||
.with(Id(:roles), :CurrentButton).and_return("foo") | ||
|
||
expect(Yast::ProductFeatures).to receive(:ClearOverlay) | ||
expect(Yast::ProductFeatures).to receive(:SetOverlay) # .with | ||
|
||
expect(subject.run).to eq(:next) | ||
end | ||
|
||
it "displays dialog, and leaves ProductFeatures on Back" do | ||
allow(Yast::Wizard).to receive(:SetContents) | ||
allow(Yast::UI).to receive(:UserInput) | ||
.and_return(:back) | ||
expect(Yast::ProductFeatures).to receive(:ClearOverlay) | ||
expect(Yast::ProductFeatures).to_not receive(:SetOverlay) | ||
|
||
expect(subject.run).to eq(:back) | ||
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