Skip to content

Commit

Permalink
feat: 962 - link to add a discussion topic on the wiki (#963)
Browse files Browse the repository at this point in the history
Impacted files:
* `user.dart`: added method `getUserWikiDiscussionPage`
* `user_management_test_prod.dart`: tested new method `getUserWikiDiscussionPage`
  • Loading branch information
monsieurtanuki authored Aug 13, 2024
1 parent bd3202b commit 1e357ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/src/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,24 @@ class User extends JsonObject {
@override
Map<String, dynamic> toJson() => _$UserToJson(this);

static String getUserWikiTag(final String userId) =>
'${userId.substring(0, 1).toUpperCase()}${userId.substring(1)}';

static String getUserWikiPage(final String userId) => Uri(
scheme: 'https',
host: 'wiki.openfoodfacts.org',
path: 'User:'
'${userId.substring(0, 1).toUpperCase()}${userId.substring(1)}',
path: 'User:${getUserWikiTag(userId)}',
).toString();

/// Link to add a discussion topic on the OpenFoodFacts wiki page of a user.
static String getUserWikiDiscussionPage(final String userId) => Uri(
scheme: 'https',
host: 'wiki.openfoodfacts.org',
path: 'index.php',
queryParameters: {
'title': 'User_talk:${getUserWikiTag(userId)}',
'action': 'edit',
'section': 'new',
},
).toString();
}
4 changes: 4 additions & 0 deletions test/user_management_test_prod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ void main() {
User.getUserWikiPage('teolemon'),
'https://wiki.openfoodfacts.org/User:Teolemon',
);
expect(
User.getUserWikiDiscussionPage('tacinte'),
'https://wiki.openfoodfacts.org/index.php?title=User_talk%3ATacinte&action=edit&section=new',
);
});
});
}
Expand Down

0 comments on commit 1e357ce

Please sign in to comment.