launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #30830
Re: [Merge] ~ines-almeida/launchpad:social-accounts-edit-view into launchpad:master
Added tests and rebased branch from master after API branch got merged
Diff comments:
> diff --git a/lib/lp/registry/browser/person.py b/lib/lp/registry/browser/person.py
> index 8f044fd..139b687 100644
> --- a/lib/lp/registry/browser/person.py
> +++ b/lib/lp/registry/browser/person.py
> @@ -889,6 +894,12 @@ class PersonOverviewMenu(
> return Link(target, text, icon="edit", summary=text)
>
> @enabled_with_permission("launchpad.Edit")
> + def editmatrixaccounts(self):
> + target = "+editmatrixaccounts"
> + text = "Update Matrix accounts"
Done :)
> + return Link(target, text, icon="edit", summary=text)
> +
> + @enabled_with_permission("launchpad.Edit")
> def editjabberids(self):
> target = "+editjabberids"
> text = "Update Jabber IDs"
> @@ -2417,6 +2425,84 @@ class PersonEditIRCNicknamesView(LaunchpadFormView):
> self.request.response.addErrorNotification(
> "Neither Nickname nor Network can be empty."
> )
> + return
> +
> + # If we there were no errors, return user to profile page
> + self.next_url = canonical_url(self.context)
> +
> +
> +class PersonEditMatrixAccountsView(LaunchpadFormView):
> + # TODO: have a look into generalising this view and the relevant template
> + # (`person-editmatrixaccounts.pt`) for any social platform
> +
> + schema = Interface
> + platform = MatrixPlatform
> +
> + @property
> + def page_title(self):
> + return smartquote(
> + f"{self.context.displayname}'s {self.platform.title} accounts"
> + )
> +
> + label = page_title
> + next_url = None
> +
> + @property
> + def cancel_url(self):
> + return canonical_url(self.context)
> +
> + @property
> + def existing_accounts(self):
> + return self.context.getSocialAccounts(
> + platform=self.platform.platform_type
> + )
> +
> + @action(_("Save Changes"), name="save")
> + def save(self, action, data):
> + """Process the social accounts form."""
> + form = self.request.form
> +
> + # Update or remove existing accounts
> + for social_account in self.existing_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 self.platform.identity_fields
> + }
> + if not all(updated_identity.values()):
> + self.request.response.addErrorNotification(
> + "Fields cannot be left empty."
> + )
> + return
> +
> + social_account.identity = updated_identity
> +
> + # Add new account
> + new_account_identity = {
> + field_name: form.get(f"new_{field_name}")
> + for field_name in self.platform.identity_fields
> + }
> +
> + if all(new_account_identity.values()):
> + getUtility(ISocialAccountSet).new(
> + person=self.context,
> + platform=self.platform.platform_type,
> + identity=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 are required to add a new account."
> + )
> + return
> +
> + # If we there were no errors, return user to profile page
> + self.next_url = canonical_url(self.context)
Hmmmm, sure, I think that's better
>
>
> class PersonEditJabberIDsView(LaunchpadFormView):
--
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.
References