use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class FilesController method uploadCardImage.
@RequestMapping(value = "/upload/cardImage/{cardWrapperId}", method = RequestMethod.POST)
@ResponseBody
public PostResult uploadCardImage(@PathVariable("cardWrapperId") String cardWrapperIdStr, @RequestParam("file") MultipartFile file) throws IOException {
if (getLoggedUser() == null) {
return new PostResult("error", "endpoint enabled users only", "");
}
UUID cardWrapperId = UUID.fromString(cardWrapperIdStr);
Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
if (governanceService.canEditModel(initiative.getId(), getLoggedUserId()) == DecisionVerdict.DENIED) {
return new PostResult("error", "not authorized", "");
}
return fileService.uploadCardImage(getLoggedUserId(), cardWrapperId, file);
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class ActivityService method getInitiativeSubscribers.
@Transactional
private List<Subscriber> getInitiativeSubscribers(UUID initiativeId) {
/* example https://docs.google.com/drawings/d/1PqPhefzrGVlWVfG-SRGS56l_e2qpNEsajLbnsAWcTfA/edit,
* assume initiativeId = C */
/* start with this initiative subscribers (S3 and S6 in example). Take into account that
* a subscriber state may be SUBSCRIPTION_DISABLED */
List<Subscriber> allSubscribers = subscriberRepository.findByElementId(initiativeId);
/* then add the subscribers of all parent initiatives (B and A, in that order) */
List<Initiative> parents = initiativeService.getParentGenealogyInitiatives(initiativeId);
for (Initiative parent : parents) {
List<Subscriber> parentSubscribers = subscriberRepository.findByElementId(parent.getId());
for (Subscriber parentSubscriber : parentSubscribers) {
int ixOfSubscriber = indexOfSubscriber(allSubscribers, parentSubscriber);
if (ixOfSubscriber == -1) {
/* if this user is not already in the list of subscriptions, then
* add it (this means that the applicable subscription is that at
* the lowest level) */
allSubscribers.add(parentSubscriber);
}
}
}
return allSubscribers;
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class EmailService method prepareWantToContributeEmail.
private Mail prepareWantToContributeEmail(List<WantToContributeNotification> notifications) {
Mail mail = new Mail();
Email fromEmail = new Email();
fromEmail.setName(env.getProperty("collectiveone.webapp.from-mail-name"));
fromEmail.setEmail(env.getProperty("collectiveone.webapp.from-mail"));
mail.setFrom(fromEmail);
mail.setSubject("Request to contribute");
for (WantToContributeNotification notification : notifications) {
String toEmailString = notification.getAdmin().getEmail();
Initiative initiative = notification.getInitiative();
String acceptRequestUrl = env.getProperty("collectiveone.webapp.baseurl") + "/#/app/inits/" + initiative.getId().toString() + "/people/addMember/" + notification.getUser().getC1Id().toString();
Personalization personalization = new Personalization();
Email toEmail = new Email();
toEmail.setEmail(toEmailString);
personalization.addTo(toEmail);
personalization.addSubstitution("$INITIATIVE_ANCHOR$", getInitiativeAnchor(initiative));
personalization.addSubstitution("$USER_NICKNAME$", notification.getUser().getProfile().getNickname());
personalization.addSubstitution("$USER_PICTURE$", notification.getUser().getProfile().getPictureUrl());
personalization.addSubstitution("$USER_EMAIL$", notification.getUser().getEmail());
personalization.addSubstitution("$ACCEPT_AS_MEMBER_URL$", acceptRequestUrl);
mail.addPersonalization(personalization);
notification.setEmailState(NotificationEmailState.DELIVERED);
wantToContributeRepository.save(notification);
}
mail.setTemplateId(env.getProperty("collectiveone.webapp.want-to-contribute-template"));
return mail;
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class ActivityService method messagePosted.
@Transactional
public void messagePosted(Message message, AppUser triggerUser, MessageThreadContextType contextType, UUID elementId) {
Initiative initiative = initiativeRepository.findById(messageService.getInitiativeIdOfMessageThread(message.getThread()));
Activity activity = getBaseActivity(triggerUser, initiative);
activity.setType(ActivityType.MESSAGE_POSTED);
activity.setMessage(message);
setMessageLocation(activity, contextType, elementId);
activity = activityRepository.save(activity);
addInitiativeActivityNotifications(activity);
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class EmailService method basicInitiativePersonalization.
private Personalization basicInitiativePersonalization(Notification notification) {
String toEmailString = notification.getSubscriber().getUser().getEmail();
String triggeredByUsername = notification.getActivity().getTriggerUser().getProfile().getNickname();
String triggerUserPictureUrl = notification.getActivity().getTriggerUser().getProfile().getPictureUrl();
Initiative initiative = notification.getActivity().getInitiative();
Personalization personalization = new Personalization();
Email toEmail = new Email();
toEmail.setEmail(toEmailString);
personalization.addTo(toEmail);
personalization.addSubstitution("$INITIATIVE_NAME$", initiative.getMeta().getName());
personalization.addSubstitution("$TRIGGER_USER_NICKNAME$", triggeredByUsername);
personalization.addSubstitution("$TRIGGER_USER_PICTURE$", triggerUserPictureUrl);
personalization.addSubstitution("$INITIATIVE_ANCHOR$", getInitiativeAnchor(initiative));
personalization.addSubstitution("$INITIATIVE_PICTURE$", "http://guillaumeladvie.com/wp-content/uploads/2014/04/ouishare.jpg");
personalization.addSubstitution("$UNSUSCRIBE_FROM_INITIATIVE_HREF$", getUnsuscribeFromInitiativeHref(initiative));
personalization.addSubstitution("$UNSUSCRIBE_FROM_ALL_HREF$", getUnsuscribeFromAllHref());
return personalization;
}
Aggregations