use of com.serotonin.m2m2.web.mvc.rest.v1.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserAccessRestController method getDataSourceAccess.
@ApiOperation(value = "Get Data Source Access List", notes = "Returns a list of users and thier access")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/data-source/{xid}")
public ResponseEntity<List<UserAccessModel>> getDataSourceAccess(@ApiParam(value = "Valid data point xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<List<UserAccessModel>> result = new RestProcessResult<List<UserAccessModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> vo = DataSourceDao.instance.getByXid(xid);
if (vo != null) {
List<UserAccessModel> models = new ArrayList<UserAccessModel>();
List<User> allUsers = UserDao.instance.getUsers();
for (User mangoUser : allUsers) {
if (Permissions.hasDataSourcePermission(mangoUser, vo)) {
models.add(new UserAccessModel(Permissions.ACCESS_TYPE_CODES.getCode(DataPointAccessTypes.DATA_SOURCE), new UserModel(mangoUser)));
}
}
return result.createResponseEntity(models);
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserAccessRestController method getDataPointAccess.
@ApiOperation(value = "Get Data Point Access List", notes = "Returns a list of users and thier access")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/data-point/{xid}")
public ResponseEntity<List<UserAccessModel>> getDataPointAccess(@ApiParam(value = "Valid data point xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<List<UserAccessModel>> result = new RestProcessResult<List<UserAccessModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
DataPointVO vo = DataPointDao.instance.getByXid(xid);
if (vo != null) {
List<UserAccessModel> models = new ArrayList<UserAccessModel>();
List<User> allUsers = UserDao.instance.getUsers();
int accessType;
for (User mangoUser : allUsers) {
accessType = Permissions.getDataPointAccessType(mangoUser, vo);
if (accessType != Permissions.DataPointAccessTypes.NONE) {
models.add(new UserAccessModel(Permissions.ACCESS_TYPE_CODES.getCode(accessType), new UserModel(mangoUser)));
}
}
return result.createResponseEntity(models);
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserRestController method getNewUser.
@ApiOperation(value = "Get new user", notes = "Returns a new user with default values")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/new/user")
public ResponseEntity<UserModel> getNewUser(HttpServletRequest request) {
RestProcessResult<UserModel> result = new RestProcessResult<UserModel>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
return result.createResponseEntity(new UserModel(new User()));
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserRestController method updateMuted.
@ApiOperation(value = "Update a user's audio mute setting", notes = "If you do not provide the mute parameter the current setting will be toggled")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json", "text/csv" }, value = "/{username}/mute")
public ResponseEntity<UserModel> updateMuted(@ApiParam(value = "Username", required = true, allowMultiple = false) @PathVariable String username, @ApiParam(value = "Mute", required = false, defaultValue = "Toggle the current setting", allowMultiple = false) @RequestParam(required = false) Boolean mute, HttpServletRequest request, Authentication authentication) throws RestValidationFailedException {
RestProcessResult<UserModel> result = new RestProcessResult<UserModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
User u = UserDao.instance.getUser(username);
if (Permissions.hasAdmin(user)) {
if (u == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (u.getId() == user.getId() && !(authentication instanceof UsernamePasswordAuthenticationToken)) {
throw new AccessDeniedException(new TranslatableMessage("rest.error.usernamePasswordOnly"));
}
if (mute == null) {
u.setMuted(!u.isMuted());
} else {
u.setMuted(mute);
}
UserModel model = new UserModel(u);
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
} else {
UserDao.instance.saveUser(u);
sessionRegistry.userUpdated(request, u);
}
return result.createResponseEntity(model);
} else {
if (u.getId() != user.getId()) {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to access user : " + u.getUsername());
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
} else {
if (mute == null) {
// Toggle
u.setMuted(!u.isMuted());
} else {
u.setMuted(mute);
}
UserModel model = new UserModel(u);
// Allow users to update themselves
model.getData().setId(u.getId());
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
} else {
UserDao.instance.saveUser(u);
sessionRegistry.userUpdated(request, u);
}
return result.createResponseEntity(model);
}
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserRestController method getUser.
@ApiOperation(value = "Get user by name", notes = "Returns the user specified by the given username")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/{username}")
public ResponseEntity<UserModel> getUser(@ApiParam(value = "Valid username", required = true, allowMultiple = false) @PathVariable String username, HttpServletRequest request) {
RestProcessResult<UserModel> result = new RestProcessResult<UserModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
User u = UserDao.instance.getUser(username);
if (Permissions.hasAdmin(user)) {
if (u == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
UserModel model = new UserModel(u);
return result.createResponseEntity(model);
} else {
if (u.getId() != user.getId()) {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to access user : " + u.getUsername());
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
} else {
// Allow users to access themselves
return result.createResponseEntity(new UserModel(u));
}
}
}
return result.createResponseEntity();
}
Aggregations