Skip to content

Commit

Permalink
Disable bulk finalize for configurations that previously had finalize…
Browse files Browse the repository at this point in the history
… in form entry disabled
  • Loading branch information
seadowg committed Oct 14, 2023
1 parent 4c2c2c2 commit df0d3ef
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FormEndViewModel(
}

fun isFinalizeEnabled(): Boolean {
return settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_FINALIZE)
return settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY)
}

fun shouldFormBeSentAutomatically(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class FormEntryAccessPreferencesFragment : BaseAdminPreferencesFragment() {
settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM)

findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).isEnabled =
settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM) && findPreference(ProtectedProjectKeys.KEY_FINALIZE).isChecked
settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM) && findPreference(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY).isChecked
findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference, newValue: Any? ->
findPreference(ProtectedProjectKeys.KEY_FINALIZE).isEnabled = newValue as Boolean
findPreference(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY).isEnabled = newValue as Boolean
true
}

findPreference(ProtectedProjectKeys.KEY_FINALIZE).isEnabled = findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).isChecked
findPreference(ProtectedProjectKeys.KEY_FINALIZE).onPreferenceChangeListener =
findPreference(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY).isEnabled = findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).isChecked
findPreference(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY).onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference, newValue: Any? ->
findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).isEnabled = newValue as Boolean
true
Expand All @@ -62,26 +62,26 @@ class FormEntryAccessPreferencesFragment : BaseAdminPreferencesFragment() {
settingsProvider.getProtectedSettings().save(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM, false)
settingsProvider.getProtectedSettings().save(ProtectedProjectKeys.KEY_EDIT_SAVED, false)
settingsProvider.getProtectedSettings().save(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false)
settingsProvider.getProtectedSettings().save(ProtectedProjectKeys.KEY_FINALIZE, true)
settingsProvider.getProtectedSettings().save(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, true)
settingsProvider.getProtectedSettings().save(ProtectedProjectKeys.KEY_JUMP_TO, false)
settingsProvider.getUnprotectedSettings().save(ProjectKeys.KEY_CONSTRAINT_BEHAVIOR, ProjectKeys.CONSTRAINT_BEHAVIOR_ON_SWIPE)

findPreference(ProtectedProjectKeys.KEY_JUMP_TO).isEnabled = false
findPreference(ProtectedProjectKeys.KEY_SAVE_MID).isEnabled = false
findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).isEnabled = false
findPreference(ProtectedProjectKeys.KEY_FINALIZE).isEnabled = false
findPreference(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY).isEnabled = false
findPreference(ProtectedProjectKeys.KEY_JUMP_TO).isChecked = false
findPreference(ProtectedProjectKeys.KEY_SAVE_MID).isChecked = false
findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).isChecked = false
findPreference(ProtectedProjectKeys.KEY_FINALIZE).isChecked = true
findPreference(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY).isChecked = true
}

private fun onMovingBackwardsEnabled() {
settingsProvider.getProtectedSettings().save(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM, true)
findPreference(ProtectedProjectKeys.KEY_JUMP_TO).isEnabled = true
findPreference(ProtectedProjectKeys.KEY_SAVE_MID).isEnabled = true
findPreference(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT).isEnabled = true
findPreference(ProtectedProjectKeys.KEY_FINALIZE).isEnabled = true
findPreference(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY).isEnabled = true
}

