Search in sources :

Example 16 with Initiative

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);
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) Initiative(org.collectiveone.modules.initiatives.Initiative) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with Initiative

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;
}
Also used : Initiative(org.collectiveone.modules.initiatives.Initiative) TokenMint(org.collectiveone.modules.tokens.TokenMint) Transactional(javax.transaction.Transactional)

Example 18 with Initiative

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;
}
Also used : Mail(com.sendgrid.Mail) Email(com.sendgrid.Email) Personalization(com.sendgrid.Personalization) Initiative(org.collectiveone.modules.initiatives.Initiative)

Example 19 with Initiative

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);
}
Also used : Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 20 with Initiative

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;
}
Also used : Personalization(com.sendgrid.Personalization) Email(com.sendgrid.Email) Initiative(org.collectiveone.modules.initiatives.Initiative)

Aggregations

Initiative (org.collectiveone.modules.initiatives.Initiative)32 Transactional (javax.transaction.Transactional)15 UUID (java.util.UUID)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 PostResult (org.collectiveone.common.dto.PostResult)11 GetResult (org.collectiveone.common.dto.GetResult)10 ArrayList (java.util.ArrayList)4 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)4 ActivityDto (org.collectiveone.modules.activity.dto.ActivityDto)3 PageRequest (org.springframework.data.domain.PageRequest)3 Email (com.sendgrid.Email)2 Personalization (com.sendgrid.Personalization)2 Timestamp (java.sql.Timestamp)2 Assignation (org.collectiveone.modules.assignations.Assignation)2 ModelCardWrapper (org.collectiveone.modules.model.ModelCardWrapper)2 ModelSection (org.collectiveone.modules.model.ModelSection)2 ModelView (org.collectiveone.modules.model.ModelView)2 TokenMint (org.collectiveone.modules.tokens.TokenMint)2 TokenType (org.collectiveone.modules.tokens.TokenType)2 AssetsDto (org.collectiveone.modules.tokens.dto.AssetsDto)2