Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions rust/agama-dbus-server/src/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ pub struct GenericQuestion {
/// possible answers for question
options: Vec<String>,
/// default answer. Can be used as hint or preselection
default_option: String,
default_option: Option<String>,
/// Confirmed answer. If empty then not answered yet.
answer: String,
}

impl GenericQuestion {
pub fn new(id: u32, text: String, options: Vec<String>, default_option: String) -> Self {
pub fn new(
id: u32,
text: String,
options: Vec<String>,
default_option: Option<String>,
) -> Self {
Self {
id,
text,
Expand Down Expand Up @@ -55,7 +60,10 @@ impl GenericQuestion {

#[dbus_interface(property)]
pub fn default_option(&self) -> &str {
self.default_option.as_str()
match self.default_option {
Some(ref option) => option.as_str(),
None => "",
}
}

#[dbus_interface(property)]
Expand Down Expand Up @@ -106,7 +114,7 @@ impl LuksQuestion {
id,
msg,
vec!["skip".to_string(), "decrypt".to_string()],
"skip".to_string(),
Some("skip".to_string()),
);

Self {
Expand Down Expand Up @@ -164,12 +172,12 @@ impl Questions {
let id = self.last_id;
self.last_id += 1; // TODO use some thread safety
let options = options.iter().map(|o| o.to_string()).collect();
// TODO: enforce default option and do not use array for it to avoid that unwrap
// TODO: enforce default option and do not use an array
let question = GenericQuestion::new(
id,
text.to_string(),
options,
default_option.first().unwrap().to_string(),
default_option.first().map(|o| o.to_string()),
);
let object_path = ObjectPath::try_from(question.object_path()).unwrap();

Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama-cli.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jul 5 11:11:20 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Fix the questions service to handle questions with no default
option (gh#openSUSE/agama#649).

-------------------------------------------------------------------
Thu Jun 1 08:14:14 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down