use of org.craftercms.studio.model.Site in project studio by craftercms.
the class UsersController method getUserSites.
/**
* Get user sites API
*
* @param userId User identifier
* @return Response containing list of sites
*/
@GetMapping(PATH_PARAM_ID + SITES)
public ResponseBody getUserSites(@PathVariable(REQUEST_PARAM_ID) String userId, @RequestParam(value = REQUEST_PARAM_OFFSET, required = false, defaultValue = "0") int offset, @RequestParam(value = REQUEST_PARAM_LIMIT, required = false, defaultValue = "10") int limit) throws ServiceLayerException, UserNotFoundException {
int uId = -1;
String username = StringUtils.EMPTY;
if (StringUtils.isNumeric(userId)) {
uId = Integer.parseInt(userId);
} else {
username = userId;
}
List<Site> allSites = userService.getUserSites(uId, username);
List<Site> paginatedSites = PaginationUtils.paginate(allSites, offset, limit, "siteId");
PaginatedResultList<Site> result = new PaginatedResultList<>();
result.setResponse(OK);
result.setTotal(allSites.size());
result.setOffset(offset);
result.setLimit(limit);
result.setEntities(RESULT_KEY_SITES, paginatedSites);
ResponseBody responseBody = new ResponseBody();
responseBody.setResult(result);
return responseBody;
}
use of org.craftercms.studio.model.Site in project studio by craftercms.
the class UsersController method getCurrentUserSites.
/**
* Get the sites of the current authenticated user API
*
* @return Response containing current authenticated user sites
*/
@GetMapping(ME + SITES)
public ResponseBody getCurrentUserSites(@RequestParam(value = REQUEST_PARAM_OFFSET, required = false, defaultValue = "0") int offset, @RequestParam(value = REQUEST_PARAM_LIMIT, required = false, defaultValue = "10") int limit) throws AuthenticationException, ServiceLayerException {
List<Site> allSites = userService.getCurrentUserSites();
List<Site> paginatedSites = PaginationUtils.paginate(allSites, offset, limit, "siteId");
PaginatedResultList<Site> result = new PaginatedResultList<>();
result.setResponse(OK);
result.setTotal(allSites.size());
result.setOffset(offset);
result.setLimit(limit);
result.setEntities(RESULT_KEY_SITES, paginatedSites);
ResponseBody responseBody = new ResponseBody();
responseBody.setResult(result);
return responseBody;
}
use of org.craftercms.studio.model.Site in project studio by craftercms.
the class UserServiceImpl method getUserSites.
@Override
@HasPermission(type = DefaultPermission.class, action = "read_users")
public List<Site> getUserSites(long userId, String username) throws ServiceLayerException, UserNotFoundException {
List<Site> sites = new ArrayList<>();
Set<String> allSites = siteService.getAllAvailableSites();
List<Group> userGroups = userServiceInternal.getUserGroups(userId, username);
boolean isSysAdmin = userGroups.stream().anyMatch(group -> group.getGroupName().equals(SYSTEM_ADMIN_GROUP));
// Iterate all sites. If the user has any of the site groups, it has access to the site
for (String siteId : allSites) {
List<String> siteGroups = groupServiceInternal.getSiteGroups(siteId);
if (isSysAdmin || userGroups.stream().anyMatch(userGroup -> siteGroups.contains(userGroup.getGroupName()))) {
try {
SiteFeed siteFeed = siteService.getSite(siteId);
Site site = new Site();
site.setSiteId(siteFeed.getSiteId());
site.setDesc(siteFeed.getDescription());
sites.add(site);
} catch (SiteNotFoundException e) {
logger.error("Site not found: {0}", e, siteId);
}
}
}
return sites;
}
Aggregations