private fun findPreference(key: String): CheckBoxPreference {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
android:title="@string/save_as_draft"
app:iconSpaceReserved="false" />
<CheckBoxPreference
android:key="finalize"
android:key="finalize_in_form_entry"
android:title="@string/finalize"
app:iconSpaceReserved="false" />
</PreferenceCategory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,32 @@ public List<Migration> getProtectedMigrations() {
.withValues(false, false)
.toPairs(
ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, true,
ProtectedProjectKeys.KEY_FINALIZE, false
ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, false
)
.withValues(false, true)
.toPairs(
ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false,
ProtectedProjectKeys.KEY_FINALIZE, true
ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, true
)
.withValues(false, null)
.toPairs(
ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false,
ProtectedProjectKeys.KEY_FINALIZE, true
ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, true
),
removeKey("mark_as_finalized"),
removeKey("default_completed"),
updateKeys(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM)
.withValues(false)
.toPairs(
ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false,
ProtectedProjectKeys.KEY_FINALIZE, true
)
ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, true
),
updateKeys("finalize").withValues(false)
.toPairs(
ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, false,
ProtectedProjectKeys.KEY_BULK_FINALIZE, false
),
removeKey("finalize")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object ProtectedProjectKeys {
const val KEY_JUMP_TO = "jump_to"
const val KEY_SAVE_MID = "save_mid"
const val KEY_SAVE_AS_DRAFT = "save_as_draft"
const val KEY_FINALIZE = "finalize"
const val KEY_FINALIZE_IN_FORM_ENTRY = "finalize_in_form_entry"

const val ALLOW_OTHER_WAYS_OF_EDITING_FORM = "allow_other_ways_of_editing_form"
const val KEY_BULK_FINALIZE = "bulk_finalize"
Expand Down Expand Up @@ -82,7 +82,7 @@ object ProtectedProjectKeys {
KEY_JUMP_TO,
KEY_SAVE_MID,
KEY_SAVE_AS_DRAFT,
KEY_FINALIZE,
KEY_FINALIZE_IN_FORM_ENTRY,
ALLOW_OTHER_WAYS_OF_EDITING_FORM,
KEY_BULK_FINALIZE
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void when_markAsFinalized_wasDisabled_and_defaultCompleted_wasDisabled_th

runMigrations();

assertSettings(protectedSettings, ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, true, ProtectedProjectKeys.KEY_FINALIZE, false);
assertSettings(protectedSettings, ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, true, ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, false);

assertThat(protectedSettings.contains("mark_as_finalized"), equalTo(false));
assertThat(protectedSettings.contains("default_completed"), equalTo(false));
Expand All @@ -273,7 +273,7 @@ public void when_markAsFinalized_wasDisabled_and_defaultCompleted_wasEnabled_the

runMigrations();

assertSettings(protectedSettings, ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false, ProtectedProjectKeys.KEY_FINALIZE, true);
assertSettings(protectedSettings, ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false, ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, true);

assertThat(protectedSettings.contains("mark_as_finalized"), equalTo(false));
assertThat(protectedSettings.contains("default_completed"), equalTo(false));
Expand All @@ -285,7 +285,7 @@ public void when_markAsFinalized_wasDisabled_and_defaultCompleted_wasNotSet_then

runMigrations();

assertSettings(protectedSettings, ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false, ProtectedProjectKeys.KEY_FINALIZE, true);
assertSettings(protectedSettings, ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, false, ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, true);

assertThat(protectedSettings.contains("mark_as_finalized"), equalTo(false));
assertThat(protectedSettings.contains("default_completed"), equalTo(false));
Expand Down Expand Up @@ -322,31 +322,52 @@ public void when_AllowOtherWaysOfEditingFormIsDisabled_thenSaveAsDraftShouldBeDi
initSettings(protectedSettings,
ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM, false,
ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, true,
ProtectedProjectKeys.KEY_FINALIZE, false
ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, false
);

runMigrations();

assertThat(protectedSettings.contains(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM), equalTo(true));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM), equalTo(false));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT), equalTo(false));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_FINALIZE), equalTo(true));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY), equalTo(true));
}

@Test
public void when_AllowOtherWaysOfEditingFormIsEnabled_thenDoNotUpdateSaveAsDraftOrFinalize() {
initSettings(protectedSettings,
ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM, true,
ProtectedProjectKeys.KEY_SAVE_AS_DRAFT, true,
ProtectedProjectKeys.KEY_FINALIZE, false
ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY, false
);

runMigrations();

assertThat(protectedSettings.contains(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM), equalTo(true));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.ALLOW_OTHER_WAYS_OF_EDITING_FORM), equalTo(true));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_SAVE_AS_DRAFT), equalTo(true));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_FINALIZE), equalTo(false));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY), equalTo(false));
}

@Test
public void migratesFinalizeInFormEntryToNewKey() {
initSettings(protectedSettings, "finalize", false);

runMigrations();

assertThat(protectedSettings.contains("finalize"), equalTo(false));
assertThat(protectedSettings.contains(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY), equalTo(true));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_FINALIZE_IN_FORM_ENTRY), equalTo(false));
}

@Test
public void whenFinalizeInFormEntryWasDisabledWithOldKey_disablesBulkFinalize() {
initSettings(protectedSettings, "finalize", false);

runMigrations();

assertThat(protectedSettings.contains(ProtectedProjectKeys.KEY_BULK_FINALIZE), equalTo(true));
assertThat(protectedSettings.getBoolean(ProtectedProjectKeys.KEY_BULK_FINALIZE), equalTo(false));
}

private void runMigrations() {
Expand Down

0 comments on commit df0d3ef

Please sign in to comment.