Skip to content

Commit

Permalink
Fix 'Toggle Mode' bug for non-English locale (see https://bugzilla.op…
Browse files Browse the repository at this point in the history
  • Loading branch information
belphegor-belbel committed Jul 18, 2017
1 parent 1fff9ed commit 98bfd42
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions src/include/apparmor/config_complain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def updateComplain(id, profile, mode, showAll)
nil
end

def getRecordList(showAll)
def updateRecordList(showAll)
_Settings = {}
Ops.set(_Settings, "list", "1")

Expand All @@ -99,7 +99,7 @@ def getRecordList(showAll)
Ops.set(_Settings, "showall", "0")
end

recList = []
@recList = []
key = 1

# restarts ag_complain agent if necessary
Expand All @@ -112,25 +112,18 @@ def getRecordList(showAll)
)
end

translation_mapping = {
# translators: string is value in table for mode of apparmor
"enforce" => _("enforce"),
"complain" => _("complain"),
}

Builtins.foreach(db) do |record|
recList = Builtins.add(
recList,
Item(Id(key), Ops.get(record, "name"), translation_mapping[record["mode"]])
@recList = Builtins.add(
@recList,
Item(Id(key), Ops.get(record, "name"), record["mode"])
)
key = Ops.add(key, 1)
end

deep_copy(recList)
nil
end

def getProfModeForm(recList, showAll)
recList = deep_copy(recList)
def getProfModeForm(showAll)
allBtn = PushButton(Id(:showAll), _("Show All Profiles"))
allText = _("Configure Mode for Active Profiles")

Expand All @@ -139,6 +132,21 @@ def getProfModeForm(recList, showAll)
allText = _("Configure Mode for All Profiles")
end

translation_mapping = {
# translators: string is value in table for mode of apparmor
"enforce" => _("enforce"),
"complain" => _("complain"),
}

recListTranslated = []
Builtins.foreach(@recList) do |record|
recListTranslated = Builtins.add(
recListTranslated,
Item(record.params[0], record.params[1],
translation_mapping[record.params[2]])
)
end

modeForm = Frame(
Id(:changeMode),
allText,
Expand All @@ -151,7 +159,7 @@ def getProfModeForm(recList, showAll)
Id(:table),
Opt(:notify),
Header(_("Profile Name"), _("Mode")),
recList
recListTranslated
)
),
VSpacing(0.5),
Expand All @@ -168,16 +176,16 @@ def getProfModeForm(recList, showAll)
end

def updateModeConfigForm(showAll)
recList = getRecordList(showAll)
newModeForm = getProfModeForm(recList, showAll)
updateRecordList(showAll)
newModeForm = getProfModeForm(showAll)

deep_copy(newModeForm)
end

# Profile Mode Configuration -- Sets Complain and Enforce Behavior
def profileModeConfigForm
recList = getRecordList(@showAll)
modeForm = getProfModeForm(recList, @showAll)
updateRecordList(@showAll)
modeForm = getProfModeForm(@showAll)
Wizard.CreateDialog
Wizard.SetContentsButtons(
_("Profile Mode Configuration"),
Expand Down Expand Up @@ -256,13 +264,12 @@ def profileModeConfigForm
1,
""
)
mode = Ops.get_string(
Convert.to_term(
UI.QueryWidget(Id(:table), term(:Item, itemselected))
),
2,
""
)
mode = "!unknown!"
Builtins.foreach(@recList) do |record|
if record.params[1] == profile
mode = record.params[2]
end
end

updateComplain(id, profile, mode, @showAll)
modified = true
Expand Down

0 comments on commit 98bfd42

Please sign in to comment.