예제 #1
0
def send_email(req):
    requestee = User.get(req.user_id)
    pkg = Package.get(req.pkg_id)
    selrole = False
    for role in pkg.roles:
        if role.role == "admin":
            selrole = role
    if not selrole:
        return
    admin = User.get(selrole.user_id)
    msg = _("""%s (%s) is requesting editor access to a dataset you have created
    %s.

Please click this link if you want to give this user write access:
%s%s""")
    controller = 'ckanext.kata.controllers:AccessRequestController'
    body = msg % (requestee.name, requestee.email, pkg.title if pkg.title else pkg.name,
                config.get('ckan.site_url', ''),
                h.url_for(controller=controller,
                action="unlock_access",
                id=req.id))
    email_dict = {}
    email_dict["subject"] = _("Access request for dataset %s" % pkg.title if pkg.title else pkg.name)
    email_dict["body"] = body
    send_notification(admin.as_dict(), email_dict)
예제 #2
0
def sendUserNotification(pkg, approved):
    url = config.get('ckan.site_url')

    status = getDoiStatus(pkg).get('status')
    if status is None:
        status = {}

    conn = psycopg2.connect(connStr)
    cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    cur.execute(
        "select email from public.user where name = %s", (status.get('requested_by'),)
    )
    users = cur.fetchall()
    cur.close()

    email = ""
    for user in users:
        email = user.get('email')
        break

    body = ""
    if approved:
        body = ("The DOI request for the dataset '%s' has been approved.  "
                "It may take a couple minutes for the DOI to generate.  "
                "You can view the dataset here:  %s/#result/%s\n\n"
                "\n\n-EcoSIS Team") % (pkg.get('title'),
                                       config.get('ecosis.search_url'),
                                       pkg.get("id"))
    else:
        body = ("The DOI request for the dataset '%s' requires more information before approval.  "
                "Please provide a full description, keywords and fill out as much metadata as possible.  "
                "Then feel free to re-request a DOI."
                "\n\n-EcoSIS Team") % (pkg.get('title'))

    if url != "" and url is not None:
        if email != "" and email is not None:
            try:
                send_notification(
                    {
                        "email" : email,
                        "display_name" : "EcoSIS User %s," % status.get('requested_by')
                    },
                    {
                        "subject" : "EcoSIS Dataset DOI Request - %s" % pkg.get('title'),
                        "body" : body
                    }
                )
            except:
                print "Failed to send admin email"

    return {
        "email" : email,
        "user" : status.get('requested_by')
    }
예제 #3
0
    def _send_message(self, subject, message, recipient_email, recipient_name=None):
        email_dict = {'subject': subject,
                      'body': message}

        if not recipient_name:
            # fall back to using the email address as the name of the recipient
            recipient_name = recipient_email

        recipient_dict = {'display_name': recipient_name, 'email': recipient_email}

        if message:
            send_notification(recipient_dict, email_dict)
예제 #4
0
    def _send_message(self, subject, message, recipient_email, recipient_name=None):
        email_dict = {'subject': subject,
                      'body': message}

        if not recipient_name:
            # fall back to using the email address as the name of the recipient
            recipient_name = recipient_email

        recipient_dict = {'display_name': recipient_name, 'email': recipient_email}

        if message:
            send_notification(recipient_dict, email_dict)
예제 #5
0
def send_contact_email(owner, requestee, pkg, message):
    msg = _("""%s (%s) is requesting access to study material for dataset you have created
    %s.

The message is as follows:
%s
""")
    body = msg % (requestee.name,\
                  requestee.email,\
                  pkg.title if pkg.title else pkg.name,\
                  message)
    email_dict = {}
    email_dict["subject"] = _("Material access request for dataset %s" % pkg.title\
                              if pkg.title else pkg.name)
    email_dict["body"] = body
    send_notification(owner.as_dict(), email_dict)
예제 #6
0
def sendAdminNotification(pkg):
    url = config.get('ckan.site_url')
    admin_email = config.get('ecosis.admin_email')

    if url != "" and url is not None:
        if admin_email != "" and admin_email is not None:
            try:
                send_notification(
                    {
                        "email" : admin_email,
                        "display_name" : "EcoSIS Admins"
                    },
                    {
                        "subject" : "EcoSIS Dataset DOI Request - %s" % pkg.get('title'),
                        "body" : ("A DOI has been requested for the dataset '%s' by user %s/user/%s.  "
                                    "You can view the dataset here:  %s/#result/%s and approve the DOI here: %s/doi-admin/#%s"
                                    "\n\n-EcoSIS Server") %
                                 (pkg.get('title'), config.get('ckan.site_url'), c.user, config.get('ecosis.search_url'), pkg.get("id"), config.get('ckan.site_url'), urllib2.quote(pkg.get("title")))
                    }
                )
            except:
                print "Failed to send admin email"
