33import lombok .RequiredArgsConstructor ;
44import org .apache .commons .lang3 .StringUtils ;
55import org .lowcoder .api .authentication .dto .OrganizationDomainCheckResult ;
6+ import org .lowcoder .api .authentication .service .AuthenticationApiService ;
67import org .lowcoder .api .framework .view .ResponseView ;
78import org .lowcoder .api .home .SessionUserService ;
89import org .lowcoder .api .home .UserHomeApiService ;
910import org .lowcoder .api .usermanagement .view .UpdateUserRequest ;
1011import org .lowcoder .api .usermanagement .view .UserProfileView ;
12+ import org .lowcoder .domain .organization .model .MemberRole ;
13+ import org .lowcoder .domain .organization .service .OrgMemberService ;
1114import org .lowcoder .domain .user .constant .UserStatusType ;
1215import org .lowcoder .domain .user .model .User ;
1316import org .lowcoder .domain .user .model .UserDetail ;
1417import org .lowcoder .domain .user .service .UserService ;
1518import org .lowcoder .domain .user .service .UserStatusService ;
1619import org .lowcoder .sdk .config .CommonConfig ;
20+ import org .lowcoder .sdk .constants .AuthSourceConstants ;
1721import org .lowcoder .sdk .exception .BizError ;
1822import org .springframework .http .HttpStatus ;
1923import org .springframework .http .codec .multipart .Part ;
@@ -35,6 +39,19 @@ public class UserController implements UserEndpoints
3539 private final UserStatusService userStatusService ;
3640 private final UserApiService userApiService ;
3741 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+ }
3855
3956 @ Override
4057 public Mono <ResponseView <?>> getUserProfile (ServerWebExchange exchange ) {
@@ -67,19 +84,27 @@ public Mono<ResponseView<Boolean>> markStatus(@RequestBody MarkUserStatusRequest
6784 @ Override
6885 public Mono <ResponseView <UserProfileView >> update (@ RequestBody UpdateUserRequest updateUserRequest , ServerWebExchange exchange ) {
6986 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 );
83108 }
84109
85110 @ Override
@@ -89,13 +114,28 @@ public Mono<ResponseView<Boolean>> uploadProfilePhoto(@RequestPart("file") Mono<
89114 .map (ResponseView ::success );
90115 }
91116
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+
92125 @ Override
93126 public Mono <ResponseView <Void >> deleteProfilePhoto () {
94127 return sessionUserService .getVisitor ()
95128 .flatMap (visitor -> userService .deleteProfilePhoto (visitor )
96129 .map (ResponseView ::success ));
97130 }
98131
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+
99139 @ Override
100140 public Mono <Void > getProfilePhoto (ServerWebExchange exchange ) {
101141 return sessionUserService .getVisitorId ()
0 commit comments