launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #30807
Re: [Merge] ~ines-almeida/launchpad:social-accounts-edit-view into launchpad:master
Diff comments:
> diff --git a/lib/lp/registry/browser/person.py b/lib/lp/registry/browser/person.py
> index 65ae0ba..b247e59 100644
> --- a/lib/lp/registry/browser/person.py
> +++ b/lib/lp/registry/browser/person.py
> @@ -2415,6 +2426,69 @@ class PersonEditIRCNicknamesView(LaunchpadFormView):
> )
>
>
> +class PersonEditMatrixAccountsView(LaunchpadFormView):
> + schema = Interface
> +
> + @property
> + def page_title(self):
> + return smartquote(f"{self.context.displayname}'s Matrix accounts")
> +
> + label = page_title
> +
> + @property
> + def cancel_url(self):
> + return canonical_url(self.context)
> +
> + @property
> + def matrix_accounts(self):
We might change the API to list social_accounts separated by platform. If so, I will remove this. If not, then I'll see what better way there is to list these
> + accounts = []
> + for account in self.context.social_accounts:
> + if account.platform == SocialPlatform.MATRIX:
> + accounts.append(account)
> + return accounts
> +
> + @action(_("Save Changes"), name="save")
> + def save(self, action, data):
> + """Process the matrix accounts form."""
> + form = self.request.form
> + for social_account in self.matrix_accounts:
> + if form.get(f"remove_{social_account.id}"):
> + social_account.destroySelf()
> +
> + else:
> + updated_identity = {
> + field: form.get(f"{field}_{social_account.id}")
> + for field in SocialPlatform.matrix_identity_fields
> + }
> + if not all(updated_identity.values()):
> + self.request.response.addErrorNotification(
> + "Fields cannot be empty."
> + )
> + return
> +
> + social_account.identity = updated_identity
> +
> + new_account_identity = {
> + field_name: form.get(f"new_{field_name}")
> + for field_name in SocialPlatform.matrix_identity_fields
> + }
> +
> + if all(new_account_identity.values()):
> + getUtility(ISocialAccountSet).new(
> + self.context, SocialPlatform.MATRIX, new_account_identity
> + )
> +
> + elif any(new_account_identity.values()):
> + for field_key, field_value in new_account_identity.items():
> + self.__setattr__(f"new_{field_key}", field_value)
> + self.request.response.addErrorNotification(
> + "All fields must be filled."
> + )
> +
> + # Clean the cached social_accounts if form is saved
> + del get_property_cache(self.context).social_accounts
> +
> +
> class PersonEditJabberIDsView(LaunchpadFormView):
> schema = IJabberID
> field_names = ["jabberid"]
> diff --git a/lib/lp/registry/interfaces/socialaccount.py b/lib/lp/registry/interfaces/socialaccount.py
> index 7e910cc..e8c219e 100644
> --- a/lib/lp/registry/interfaces/socialaccount.py
> +++ b/lib/lp/registry/interfaces/socialaccount.py
> @@ -40,6 +40,7 @@ class SocialPlatform(DBEnumeratedType):
> The Social Account will hold Matrix account info.
> """,
> )
> + matrix_identity_fields = ["nickname", "network"]
I would rather this was fetched from a simple Matrix class that contains this + other information on the specific social platform. This was a quick way of having it for now. Thoughts?
>
>
> # XXX pelpsi 2023-12-14 bug=760849: "beta" is a lie to get WADL generation
--
https://code.launchpad.net/~ines-almeida/launchpad/+git/launchpad/+merge/458537
Your team Launchpad code reviewers is requested to review the proposed merge of ~ines-almeida/launchpad:social-accounts-edit-view into launchpad:master.
Follow ups