Example #1
0
    def create_subscriber(self, community_id,
                          args) -> Tuple[dict, MassEnergizeAPIError]:
        subscriber, err = self.store.create_subscriber(community_id, args)
        if err:
            return None, err

        subject = 'Thank you for subscribing'
        content_variables = {
            'name':
            subscriber.name,
            'id':
            subscriber.id,
            'logo':
            subscriber.community.logo.file.url
            if subscriber.community and subscriber.community.logo else
            'https://s3.us-east-2.amazonaws.com/community.massenergize.org/static/media/logo.ee45265d.png',
            'community':
            subscriber.community.name if subscriber.community
            and subscriber.community.name else 'MassEnergize',
            'homelink':
            '%s/%s' % (COMMUNITY_URL_ROOT, subscriber.community.subdomain)
            if subscriber.community else COMMUNITY_URL_ROOT
        }
        send_massenergize_rich_email(subject, subscriber.email,
                                     'subscriber_registration_email.html',
                                     content_variables)

        return serialize(subscriber), None
Example #2
0
    def create_user(self, context: Context,
                    args) -> Tuple[dict, MassEnergizeAPIError]:
        res, err = self.store.create_user(context, args)
        if err:
            return None, err

        community = res["community"]
        user = res["user"]
        community_name = community.name if community else "Global Massenergize Community"
        community_logo = community.logo.file.url if community and community.logo else 'https://s3.us-east-2.amazonaws.com/community.massenergize.org/static/media/logo.ee45265d.png'
        subdomain = community.subdomain if community else "global"
        subject = f'Welcome to {community_name}, a MassEnergize community'
        homelink = f'{COMMUNITY_URL_ROOT}/{subdomain}'

        content_variables = {
            'name': user.preferred_name,
            'community': community_name,
            'homelink': homelink,
            'logo': community_logo,
            'actionslink': f'{homelink}/actions',
            'eventslink': f'{homelink}/events',
            'serviceslink': f'{homelink}/services',
            'privacylink': f"{homelink}/policies?name=Privacy%20Policy"
        }

        send_massenergize_rich_email(subject, user.email,
                                     'user_registration_email.html',
                                     content_variables)

        return serialize(user, full=True), None
Example #3
0
def _send_invitation_email(user_info, mess):

    # send email inviting user to complete their profile
    cadmin_name = user_info.get("cadmin", "The Community Administrator")
    cadmin_email = user_info.get("cadmin_email", "*****@*****.**")
    cadmin_firstname = cadmin_name.split(" ")[0]
    community_name = user_info.get("community", None)
    community_logo = user_info.get("community_logo", None)
    community_info = user_info.get("community_info", None)
    team_name = user_info.get("team_name", None)
    location = user_info.get("location", None)
    subdomain = user_info.get("subdomain", "global")
    email = user_info.get("email", None)
    first_name = user_info.get("first_name", None)
    team_leader = user_info.get('team_leader', None)
    team_leader_firstname = user_info.get('team_leader_firstname', None)
    team_leader_email = user_info.get('team_leader_email', None)

    if mess and mess != "":
        custom_intro = "Here is a welcome message from " + cadmin_firstname
        custom_message = mess
    else:
        custom_intro = "Here is how " + cadmin_firstname + " describes " + community_name
        custom_message = community_info

    subject = cadmin_name + " invites you to join the " + community_name + " Community"
    #send_massenergize_email(subject=subject , msg=message, to=email)
    email_template = 'community_invitation_email.html'
    if team_name == 'none' or team_name == "None":
        team_name = None
    if team_name:
        email_template = 'team_invitation_email.html'

    #community_logo =  community.logo.file.url if community and community.logo else 'https://s3.us-east-2.amazonaws.com/community.massenergize.org/static/media/logo.ee45265d.png'
    #subdomain =   community.subdomain if community else "global"
    #subject = f'Welcome to {community_name}, a MassEnergize community'
    homelink = f'{COMMUNITY_URL_ROOT}/{subdomain}'

    content_variables = {
        'name': first_name,
        'community': community_name,
        'community_admin': cadmin_name,
        'community_admin_firstname': cadmin_firstname,
        'homelink': homelink,
        'logo': community_logo,
        'location': location,
        'team': team_name,
        'team_leader': team_leader,
        'team_leader_firstname': team_leader_firstname,
        'team_leader_email': team_leader_email,
        'custom_intro': custom_intro,
        'custom_message': custom_message,
        'contactlink': f'{homelink}/contactus',
        'signuplink': f'{homelink}/signup',
        'privacylink': f"{homelink}/policies?name=Privacy%20Policy"
    }

    send_massenergize_rich_email(subject, email, email_template,
                                 content_variables, cadmin_email)
Example #4
0
    def add_community_admin(self, context,
                            args) -> (dict, MassEnergizeAPIError):
        res, err = self.store.add_community_admin(context, args)

        if err:
            return None, err
        subject = 'Welcome to the MassEnergize Team'
        content_variables = {
            'name': res["name"],
            'admin_link': ADMIN_URL_ROOT,
            "community_name": res["community_name"],
            'sandbox_link': f"{COMMUNITY_SANDBOX_URL_ROOT}/{res['subdomain']}",
            'portal_link': f"{COMMUNITY_URL_ROOT}/{res['subdomain']}",
            'admin_type': 'Community'
        }
        send_massenergize_rich_email(subject, res["email"],
                                     'new_admin_email.html', content_variables)
        return res, None
Example #5
0
 def add_super_admin(self, context, args) -> (dict, MassEnergizeAPIError):
     admin, err = self.store.add_super_admin(context, args)
     if err:
         return None, err
     subject = 'Welcome to the MassEnergize Team'
     content_variables = {
         'name':
         admin.full_name,
         'adminlink':
         ADMIN_URL_ROOT,
         'admintype':
         'Super',
         'admintext':
         "Now that you are a super admin, you have access the MassEnergize admin website at %s. You have full control over the content of our sites, can publish new communities and add new admins"
         % (ADMIN_URL_ROOT)
     }
     send_massenergize_rich_email(subject, admin.email,
                                  'new_admin_email.html', content_variables)
     return serialize(admin, full=True), None
Example #6
0
    def message_admin(self, context,
                      args) -> Tuple[dict, MassEnergizeAPIError]:

        message, err = self.store.message_admin(context, args)
        if err:
            return None, err

        # Original comment: dont want to send emails all the time, just show up in the admin site and if they want they can send emails
        # Now community admins are requesting e-mail messages.  We don't have contact preferences defined yet but will do that.
        # For now, send e-mail to primary community contact for a site
        admin_email = message.community.owner_email
        admin_name = message.community.owner_name
        first_name = admin_name.split(" ")[0]
        if not first_name or first_name == "":
            first_name = admin_name

        subject = 'A message was sent to the Community Admin for ' + message.community.name

        content_variables = {
            'name': first_name,
            'message_url': f"{ADMIN_URL_ROOT}/admin/edit/{message.id}/message",
            "community_name": message.community.name,
            "from_name": message.user_name,
            "email": message.email,
            "subject": message.title,
            "message_body": message.body,
        }
        send_massenergize_rich_email(subject, admin_email,
                                     'contact_admin_email.html',
                                     content_variables)

        send_slack_message(
            SLACK_COMMUNITY_ADMINS_WEBHOOK_URL, {
                "from_name": message.user_name,
                "email": message.email,
                "subject": message.title,
                "message": message.body,
                "url": f"{ADMIN_URL_ROOT}/admin/edit/{message.id}/message",
                "community": message.community.name
            })

        return serialize(message), None