Merge ~ines-almeida/launchpad:social-accounts-generalise-UI into launchpad:master

Proposed by Ines Almeida
Status: Merged
Approved by: Ines Almeida
Approved revision: 49a4ce53a4fe691eaa8e27b98ad60b3df5116c51
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ines-almeida/launchpad:social-accounts-generalise-UI
Merge into: launchpad:master
Diff against target: 204 lines (+41/-37)
5 files modified
lib/lp/registry/browser/configure.zcml (+1/-1)
lib/lp/registry/browser/person.py (+19/-7)
lib/lp/registry/interfaces/socialaccount.py (+6/-0)
lib/lp/registry/model/person.py (+2/-3)
lib/lp/registry/templates/person-editsocialaccounts.pt (+13/-26)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+459182@code.launchpad.net

Commit message

ui: generalize edit matrix accounts page

This will make it much more straight-forward to add new social platforms as we won't need different templates for different platforms

Description of the change

UI tests re-run and don't seem to need any change, as the template remains the same.

Also adding a quick `SOCIAL_PLATFORM_TYPES_MAP` to the `__all__` due to a warning message when running tests.

To post a comment you must log in.
49a4ce5... by Ines Almeida

Update how to get Platform class from social_account.platform

Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Will there be any visual changes? If so, could you provide before/after screenshots?

Revision history for this message
Ines Almeida (ines-almeida) wrote :

No visual changes. The contents of the page should be exactly the same.

The difference is that the template for adding a social account is generic instead of being tied to Matrix, which should make it simpler to add new social account platforms (or migrate IRC and Jabber into the social accounts table).

Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/browser/configure.zcml b/lib/lp/registry/browser/configure.zcml
2index 35fe1d3..970fd02 100644
3--- a/lib/lp/registry/browser/configure.zcml
4+++ b/lib/lp/registry/browser/configure.zcml
5@@ -1223,7 +1223,7 @@
6 for="lp.registry.interfaces.person.IPerson"
7 class="lp.registry.browser.person.PersonEditMatrixAccountsView"
8 permission="launchpad.Edit"
9- template="../templates/person-editmatrixaccounts.pt"
10+ template="../templates/person-editsocialaccounts.pt"
11 />
12 <browser:page
13 name="+editjabberids"
14diff --git a/lib/lp/registry/browser/person.py b/lib/lp/registry/browser/person.py
15index de0003d..ae8b415 100644
16--- a/lib/lp/registry/browser/person.py
17+++ b/lib/lp/registry/browser/person.py
18@@ -2458,12 +2458,9 @@ class PersonEditIRCNicknamesView(LaunchpadFormView):
19 self.next_url = canonical_url(self.context)
20
21
22-class PersonEditMatrixAccountsView(LaunchpadFormView):
23- # TODO: have a look into generalising this view and the relevant template
24- # (`person-editmatrixaccounts.pt`) for any social platform
25-
26+class PersonEditSocialAccountsView(LaunchpadFormView):
27 schema = Interface
28- platform = MatrixPlatform
29+ platform = None
30
31 @property
32 def page_title(self):
33@@ -2473,6 +2470,7 @@ class PersonEditMatrixAccountsView(LaunchpadFormView):
34
35 label = page_title
36 next_url = None
37+ new_identity = dict()
38
39 @property
40 def cancel_url(self):
41@@ -2484,6 +2482,17 @@ class PersonEditMatrixAccountsView(LaunchpadFormView):
42 platform=self.platform.platform_type
43 )
44
45+ @property
46+ def identity_headers(self):
47+ return [item.capitalize() for item in self.platform.identity_fields]
48+
49+ @property
50+ def identity_examples(self):
51+ return [
52+ self.platform.identity_fields_example[field]
53+ for field in self.platform.identity_fields
54+ ]
55+
56 @action(_("Save Changes"), name="save")
57 def save(self, action, data):
58 """Process the social accounts form."""
59@@ -2517,8 +2526,7 @@ class PersonEditMatrixAccountsView(LaunchpadFormView):
60 try:
61 self.platform.validate_identity(new_account_identity)
62 except SocialAccountIdentityError as e:
63- for field_key, field_value in new_account_identity.items():
64- self.__setattr__(f"new_{field_key}", field_value)
65+ self.__setattr__("new_identity", new_account_identity)
66 self.request.response.addErrorNotification(e)
67 return
68
69@@ -2535,6 +2543,10 @@ class PersonEditMatrixAccountsView(LaunchpadFormView):
70 )
71
72
73+class PersonEditMatrixAccountsView(PersonEditSocialAccountsView):
74+ platform = MatrixPlatform
75+
76+
77 class PersonEditJabberIDsView(LaunchpadFormView):
78 schema = IJabberID
79 field_names = ["jabberid"]
80diff --git a/lib/lp/registry/interfaces/socialaccount.py b/lib/lp/registry/interfaces/socialaccount.py
81index 94e8d78..2c351f2 100644
82--- a/lib/lp/registry/interfaces/socialaccount.py
83+++ b/lib/lp/registry/interfaces/socialaccount.py
84@@ -10,6 +10,7 @@ __all__ = [
85 "SocialPlatformType",
86 "SocialAccountIdentityError",
87 "validate_social_account_identity",
88+ "SOCIAL_PLATFORM_TYPES_MAP",
89 ]
90
91 import http.client
92@@ -105,6 +106,7 @@ class ISocialAccountSet(Interface):
93 class SocialPlatform:
94 title = ""
95 identity_fields = []
96+ identity_fields_example = {}
97 platform_type = None
98 icon = ""
99 display_format = ""
100@@ -119,6 +121,10 @@ class SocialPlatform:
101 class MatrixPlatform(SocialPlatform):
102 title = "Matrix"
103 identity_fields = ["username", "homeserver"]
104+ identity_fields_example = {
105+ "username": "mark",
106+ "homeserver": "ubuntu.com",
107+ }
108 platform_type = SocialPlatformType.MATRIX
109 icon = "social-matrix"
110 display_format = "<strong>@{username}:{homeserver}</strong>"
111diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
112index 1a1a122..201b3ae 100644
113--- a/lib/lp/registry/model/person.py
114+++ b/lib/lp/registry/model/person.py
115@@ -165,9 +165,9 @@ from lp.registry.interfaces.product import IProduct, IProductSet
116 from lp.registry.interfaces.projectgroup import IProjectGroup
117 from lp.registry.interfaces.role import IPersonRoles
118 from lp.registry.interfaces.socialaccount import (
119+ SOCIAL_PLATFORM_TYPES_MAP,
120 ISocialAccount,
121 ISocialAccountSet,
122- MatrixPlatform,
123 SocialPlatformType,
124 validate_social_account_identity,
125 )
126@@ -5371,8 +5371,7 @@ class SocialAccount(StormBase, HasOwnerMixin):
127 self.identity = identity
128
129 def getSocialPlatform(self):
130- if self.platform == SocialPlatformType.MATRIX:
131- return MatrixPlatform
132+ return SOCIAL_PLATFORM_TYPES_MAP.get(self.platform)
133
134 def destroySelf(self):
135 IStore(self).remove(self)
136diff --git a/lib/lp/registry/templates/person-editmatrixaccounts.pt b/lib/lp/registry/templates/person-editsocialaccounts.pt
137similarity index 70%
138rename from lib/lp/registry/templates/person-editmatrixaccounts.pt
139rename to lib/lp/registry/templates/person-editsocialaccounts.pt
140index 66ec724..486ab2d 100644
141--- a/lib/lp/registry/templates/person-editmatrixaccounts.pt
142+++ b/lib/lp/registry/templates/person-editsocialaccounts.pt
143@@ -18,24 +18,18 @@
144 <table>
145
146 <tr>
147- <td><label>Homeserver</label></td>
148- <td><label>Username</label></td>
149+ <td tal:repeat="header view/identity_headers">
150+ <label tal:content="header"></label>
151+ </td>
152 </tr>
153
154 <tr tal:repeat="social_account view/existing_accounts">
155- <td>
156- <input type="text"
157- class="field_homeserver"
158- tal:attributes="name string:homeserver_${social_account/id};
159- value social_account/identity/homeserver" />
160- </td>
161- <td>
162+ <td tal:repeat="field view/platform/identity_fields">
163 <input type="text"
164- class="field_username"
165- tal:attributes="name string:username_${social_account/id};
166- value social_account/identity/username" />
167+ tal:attributes="name string:${field}_${social_account/id};
168+ value python:social_account.identity[field];
169+ class string:field_${field}" />
170 </td>
171-
172 <td>
173 <label>
174 <input type="checkbox"
175@@ -47,23 +41,16 @@
176 </tr>
177
178 <tr>
179- <td>
180- <input name="new_homeserver"
181- type="text"
182- placeholder="Enter new homeserver"
183- tal:attributes="value view/new_homeserver|nothing" />
184- </td>
185- <td>
186- <input name="new_username"
187- type="text"
188- placeholder="Enter new username"
189- tal:attributes="value view/new_username|nothing" />
190+ <td tal:repeat="field view/platform/identity_fields">
191+ <input type="text"
192+ tal:attributes="value python:view.new_identity.get(field);
193+ name string:new_${field};
194+ placeholder string:Enter new ${field}" />
195 </td>
196 </tr>
197
198 <tr>
199- <td class="formHelp">Example: ubuntu.com</td>
200- <td class="formHelp">Example: mark</td>
201+ <td tal:repeat="example view/identity_examples" tal:content="string:Example: ${example}"></td>
202 </tr>
203 </table>
204 </div>

Subscribers

People subscribed via source and target branches

to status/vote changes: