Commit 8fa01dbd authored by Piotr Gawron's avatar Piotr Gawron
Browse files

adding new user properly set privileges

parent 77d97e76
......@@ -354,20 +354,24 @@ EditUserDialog.prototype.initProjectsTab = function () {
columns: columns
});
$(projectsTable).on("click", "[name='project-privilege-checkbox']", function () {
var data = $(this).attr("data");
var data = $(this).attr("data").split(":");
var type = data[0];
var projectId = data[1];
if ($(this).is(":checked")) {
return self.grantPrivilege({privilegeType: data});
return self.grantPrivilege({privilegeType: type, objectId: projectId});
} else {
return self.revokePrivilege({privilegeType: data});
return self.revokePrivilege({privilegeType: type, objectId: projectId});
}
});
$("[name='defaultProjectsRow']", self.getElement()).on("click", "[name='project-privilege-checkbox']", function () {
var data = $(this).attr("data");
var data = $(this).attr("data").split(":");
var type = data[0];
var projectId = data[1];
if ($(this).is(":checked")) {
return self.grantPrivilege({privilegeType: data});
return self.grantPrivilege({privilegeType: type, objectId: projectId});
} else {
return self.revokePrivilege({privilegeType: data});
return self.revokePrivilege({privilegeType: type, objectId: projectId});
}
});
};
......@@ -391,11 +395,13 @@ EditUserDialog.prototype.initPrivilegesTab = function () {
});
$(privilegesTable).on("click", "[name='privilege-checkbox']", function () {
var privilegeType = $(this).attr("data");
var data = $(this).attr("data").split(":");
var type = data[0];
var projectId = data[1];
if ($(this).is(":checked")) {
return self.grantPrivilege({privilegeType: privilegeType});
return self.grantPrivilege({privilegeType: type, objectId: projectId});
} else {
return self.revokePrivilege({privilegeType: privilegeType});
return self.revokePrivilege({privilegeType: type, objectId: projectId});
}
});
};
......@@ -555,7 +561,7 @@ EditUserDialog.prototype.projectToTableRow = function (project, columns) {
if (option !== null && option !== undefined) {
if (option.getValue().toLowerCase() === "true") {
user.setPrivilege({privilegeType: privilege, objectId: projectId});
user.setPrivilege({privilegeType: privilege.getName(), objectId: projectId});
checked = "checked";
}
}
......
......@@ -98,8 +98,6 @@ public class UserController extends BaseController {
@RequestBody MultiValueMap<String, Object> formData,
@PathVariable(value = "login") String login) throws QueryException {
Map<String, Object> userMap = userRest.addUser(login, formData);
User user = userService.getUserByLogin(login);
userService.grantDefaultPrivileges(user);
return userMap;
}
......
......@@ -689,6 +689,7 @@ public class UserRestImpl extends BaseRestImpl {
}
user = new User();
user.setLogin(login);
boolean defaultPrivileges = false;
for (String key : userData.keySet()) {
String stringValue = getFirstValue(userData.get(key));
if (key.equalsIgnoreCase("name")) {
......@@ -705,11 +706,18 @@ public class UserRestImpl extends BaseRestImpl {
if (!user.getLogin().equals(stringValue)) {
throw new QueryException("login must match url");
}
} else if (key.equalsIgnoreCase("defaultPrivileges")) {
if (stringValue != null ) {
defaultPrivileges = "true".equalsIgnoreCase(stringValue);
}
} else {
throw new QueryException("Unknown parameter: " + key);
}
}
getUserService().addUser(user);
if (defaultPrivileges) {
getUserService().grantDefaultPrivileges(user);
}
return getUser(login, "");
}
......
......@@ -282,7 +282,9 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
createProject(TEST_PROJECT);
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("name", "FirstName"))));
new BasicNameValuePair("name", "FirstName"),
new BasicNameValuePair("defaultPrivileges", "true")
)));
RequestBuilder grantRequest = post("/users/" + testLogin)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
......@@ -315,7 +317,9 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
createProject(TEST_PROJECT);
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("name", "FirstName"))));
new BasicNameValuePair("name", "FirstName"),
new BasicNameValuePair("defaultPrivileges", "true")
)));
RequestBuilder grantRequest = post("/users/" + testLogin)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment