Skip to content

Commit eff0966

Browse files
committed
fix: honor disabled status when creating dashboard users
1 parent e934516 commit eff0966

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

‎shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/DashboardUserDO.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public static DashboardUserDO buildDashboardUserDO(final DashboardUserDTO dashbo
250250
.build();
251251
if (StringUtils.isEmpty(item.getId())) {
252252
dashboardUserDO.setId(UUIDUtils.getInstance().generateShortUuid());
253-
dashboardUserDO.setEnabled(true);
253+
dashboardUserDO.setEnabled(!Boolean.FALSE.equals(item.getEnabled()));
254254
dashboardUserDO.setDateCreated(currentTime);
255255
} else {
256256
dashboardUserDO.setId(item.getId());
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shenyu.admin.model.entity;
19+
20+
import org.apache.shenyu.admin.model.dto.DashboardUserDTO;
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
import static org.junit.jupiter.api.Assertions.assertNull;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
29+
/**
30+
* Tests dashboard user status mapping for creation and updates.
31+
*/
32+
final class DashboardUserDOTest {
33+
34+
@Test
35+
void preservesDisabledStatusOnCreation() {
36+
DashboardUserDTO dto = new DashboardUserDTO();
37+
dto.setEnabled(false);
38+
DashboardUserDO entity = DashboardUserDO.buildDashboardUserDO(dto);
39+
assertFalse(entity.getEnabled());
40+
assertNotNull(entity.getId());
41+
assertNotNull(entity.getDateCreated());
42+
}
43+
44+
@Test
45+
void preservesEnabledStatusOnCreation() {
46+
DashboardUserDTO dto = new DashboardUserDTO();
47+
dto.setEnabled(true);
48+
assertTrue(DashboardUserDO.buildDashboardUserDO(dto).getEnabled());
49+
}
50+
51+
@Test
52+
void defaultsNewUsersToEnabledWhenStatusIsOmitted() {
53+
assertTrue(DashboardUserDO.buildDashboardUserDO(new DashboardUserDTO()).getEnabled());
54+
}
55+
56+
@Test
57+
void preservesDisabledStatusOnUpdate() {
58+
DashboardUserDTO dto = new DashboardUserDTO();
59+
dto.setId("existing-user");
60+
dto.setEnabled(false);
61+
DashboardUserDO entity = DashboardUserDO.buildDashboardUserDO(dto);
62+
assertEquals("existing-user", entity.getId());
63+
assertFalse(entity.getEnabled());
64+
assertNull(entity.getDateCreated());
65+
}
66+
67+
@Test
68+
void preservesOmittedStatusOnPartialUpdate() {
69+
DashboardUserDTO dto = new DashboardUserDTO();
70+
dto.setId("existing-user");
71+
assertNull(DashboardUserDO.buildDashboardUserDO(dto).getEnabled());
72+
}
73+
}

0 commit comments

Comments
 (0)