use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class GravatarAvatarGeneratorTest method getRawLink_should_use_email_of_profile.
@Test
public void getRawLink_should_use_email_of_profile() {
String email = "toto@example.com";
Profile profile = getProfileWithEmail(email);
AvatarFormat format = AvatarFormat.Square32;
String urlOfEmail = generator.getRawLink(email);
String urlOfProfile = generator.getRawLink(profile);
assertEquals(urlOfEmail, urlOfProfile);
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class ImgurAvatarRepositoryTest method setUp.
@Before
public void setUp() {
this.profile = new Profile();
this.profile.setUser(new User());
this.defaultRepository = new DefaultAvatarRepository();
this.repository = new ImgurAvatarRepository(defaultRepository);
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class AdminController method backup.
@GetMapping(value = "/export", produces = "application/zip")
public ResponseEntity<StreamingResponseBody> backup(HttpServletRequest req, HttpServletResponse response) {
Profile authUser = utils.getAuthUser(req);
if (!utils.isAdmin(authUser)) {
return new ResponseEntity<StreamingResponseBody>(HttpStatus.UNAUTHORIZED);
}
String fileName = App.identifier(Config.getConfigParam("access_key", "scoold")) + "_" + Utils.formatDate("YYYYMMdd_HHmmss", Locale.US);
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".zip");
return new ResponseEntity<StreamingResponseBody>(out -> {
// export all fields, even those which are JSON-ignored
ObjectWriter writer = JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build().writer().without(SerializationFeature.INDENT_OUTPUT).without(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
long count = 0;
int partNum = 0;
// find all objects even if there are more than 10000 users in the system
Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
List<ParaObject> objects;
do {
objects = pc.findQuery("", "*", pager);
ZipEntry zipEntry = new ZipEntry(fileName + "_part" + (++partNum) + ".json");
zipOut.putNextEntry(zipEntry);
writer.writeValue(zipOut, objects);
count += objects.size();
} while (!objects.isEmpty());
logger.info("Exported {} objects to {}. Downloaded by {} (pager.count={})", count, fileName + ".zip", authUser.getCreatorid() + " " + authUser.getName(), pager.getCount());
} catch (final IOException e) {
logger.error("Failed to export data.", e);
}
}, HttpStatus.OK);
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class AdminController method generateAPIKey.
@ResponseBody
@PostMapping(path = "/generate-api-key", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> generateAPIKey(@RequestParam Integer validityHours, HttpServletRequest req, Model model) throws ParseException {
Profile authUser = utils.getAuthUser(req);
if (utils.isAdmin(authUser)) {
String jti = UUID.randomUUID().toString();
Map<String, Object> claims = Collections.singletonMap("jti", jti);
SignedJWT jwt = utils.generateJWToken(claims, TimeUnit.HOURS.toSeconds(validityHours));
if (jwt != null) {
String jwtString = jwt.serialize();
Date exp = jwt.getJWTClaimsSet().getExpirationTime();
utils.registerApiKey(jti, jwtString);
Map<String, Object> data = new HashMap<String, Object>();
data.put("jti", jti);
data.put("jwt", jwtString);
data.put("exp", exp == null ? 0L : Utils.formatDate(exp.getTime(), "YYYY-MM-dd HH:mm", Locale.UK));
return ResponseEntity.ok().body(data);
}
}
return ResponseEntity.status(403).build();
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class AdminController method createWebhook.
@PostMapping("/create-webhook")
public String createWebhook(@RequestParam String targetUrl, @RequestParam(required = false) String type, @RequestParam Boolean json, @RequestParam Set<String> events, HttpServletRequest req, Model model) {
Profile authUser = utils.getAuthUser(req);
if (Utils.isValidURL(targetUrl) && utils.isAdmin(authUser) && utils.isWebhooksEnabled()) {
Webhook webhook = new Webhook(targetUrl);
webhook.setCreate(events.contains("create"));
webhook.setUpdate(events.contains("update"));
webhook.setDelete(events.contains("delete"));
webhook.setCreateAll(events.contains("createAll"));
webhook.setUpdateAll(events.contains("updateAll"));
webhook.setDeleteAll(events.contains("deleteAll"));
webhook.setCustomEvents(events.stream().filter(e -> !StringUtils.equalsAny(e, "create", "update", "delete", "createAll", "updateAll", "deleteAll")).collect(Collectors.toList()));
if (utils.getCoreScooldTypes().contains(type)) {
webhook.setTypeFilter(type);
}
webhook.setUrlEncoded(!json);
webhook.resetSecret();
pc.create(webhook);
} else {
model.addAttribute("error", Collections.singletonMap("targetUrl", utils.getLang(req).get("requiredfield")));
return "base";
}
return "redirect:" + ADMINLINK;
}
Aggregations