Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-950] Cannot save new login if personal ownership is disabled #3265

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LRNcardozoWDF
Copy link
Member

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Fixes #1874

Add the ability to select a collection for the new item if personal ownership is disabled.

Code changes

  • LoginAddViewController.cs: Refactor how the number of rows and sections are calculated based on the value of the flag _personalOwnershipPolicyApplies. Added cells to warn the user the personal ownership is disabled and allow organisation and collection selection.
  • FormEntryTableViewCell.cs: Allow a form entry empty.

Screenshots

BEFORE
image

AFTER
image
image

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

Comment on lines +73 to +75
_organizationService = ServiceContainer.Resolve<IOrganizationService>("organizationService");
_collectionService = ServiceContainer.Resolve<ICollectionService>("collectionService");
_policyService = ServiceContainer.Resolve<IPolicyService>("policyService");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ No need to use the string key.

Comment on lines -131 to -136
if (height.HasValue)
{
ContentView.AddConstraint(
NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, height.Value));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ why was this removed from here? Doesn't it break some case for the TextField?

},
CollectionIds = CollectionCell.SelectedItem.ToString() == AppResources.NoCollectionsToList ?
null : new HashSet<string> { _collections.ElementAtOrDefault(CollectionCell.SelectedIndex)?.Id },
OrganizationId = OrganizationCell.SelectedItem != null ? _organizations.ElementAtOrDefault(CollectionCell.SelectedIndex)?.Id : null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Shouldn't this be using the SelectedIndex of the OrganizationCell?

Comment on lines +242 to +243
CollectionIds = CollectionCell.SelectedItem.ToString() == AppResources.NoCollectionsToList ?
null : new HashSet<string> { _collections.ElementAtOrDefault(CollectionCell.SelectedIndex)?.Id },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Format

Suggested change
CollectionIds = CollectionCell.SelectedItem.ToString() == AppResources.NoCollectionsToList ?
null : new HashSet<string> { _collections.ElementAtOrDefault(CollectionCell.SelectedIndex)?.Id },
CollectionIds = CollectionCell.SelectedItem.ToString() == AppResources.NoCollectionsToList
? null
: new HashSet<string> { _collections.ElementAtOrDefault(CollectionCell.SelectedIndex)?.Id },

@@ -121,6 +179,19 @@ public override void ViewDidLoad()
base.ViewDidLoad();
}

private void Type_ValueChanged(object sender, EventArgs e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 Rename to something more meaningful of what this method does, like OrganizationCell_ValueChanged

Comment on lines +185 to +191
var collectionsNames = _writeableCollections.Where(c => c.OrganizationId == _organizations.ElementAt(OrganizationCell.SelectedIndex).Id).Select(s => s.Name).ToList();
if (collectionsNames.Count == 0)
{
collectionsNames.Insert(0, AppResources.NoCollectionsToList);
}

CollectionCell.Items = collectionsNames;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 Extract to method for reuse; given this is the same as in above lines


_collections = _collectionService.GetAllDecryptedAsync().GetAwaiter().GetResult();
_writeableCollections = _collections.Where(c => !c.ReadOnly).OrderBy(c => c.Name).ToList();
var collectionsNames = _writeableCollections.Where(c => c.OrganizationId == _organizations.ElementAt(OrganizationCell.SelectedIndex).Id).Select(s => s.Name).ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Format

Suggested change
var collectionsNames = _writeableCollections.Where(c => c.OrganizationId == _organizations.ElementAt(OrganizationCell.SelectedIndex).Id).Select(s => s.Name).ToList();
var collectionsNames = _writeableCollections
.Where(c => c.OrganizationId == _organizations.ElementAt(OrganizationCell.SelectedIndex).Id)
.Select(s => s.Name)
.ToList();

@@ -113,6 +135,42 @@ public override void ViewDidLoad()
folderNames.Insert(0, AppResources.FolderNone);
FolderCell.Items = folderNames;

_personalOwnershipPolicyApplies = _policyService.PolicyAppliesToUser(PolicyType.PersonalOwnership).GetAwaiter().GetResult();
var index = 0;
if (_personalOwnershipPolicyApplies)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 This method is pretty huge, IMO personal ownership logic should be extracted to a different method we can call here so it doesn't make this method even bigger than it is.

OrganizationCell.Items = _organizations.Select(o => o.Name).ToList();
OrganizationCell.ValueChanged += Type_ValueChanged;

_collections = _collectionService.GetAllDecryptedAsync().GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Could you test if _collectionService.GetAllDecryptedAsync takes too long the app crashes? You can mock this by just adding a task delay of some seconds in the first line inside GetAllDecryptedAsync() which will be mocking the case of a really large number of collections to decrypt.
We shouldn't be using GetAwaiter().GerResult() and just put some loading on the view and performing the work asynchronously updating the table view afterwards but well I know we already have other calls that use that like Folders; so I guess it's "fine" for now as long as this loads "fast" and doesn't crash the app because ViewDidLoad took to long to finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants