Skip to content

Commit 1e357ce

Browse files
feat: 962 - link to add a discussion topic on the wiki (#963)
Impacted files: * `user.dart`: added method `getUserWikiDiscussionPage` * `user_management_test_prod.dart`: tested new method `getUserWikiDiscussionPage`
1 parent bd3202b commit 1e357ce

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/src/model/user.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,24 @@ class User extends JsonObject {
2828
@override
2929
Map<String, dynamic> toJson() => _$UserToJson(this);
3030

31+
static String getUserWikiTag(final String userId) =>
32+
'${userId.substring(0, 1).toUpperCase()}${userId.substring(1)}';
33+
3134
static String getUserWikiPage(final String userId) => Uri(
3235
scheme: 'https',
3336
host: 'wiki.openfoodfacts.org',
34-
path: 'User:'
35-
'${userId.substring(0, 1).toUpperCase()}${userId.substring(1)}',
37+
path: 'User:${getUserWikiTag(userId)}',
38+
).toString();
39+
40+
/// Link to add a discussion topic on the OpenFoodFacts wiki page of a user.
41+
static String getUserWikiDiscussionPage(final String userId) => Uri(
42+
scheme: 'https',
43+
host: 'wiki.openfoodfacts.org',
44+
path: 'index.php',
45+
queryParameters: {
46+
'title': 'User_talk:${getUserWikiTag(userId)}',
47+
'action': 'edit',
48+
'section': 'new',
49+
},
3650
).toString();
3751
}

test/user_management_test_prod.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ void main() {
192192
User.getUserWikiPage('teolemon'),
193193
'https://wiki.openfoodfacts.org/User:Teolemon',
194194
);
195+
expect(
196+
User.getUserWikiDiscussionPage('tacinte'),
197+
'https://wiki.openfoodfacts.org/index.php?title=User_talk%3ATacinte&action=edit&section=new',
198+
);
195199
});
196200
});
197201
}

0 commit comments

Comments
 (0)