3
3
import lombok .RequiredArgsConstructor ;
4
4
import org .apache .commons .lang3 .StringUtils ;
5
5
import org .lowcoder .api .authentication .dto .OrganizationDomainCheckResult ;
6
+ import org .lowcoder .api .authentication .service .AuthenticationApiService ;
6
7
import org .lowcoder .api .framework .view .ResponseView ;
7
8
import org .lowcoder .api .home .SessionUserService ;
8
9
import org .lowcoder .api .home .UserHomeApiService ;
9
10
import org .lowcoder .api .usermanagement .view .UpdateUserRequest ;
10
11
import org .lowcoder .api .usermanagement .view .UserProfileView ;
12
+ import org .lowcoder .domain .organization .model .MemberRole ;
13
+ import org .lowcoder .domain .organization .service .OrgMemberService ;
11
14
import org .lowcoder .domain .user .constant .UserStatusType ;
12
15
import org .lowcoder .domain .user .model .User ;
13
16
import org .lowcoder .domain .user .model .UserDetail ;
14
17
import org .lowcoder .domain .user .service .UserService ;
15
18
import org .lowcoder .domain .user .service .UserStatusService ;
16
19
import org .lowcoder .sdk .config .CommonConfig ;
20
+ import org .lowcoder .sdk .constants .AuthSourceConstants ;
17
21
import org .lowcoder .sdk .exception .BizError ;
18
22
import org .springframework .http .HttpStatus ;
19
23
import org .springframework .http .codec .multipart .Part ;
@@ -35,6 +39,19 @@ public class UserController implements UserEndpoints
35
39
private final UserStatusService userStatusService ;
36
40
private final UserApiService userApiService ;
37
41
private final CommonConfig commonConfig ;
42
+ private final AuthenticationApiService authenticationApiService ;
43
+ private final OrgMemberService orgMemberService ;
44
+
45
+ @ Override
46
+ public Mono <ResponseView <?>> createUserAndAddToOrg (@ PathVariable String orgId , CreateUserRequest request ) {
47
+ return orgApiService .checkVisitorAdminRole (orgId ).flatMap (__ ->
48
+ authenticationApiService .authenticateByForm (request .email (), request .password (),
49
+ AuthSourceConstants .EMAIL , true , null , orgId ))
50
+ .flatMap (authUser -> userService .createNewUserByAuthUser (authUser , false ))
51
+ .delayUntil (user -> orgMemberService .tryAddOrgMember (orgId , user .getId (), MemberRole .MEMBER ))
52
+ .delayUntil (user -> orgApiService .switchCurrentOrganizationTo (user .getId (), orgId ))
53
+ .map (ResponseView ::success );
54
+ }
38
55
39
56
@ Override
40
57
public Mono <ResponseView <?>> getUserProfile (ServerWebExchange exchange ) {
@@ -67,19 +84,27 @@ public Mono<ResponseView<Boolean>> markStatus(@RequestBody MarkUserStatusRequest
67
84
@ Override
68
85
public Mono <ResponseView <UserProfileView >> update (@ RequestBody UpdateUserRequest updateUserRequest , ServerWebExchange exchange ) {
69
86
return sessionUserService .getVisitorId ()
70
- .flatMap (uid -> {
71
- User updateUser = new User ();
72
- if (StringUtils .isNotBlank (updateUserRequest .getName ())) {
73
- updateUser .setName (updateUserRequest .getName ());
74
- updateUser .setHasSetNickname (true );
75
- }
76
- if (StringUtils .isNotBlank (updateUserRequest .getUiLanguage ())) {
77
- updateUser .setUiLanguage (updateUserRequest .getUiLanguage ());
78
- }
79
- return userService .update (uid , updateUser );
80
- })
81
- .flatMap (user -> userHomeApiService .buildUserProfileView (user , exchange ))
82
- .map (ResponseView ::success );
87
+ .flatMap (uid -> updateUser (uid , updateUserRequest , exchange ));
88
+ }
89
+
90
+ @ Override
91
+ public Mono <ResponseView <UserProfileView >> update (@ PathVariable String orgId , @ PathVariable String userId , @ RequestBody UpdateUserRequest updateUserRequest , ServerWebExchange exchange ) {
92
+ return orgApiService .checkVisitorAdminRole (orgId )
93
+ .flatMap (__ -> updateUser (userId , updateUserRequest , exchange ));
94
+ }
95
+
96
+ public Mono <ResponseView <UserProfileView >> updateUser (String userId , @ RequestBody UpdateUserRequest updateUserRequest , ServerWebExchange exchange ) {
97
+ User updateUser = new User ();
98
+ if (StringUtils .isNotBlank (updateUserRequest .getName ())) {
99
+ updateUser .setName (updateUserRequest .getName ());
100
+ updateUser .setHasSetNickname (true );
101
+ }
102
+ if (StringUtils .isNotBlank (updateUserRequest .getUiLanguage ())) {
103
+ updateUser .setUiLanguage (updateUserRequest .getUiLanguage ());
104
+ }
105
+ return userService .update (userId , updateUser )
106
+ .flatMap (user -> userHomeApiService .buildUserProfileView (user , exchange ))
107
+ .map (ResponseView ::success );
83
108
}
84
109
85
110
@ Override
@@ -89,13 +114,28 @@ public Mono<ResponseView<Boolean>> uploadProfilePhoto(@RequestPart("file") Mono<
89
114
.map (ResponseView ::success );
90
115
}
91
116
117
+ @ Override
118
+ public Mono <ResponseView <Boolean >> uploadProfilePhotoById (@ PathVariable String orgId , @ PathVariable String userId , @ RequestPart ("file" ) Mono <Part > fileMono ) {
119
+ return orgApiService .checkVisitorAdminRole (orgId ).flatMap (__ -> userService .findById (userId ))
120
+ .zipWith (fileMono )
121
+ .flatMap (tuple -> userService .saveProfilePhoto (tuple .getT2 (), tuple .getT1 ()))
122
+ .map (ResponseView ::success );
123
+ }
124
+
92
125
@ Override
93
126
public Mono <ResponseView <Void >> deleteProfilePhoto () {
94
127
return sessionUserService .getVisitor ()
95
128
.flatMap (visitor -> userService .deleteProfilePhoto (visitor )
96
129
.map (ResponseView ::success ));
97
130
}
98
131
132
+ @ Override
133
+ public Mono <ResponseView <Void >> deleteProfilePhotoById (@ PathVariable String orgId , @ PathVariable String userId ) {
134
+ return orgApiService .checkVisitorAdminRole (orgId ).flatMap (__ -> userService .findById (userId ))
135
+ .flatMap (user -> userService .deleteProfilePhoto (user )
136
+ .map (ResponseView ::success ));
137
+ }
138
+
99
139
@ Override
100
140
public Mono <Void > getProfilePhoto (ServerWebExchange exchange ) {
101
141
return sessionUserService .getVisitorId ()
0 commit comments