
user: fix the problem that user can create an account with existing group name
@dfe7ceb83f1e6e39ed102076b35db6708412e403
--- app/controllers/UserApp.java
+++ app/controllers/UserApp.java
... | ... | @@ -656,15 +656,19 @@ |
656 | 656 |
} |
657 | 657 |
|
658 | 658 |
/** |
659 |
- * 로그인ID 존재 여부, 로그인ID 예약어 여부 |
|
659 |
+ * check the given {@code loginId} is being used by someone else's logindId or group name, |
|
660 |
+ * and whether {@code loginId} is a reserved word or not. |
|
660 | 661 |
* |
661 |
- * @param loginId 로그인ID |
|
662 |
+ * @param name |
|
662 | 663 |
* @return |
664 |
+ * @see User#isLoginIdExist(String) |
|
665 |
+ * @see Organization#isNameExist(String) |
|
666 |
+ * @see ReservedWordsValidator#isReserved(String) |
|
663 | 667 |
*/ |
664 |
- public static Result isUserExist(String loginId) { |
|
668 |
+ public static Result isUsed(String name) { |
|
665 | 669 |
ObjectNode result = Json.newObject(); |
666 |
- result.put("isExist", User.isLoginIdExist(loginId)); |
|
667 |
- result.put("isReserved", ReservedWordsValidator.isReserved(loginId)); |
|
670 |
+ result.put("isExist", User.isLoginIdExist(name) || Organization.isNameExist(name)); |
|
671 |
+ result.put("isReserved", ReservedWordsValidator.isReserved(name)); |
|
668 | 672 |
return ok(result); |
669 | 673 |
} |
670 | 674 |
|
... | ... | @@ -899,7 +903,8 @@ |
899 | 903 |
} |
900 | 904 |
|
901 | 905 |
// 중복된 loginId로 가입할 수 없다. |
902 |
- if (User.isLoginIdExist(newUserForm.field("loginId").value())) { |
|
906 |
+ if (User.isLoginIdExist(newUserForm.field("loginId").value()) |
|
907 |
+ || Organization.isNameExist(newUserForm.field("loginId").value())) { |
|
903 | 908 |
newUserForm.reject("loginId", "user.loginId.duplicate"); |
904 | 909 |
} |
905 | 910 |
|
--- app/views/user/signup.scala.html
+++ app/views/user/signup.scala.html
... | ... | @@ -63,7 +63,10 @@ |
63 | 63 |
<script type="text/javascript" src="@routes.Assets.at("javascripts/lib/validate.js")"></script> |
64 | 64 |
<script type="text/javascript"> |
65 | 65 |
$(document).ready(function() { |
66 |
- $yobi.loadModule("user.SignUp"); |
|
66 |
+ $yobi.loadModule("user.SignUp", { |
|
67 |
+ "sLogindIdCheckUrl" : "@routes.UserApp.isUsed("")", |
|
68 |
+ "sEmailCheckUrl" : "@routes.UserApp.isEmailExist("")" |
|
69 |
+ }); |
|
67 | 70 |
}); |
68 | 71 |
</script> |
69 | 72 |
} |
--- conf/routes
+++ conf/routes
... | ... | @@ -47,8 +47,8 @@ |
47 | 47 |
GET /user/editform controllers.UserApp.editUserInfoForm() |
48 | 48 |
POST /user/edit controllers.UserApp.editUserInfo() |
49 | 49 |
POST /user/resetPassword controllers.UserApp.resetUserPassword() |
50 |
-GET /user/isExist/:loginId controllers.UserApp.isUserExist(loginId) |
|
51 |
-GET /user/isEmailExist/:email controllers.UserApp.isEmailExist(email) |
|
50 |
+GET /user/isUsed controllers.UserApp.isUsed(name:String) |
|
51 |
+GET /user/isEmailExist controllers.UserApp.isEmailExist(email:String) |
|
52 | 52 |
GET /info/leave/:user/:project controllers.UserApp.leave(user, project) |
53 | 53 |
POST /user/email controllers.UserApp.addEmail() |
54 | 54 |
DELETE /user/email/delete/:emailId controllers.UserApp.deleteEmail(emailId:Long) |
--- conf/test-data.yml
+++ conf/test-data.yml
... | ... | @@ -457,3 +457,20 @@ |
457 | 457 |
id: 1 |
458 | 458 |
notificationType: NEW_ISSUE |
459 | 459 |
allowed: true |
460 |
+ |
|
461 |
+# Organization |
|
462 |
+organization: |
|
463 |
+ - !!models.Organization |
|
464 |
+ id: 1 |
|
465 |
+ name: labs |
|
466 |
+ created: 2014-04-10 15:00:00 |
|
467 |
+ |
|
468 |
+# OrganizationUser |
|
469 |
+organizationUsers: |
|
470 |
+ - !!models.OrganizationUser |
|
471 |
+ user: !!models.User |
|
472 |
+ id: 2 |
|
473 |
+ organization: !!models.Organization |
|
474 |
+ id: 1 |
|
475 |
+ role: !!models.Role |
|
476 |
+ id: 6 |
--- public/javascripts/service/yobi.user.SignUp.js
+++ public/javascripts/service/yobi.user.SignUp.js
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 |
(function(ns){ |
11 | 11 |
|
12 | 12 |
var oNS = $yobi.createNamespace(ns); |
13 |
- oNS.container[oNS.name] = function(){ |
|
13 |
+ oNS.container[oNS.name] = function(htOptions){ |
|
14 | 14 |
|
15 | 15 |
var htVar = {}; |
16 | 16 |
var htElement = {}; |
... | ... | @@ -18,9 +18,9 @@ |
18 | 18 |
/** |
19 | 19 |
* initialize |
20 | 20 |
*/ |
21 |
- function _init(){ |
|
21 |
+ function _init(htOptions){ |
|
22 | 22 |
_initElement(); |
23 |
- _initVar(); |
|
23 |
+ _initVar(htOptions); |
|
24 | 24 |
|
25 | 25 |
_initFormValidator(); |
26 | 26 |
_attachEvent(); |
... | ... | @@ -43,8 +43,10 @@ |
43 | 43 |
/** |
44 | 44 |
* initialize variables |
45 | 45 |
*/ |
46 |
- function _initVar(){ |
|
46 |
+ function _initVar(htOptions){ |
|
47 | 47 |
htVar.rxLoginId = /^[a-zA-Z0-9-]+([_.][a-zA-Z0-9-]+)*$/; |
48 |
+ htVar.sLogindIdCheckUrl = htOptions.sLogindIdCheckUrl; |
|
49 |
+ htVar.sEmailCheckUrl = htOptions.sEmailCheckUrl; |
|
48 | 50 |
} |
49 | 51 |
|
50 | 52 |
/** |
... | ... | @@ -72,7 +74,7 @@ |
72 | 74 |
} |
73 | 75 |
|
74 | 76 |
if(sLoginId != ""){ |
75 |
- doesExists($(this), "/user/isExist/"); |
|
77 |
+ doesExists($(this), htVar.sLogindIdCheckUrl); |
|
76 | 78 |
} |
77 | 79 |
} |
78 | 80 |
|
... | ... | @@ -84,7 +86,7 @@ |
84 | 86 |
var welInput = $(this); |
85 | 87 |
|
86 | 88 |
if(welInput.val() !== ""){ |
87 |
- doesExists(welInput, "/user/isEmailExist/"); |
|
89 |
+ doesExists(welInput, htVar.sEmailCheckUrl); |
|
88 | 90 |
} |
89 | 91 |
} |
90 | 92 |
|
... | ... | @@ -101,10 +103,6 @@ |
101 | 103 |
* @param {String} sURL |
102 | 104 |
*/ |
103 | 105 |
function doesExists(welInput, sURL){ |
104 |
- if(sURL.substr(-1) != "/"){ |
|
105 |
- sURL += "/"; |
|
106 |
- } |
|
107 |
- |
|
108 | 106 |
$.ajax({ |
109 | 107 |
"url": sURL + welInput.val() |
110 | 108 |
}).done(function(htData){ |
... | ... | @@ -207,6 +205,6 @@ |
207 | 205 |
} catch(e){} // to avoid bootstrap bug |
208 | 206 |
} |
209 | 207 |
|
210 |
- _init(); |
|
208 |
+ _init(htOptions || {}); |
|
211 | 209 |
}; |
212 | 210 |
})("yobi.user.SignUp"); |
--- test/controllers/UserAppTest.java
+++ test/controllers/UserAppTest.java
... | ... | @@ -36,7 +36,7 @@ |
36 | 36 |
|
37 | 37 |
//When |
38 | 38 |
Result result = callAction( |
39 |
- controllers.routes.ref.UserApp.isUserExist("nekure"), |
|
39 |
+ controllers.routes.ref.UserApp.isUsed("nekure"), |
|
40 | 40 |
fakeRequest().withFormUrlEncodedBody(data) |
41 | 41 |
); // fakeRequest doesn't need here, but remains for example |
42 | 42 |
|
... | ... | @@ -59,9 +59,28 @@ |
59 | 59 |
|
60 | 60 |
//When |
61 | 61 |
Result result = callAction( |
62 |
- controllers.routes.ref.UserApp.isUserExist("yobi"), |
|
62 |
+ controllers.routes.ref.UserApp.isUsed("yobi"), |
|
63 | 63 |
fakeRequest().withFormUrlEncodedBody(data) |
64 | 64 |
); // fakeRequest doesn't need here, but remains for example |
65 |
+ |
|
66 |
+ //Then |
|
67 |
+ assertThat(status(result)).isEqualTo(OK); |
|
68 |
+ assertThat(contentAsString(result)).contains("\"isExist\":true"); |
|
69 |
+ assertThat(contentType(result)).contains("json"); |
|
70 |
+ } |
|
71 |
+ }); |
|
72 |
+ } |
|
73 |
+ |
|
74 |
+ @Test |
|
75 |
+ public void findById_alreadyExistGroupName() { |
|
76 |
+ running(support.Helpers.makeTestApplication(), new Runnable() { |
|
77 |
+ @Override |
|
78 |
+ public void run() { |
|
79 |
+ //Given |
|
80 |
+ String loginId = "labs"; |
|
81 |
+ |
|
82 |
+ //When |
|
83 |
+ Result result = callAction(controllers.routes.ref.UserApp.isUsed(loginId)); |
|
65 | 84 |
|
66 | 85 |
//Then |
67 | 86 |
assertThat(status(result)).isEqualTo(OK); |
... | ... | @@ -124,6 +143,30 @@ |
124 | 143 |
} |
125 | 144 |
|
126 | 145 |
@Test |
146 |
+ public void newUser_AlreadyExistGroupName() { |
|
147 |
+ running(support.Helpers.makeTestApplication(), new Runnable() { |
|
148 |
+ @Override |
|
149 |
+ public void run() { |
|
150 |
+ //Given |
|
151 |
+ Map<String, String> data = new HashMap<>(); |
|
152 |
+ data.put("loginId", "labs"); |
|
153 |
+ data.put("password", "somefakepassword"); |
|
154 |
+ data.put("email", "labs@fake.com"); |
|
155 |
+ data.put("name", "labs"); |
|
156 |
+ |
|
157 |
+ //When |
|
158 |
+ Result result = callAction( |
|
159 |
+ controllers.routes.ref.UserApp.newUser(), |
|
160 |
+ fakeRequest().withFormUrlEncodedBody(data) |
|
161 |
+ ); |
|
162 |
+ |
|
163 |
+ //Then |
|
164 |
+ assertThat(status(result)).describedAs("result status should '400 bad request'").isEqualTo(BAD_REQUEST); |
|
165 |
+ } |
|
166 |
+ }); |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ @Test |
|
127 | 170 |
public void newUser_confirmSignUpMode() { |
128 | 171 |
Map<String, String> config = support.Helpers.makeTestConfig(); |
129 | 172 |
config.put("signup.require.confirm", "true"); |
... | ... | @@ -161,7 +204,7 @@ |
161 | 204 |
data.put("loginId", "messages.js"); |
162 | 205 |
|
163 | 206 |
//When |
164 |
- Result result = callAction(controllers.routes.ref.UserApp.isUserExist("messages.js")); |
|
207 |
+ Result result = callAction(controllers.routes.ref.UserApp.isUsed("messages.js")); |
|
165 | 208 |
|
166 | 209 |
//Then |
167 | 210 |
assertThat(status(result)).isEqualTo(OK); |
--- test/support/Helpers.java
+++ test/support/Helpers.java
... | ... | @@ -63,7 +63,7 @@ |
63 | 63 |
YamlUtil.insertDataFromYaml("test-data.yml", new String[] { |
64 | 64 |
"users", "projects", "pullRequests", "milestones", |
65 | 65 |
"issues", "issueComments", "postings", |
66 |
- "postingComments", "projectUsers" }); |
|
66 |
+ "postingComments", "projectUsers", "organization", "organizationUsers"}); |
|
67 | 67 |
// Do numbering for issues and postings. |
68 | 68 |
for (Project project : Project.find.findList()) { |
69 | 69 |
List<Issue> issues = Issue.finder.where() |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?