예제 #7
0
def send_edit_access_request_email(req):
    """
    Send edit access request email.

    :param user_id: user who requests access
    :param pkg_id: dataset's id
    """
    requester = User.get(req.user_id)
    pkg = Package.get(req.pkg_id)
    selrole = False
    for role in pkg.roles:
        if role.role == "admin":
            selrole = role
    if not selrole:
        return

    admin = User.get(selrole.user_id)
    admin_dict = admin.as_dict()
    admin_dict['name'] = admin.fullname if admin.fullname else admin.name

    msg = u'{a} ({b}) is requesting editing rights to the metadata in dataset\n\n{c}\n\n\
for which you are currently an administrator. Please click this \
link if you want to allow this user to edit the metadata of the dataset:\n\
{d}\n\n{a} ({b}) pyytää muokkausoikeuksia tietoaineiston\n\n{c}\n\n\
metatietoihin, joiden ylläpitäjä olet. Klikkaa linkkiä, jos haluat tämän käyttäjän \
saavan muokkausoikeudet aineiston metatietoihin:\n\
{d}\n'

    controller = 'ckanext.kata.controllers:EditAccessRequestController'

    requester_name = requester.fullname if requester.fullname else requester.name
    accessurl = config.get('ckan.site_url', '') + h.url_for(controller=controller, action="unlock_access", id=req.id)
    body = msg.format(a=requester_name, b=requester.email, c=pkg.title if pkg.title else pkg.name, d=accessurl)
    email_dict = {}
    email_dict["subject"] = u"Access request for dataset / pyyntö koskien tietoaineistoa %s" % pkg.title if pkg.title else pkg.name
    email_dict["body"] = body
    send_notification(admin_dict, email_dict)
예제 #8
0
def sub_run(q, ckanPackage, emailOnComplete, emailAddress, username):
    try:
        # calculate bounding box from spectra (lat/lng was provided)
        total = query.total(ckanPackage.get('id')).get('total')
        bbox = {
            "maxlat" : -9999,
            "minlat" : 9999,
            "maxlng" : -9999,
            "minlng" : 9999,
            "use" : False
        }

        # grab each spectra and insert into public EcoSIS search
        for i in range(0, total):
            spectra = query.get(ckanPackage.get('id'), index=i, must_be_valid=True, clean_wavelengths=False)
            if not 'datapoints' in spectra:
                continue
            if len(spectra['datapoints']) == 0:
                continue

            # update search
            spectraCollection.insert(spectra)
            # update the bounding box if the spectra has a lat/lng
            updateBbox(spectra, bbox)

        # see if we found a bounding box from the spectra
        if bbox["maxlat"] != -9999 and bbox["maxlng"] != -9999 and bbox["minlng"] != 9999 and bbox["minlng"] != -9999:
            bbox["use"] = True

        # mapreduce the dataset package data
        mapreduce.mapreducePackage(ckanPackage, bbox)

        # alert (email user) or quit
        if not emailOnComplete:
            updateLookup()
            return

        try:
            send_notification(
                {
                    "email" : emailAddress,
                    "display_name" : username
                },
                {
                    "subject" : "EcoSIS Push Successful",
                    "body" : ("Your dataset '%s' has been pushed to EcoSIS Search.  "
                                "You can view your dataset here:  %s#result/%s"
                                "\n\n-The EcoSIS Team") %
                             (ckanPackage.get('title'), config.get('ecosis.search_url'), ckanPackage.get("id"))
                }
            )
        except Exception as e:
            print "Failed to send email: %s" % emailAddress

        updateLookup()

    except Exception as e:
        try:
            print 'ERROR pushing to search: %s' % ckanPackage.get('id')

            # if badness, remove from search
            deleteUtils.cleanFromSearch(ckanPackage.get('id'))

            print e
            if not emailOnComplete:
                return

            send_notification(
                {
                    "email" : emailAddress,
                    "display_name" : username
                },
                {
                    "subject" : "EcoSIS Push Failed",
                    "body" : ("Your recent push to search for '%s' has failed.  "
                              "You can try again or contact [email protected].  "
                              "We apologize for the inconvenience\n\n-The EcoSIS Team") % (ckanPackage["title"])
                }
            )
        except:
            pass