Skip to content
代码片段 群组 项目
提交 5787bc73 编辑于 作者: Raymond Liao's avatar Raymond Liao :nerd:
浏览文件

feat: #500 Should display edit button when user has edit permission

上级 9d464ec7
No related branches found
No related tags found
无相关合并请求
......@@ -250,6 +250,24 @@ class _CommunityPostDetailsPageState extends State<CommunityPostDetailsPage> {
),
),
),
if (_model.communityPostInfo != null && _model.communityPostInfo!.hasEditPermission)
InkWell(
child: SizedBox(
width: 44,
height: 44,
child: Center(
child: SvgPicture.asset("assets/images/operate.svg", semanticsLabel: "operate", colorFilter: const ColorFilter.mode(Color(0xFF66696D), BlendMode.srcIn), width: 18, height: 18),
),
),
onTap: () {
renderBottomSheet(Container(
width: MediaQuery.of(context).size.width,
padding: const EdgeInsets.symmetric(vertical: 12),
child: Center(
child: Text(JiHuLocalizations.dictionary().edit_issue),
),
));
})
]),
),
);
......
......@@ -18,40 +18,41 @@ class CommunityPost {
Assignee author;
List<String>? labelNames;
List<Label> labels;
bool hasEditPermission;
CommunityPost._(this.id, this.iid, this.title, this.description, this.createdAt, this.confidential, this.state, this.webUrl, this.author, this.labelNames, this.labels);
CommunityPost._(this.id, this.iid, this.title, this.description, this.createdAt, this.confidential, this.state, this.webUrl, this.author, this.labelNames, this.labels, this.hasEditPermission);
factory CommunityPost.fromGraphQLJson(Map<String, dynamic> json) {
return CommunityPost._(
Id.fromGid(json['id'] ?? '/0'),
int.parse(json['iid']),
json['title'] ?? '',
'',
Time.init(json['createdAt'] ?? ''),
json['confidential'] ?? false,
json['state'] ?? '',
json['webUrl'] ?? '',
Assignee.fromGraphQLJson(json['author'] ?? {}),
[],
((json['labels']?['nodes'] ?? []) as List).map((e) => Label.fromGraphQLJson(e)).toList(),
);
Id.fromGid(json['id'] ?? '/0'),
int.parse(json['iid']),
json['title'] ?? '',
'',
Time.init(json['createdAt'] ?? ''),
json['confidential'] ?? false,
json['state'] ?? '',
json['webUrl'] ?? '',
Assignee.fromGraphQLJson(json['author'] ?? {}),
[],
((json['labels']?['nodes'] ?? []) as List).map((e) => Label.fromGraphQLJson(e)).toList(),
json['userPermissions']?['updateIssue'] ?? false);
}
factory CommunityPost.fromCommunityGraphQLJson(Map<String, dynamic> json, String pathWithNameSpace) {
String description = DescriptionContent.init(json['description'] ?? '', pathWithNameSpace).value;
return CommunityPost._(
Id.fromGid(json['id'] ?? '/0'),
int.parse(json['iid'] ?? '0'),
json['title'] ?? '',
description,
Time.init(json['createdAt'] ?? ''),
json['confidential'] ?? false,
json['state'] ?? '',
json['webUrl'] ?? '',
Assignee.fromGraphQLJson(json['author'] ?? {}),
[],
((json['labels']?['nodes'] ?? []) as List).map((e) => Label.fromGraphQLJson(e)).toList(),
);
Id.fromGid(json['id'] ?? '/0'),
int.parse(json['iid'] ?? '0'),
json['title'] ?? '',
description,
Time.init(json['createdAt'] ?? ''),
json['confidential'] ?? false,
json['state'] ?? '',
json['webUrl'] ?? '',
Assignee.fromGraphQLJson(json['author'] ?? {}),
[],
((json['labels']?['nodes'] ?? []) as List).map((e) => Label.fromGraphQLJson(e)).toList(),
json['userPermissions']?['updateIssue'] ?? false);
}
List<Label> get listLabels {
......
......@@ -390,6 +390,54 @@ void main() {
expect(SvgFinder("assets/images/operate.svg"), findsNothing);
});
group('Should check edit issue permission of user', () {
testWidgets('Should display edit button when user has edit permission', (WidgetTester tester) async {
await setUpMobileBinding(tester);
when(client.postWithConnection('/api/graphql', getCommunityDetailsGraphQLRequestBody('ultimate-plan/jihu-gitlab-app/faq', 6), any))
.thenAnswer((_) => Future(() => Response.of<dynamic>(communityDetailsGraphQLResponse)));
await tester.pumpWidget(MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => ConnectionProvider()),
],
child: MaterialApp(
home: Scaffold(
body: CommunityPostDetailsPage(arguments: params),
),
)));
await tester.pumpAndSettle();
expect(find.widgetWithText(CommonAppBar, 'WFH'), findsOneWidget);
expect(find.text(JiHuLocalizations.dictionary().commentPlaceholder), findsOneWidget);
expect(SvgFinder("assets/images/comment.svg"), findsOneWidget);
expect(SvgFinder("assets/images/operate.svg"), findsOneWidget);
});
testWidgets('Should not display edit button when user has no edit permission', (WidgetTester tester) async {
await setUpMobileBinding(tester);
when(client.postWithConnection('/api/graphql', getCommunityDetailsGraphQLRequestBody('ultimate-plan/jihu-gitlab-app/faq', 6), any))
.thenAnswer((_) => Future(() => Response.of<dynamic>(communityDetailsWithNoEditPermissionGraphQLResponse)));
await tester.pumpWidget(MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => ConnectionProvider()),
],
child: MaterialApp(
home: Scaffold(
body: CommunityPostDetailsPage(arguments: params),
),
)));
await tester.pumpAndSettle();
expect(find.widgetWithText(CommonAppBar, 'WFH'), findsOneWidget);
expect(find.text(JiHuLocalizations.dictionary().commentPlaceholder), findsOneWidget);
expect(SvgFinder("assets/images/comment.svg"), findsOneWidget);
expect(SvgFinder("assets/images/operate.svg"), findsNothing);
});
});
tearDown(() {
reset(client);
ConnectionProvider().fullReset();
......
......@@ -87,6 +87,38 @@ Map<String, dynamic> communityDetailsGraphQLResponse = {
}
};
Map<String, dynamic> communityDetailsWithNoEditPermissionGraphQLResponse = {
"data": {
"project": {
"id": "gid://gitlab/Project/89335",
"name": "开源社区",
"nameWithNamespace": "旗舰版演示 / 极狐 GitLab App 产品线 / 开源社区",
"path": "faq",
"fullPath": "ultimate-plan/jihu-gitlab-app/faq",
"issue": {
"id": "gid://gitlab/Issue/326489",
"iid": "238",
"projectId": 89335,
"title": "Why remote?",
"description": "Community detail for test",
"webUrl": "https://jihulab.com/ultimate-plan/jihu-gitlab-app/faq/-/issues/238",
"confidential": false,
"state": "opened",
"createdAt": "2022-11-25T14:19:30.461+08:00",
"author": {"id": "gid://gitlab/User/23836", "avatarUrl": "/uploads/-/system/user/avatar/23836/avatar.png", "name": "yajie xue", "username": "jojo0"},
"assignees": {"nodes": []},
"userPermissions": {"updateIssue": false},
"labels": {
"nodes": [
{"id": "gid://gitlab/ProjectLabel/72406", "title": "lang::en", "description": "英文", "color": "#9400d3", "textColor": "#FFFFFF"},
{"id": "gid://gitlab/ProjectLabel/72059", "title": "type::WFH", "description": "远程办公", "color": "#6699cc", "textColor": "#FFFFFF"}
]
}
}
}
}
};
Map<String, dynamic> geekCommunityDetailsGraphQLResponse = {
"data": {
"project": {
......@@ -107,6 +139,7 @@ Map<String, dynamic> geekCommunityDetailsGraphQLResponse = {
"createdAt": "2022-11-25T14:19:30.461+08:00",
"author": {"id": "gid://gitlab/User/23836", "avatarUrl": "/uploads/-/system/user/avatar/23836/avatar.png", "name": "yajie xue", "username": "jojo0"},
"assignees": {"nodes": []},
"userPermissions": {"updateIssue": true},
"labels": {
"nodes": [
{"id": "gid://gitlab/ProjectLabel/74785", "title": "for::geek", "description": "", "color": "#6699cc", "textColor": "#FFFFFF"},
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册