Exemple #1
0
 def get_next_action(self, request, application, roles):
     """ Retrieve the next state. """
     application.reopen()
     link, is_secret = base.get_email_link(application)
     emails.send_invite_email(application, link, is_secret)
     messages.success(
         request, "Sent an invitation to %s." % application.applicant.email)
     return 'success'
 def get_next_action(self, request, application, roles):
     """ Retrieve the next state. """
     application.reopen()
     link, is_secret = base.get_email_link(application)
     emails.send_invite_email(application, link, is_secret)
     messages.success(
         request,
         "Sent an invitation to %s."
         % application.applicant.email)
     return 'success'
Exemple #3
0
 def view(self, request, application, label, roles, actions):
     """ Django view method. """
     if label is None and \
             'is_applicant' in roles and 'is_admin' not in roles:
         for action in actions:
             if action in request.POST:
                 return action
         link, is_secret = base.get_email_link(application)
         return render_to_response(
             'kgapplications/software_introduction.html',
             {'actions': actions, 'application': application,
                 'roles': roles, 'link': link, 'is_secret': is_secret},
             context_instance=RequestContext(request))
     return super(StateIntroduction, self).view(
         request, application, label, roles, actions)
Exemple #4
0
 def view(self, request, application, label, roles, actions):
     """ Django get_next_action method. """
     if application.new_applicant is not None:
         if not application.new_applicant.email_verified:
             application.new_applicant.email_verified = True
             application.new_applicant.save()
     for action in actions:
         if action in request.POST:
             return action
     link, is_secret = base.get_email_link(application)
     return render(
         template_name='kgapplications/project_aed_introduction.html',
         context={
             'actions': actions,
             'application': application, 'roles': roles,
             'link': link, 'is_secret': is_secret,
         },
         request=request)
Exemple #5
0
 def view(self, request, application, label, roles, actions):
     """ Django view method. """
     if label is None and \
             'is_applicant' in roles and 'is_admin' not in roles:
         for action in actions:
             if action in request.POST:
                 return action
         link, is_secret = base.get_email_link(application)
         return render_to_response(
             'kgapplications/software_introduction.html', {
                 'actions': actions,
                 'application': application,
                 'roles': roles,
                 'link': link,
                 'is_secret': is_secret
             },
             context_instance=RequestContext(request))
     return super(StateIntroduction, self).view(request, application, label,
                                                roles, actions)
    def get_next_action(self, request, application, roles):
        """ Retrieve the next state. """
        # Check for serious errors in submission.
        # Should only happen in rare circumstances.
        errors = application.check_valid()
        if len(errors) > 0:
            for error in errors:
                messages.error(request, error)
            return 'error'

        # approve application
        approved_by = request.user
        created_person, created_account = application.approve(approved_by)

        # send email
        application.extend()
        link, is_secret = base.get_email_link(application)
        emails.send_approved_email(
            application, created_person, created_account, link, is_secret)

        if created_person or created_account:
            return 'password_needed'
        else:
            return 'password_ok'
Exemple #7
0
    def get_next_action(self, request, application, roles):
        """ Retrieve the next state. """
        # Check for serious errors in submission.
        # Should only happen in rare circumstances.
        errors = application.check_valid()
        if len(errors) > 0:
            for error in errors:
                messages.error(request, error)
            return 'error'

        # approve application
        approved_by = request.user
        created_person, created_account = application.approve(approved_by)

        # send email
        application.extend()
        link, is_secret = base.get_email_link(application)
        emails.send_approved_email(application, created_person,
                                   created_account, link, is_secret)

        if created_person or created_account:
            return 'password_needed'
        else:
            return 'password_ok'
    def handle(self, *args, **options):
        csvfile = options.get('csvfile')
        verbosity = int(options.get('verbosity', 1))

        try:
            data = csv.DictReader(open(csvfile))
        except csv.Error:
            sys.stderr.write("ERROR: Failed to read CSV file.\n")
            sys.exit(1)

        success = 0
        fail_count = 0
        skip = 0
        for user in data:
            fail = False

            if verbosity >= 1:
                print("Attempting to send an invite to user '%s' at '%s'" % (user.get('username'), user.get('email')))

            if 'username' not in user:
                sys.stderr.write("Error: Failed to find username column.\n")
                fail = True
            if 'password' not in user:
                sys.stderr.write("Error: Failed to find password column.\n")
                fail = True
            if 'short_name' not in user:
                sys.stderr.write("Error: Failed to find short_name column.\n")
                fail = True
            if 'full_name' not in user:
                sys.stderr.write("Error: Failed to find full_name column.\n")
                fail = True
            if 'email' not in user:
                sys.stderr.write("Error: Failed to find email column.\n")
                fail = True
            if 'institute' not in user:
                sys.stderr.write("Error: Failed to find institute column.\n")
                fail = True
            if 'project' not in user:
                sys.stderr.write("Error: Failed to find project column.\n")
                fail = True

            if not RE_VALID_USERNAME.match(user['username']):
                sys.stderr.write(
                    "Error: Username is invalid. "
                    "Use only letters, digits and underscores.\n")
                fail = True

            try:
                validate_email(user['email'])
            except exceptions.ValidationError:
                sys.stderr.write(
                    "Error: E-mail address '%s' is invalid.\n" % user['email'])
                fail = True

            if fail:
                sys.stderr.write(
                    "Skipping row for username '%s' due to errors\n"
                    % user['username'])
                fail_count += 1
                continue

            try:
                institute = Institute.objects.get(name=user['institute'])
                user['institute'] = institute
            except Institute.DoesNotExist:
                sys.stderr.write(
                    "Error: Institute '%s' does not exist. Skipping\n"
                    % user['institute'])
                fail_count += 1
                continue

            project = None
            if user['project']:
                try:
                    project = Project.objects.get(pid=user['project'])
                except Project.DoesNotExist:
                    sys.stderr.write(
                        "Error: Project '%s' does not exist. Skipping\n"
                        % user['project'])
                    fail_count += 1
                    continue

            applicant, existing_person = get_applicant_from_email(user['email'])
            if existing_person:
                print("skipping %s:%s, user already exists" % (user['username'], user['email']))
                skip += 1
                continue

            application = ProjectApplication()
            applicant.short_name = user["short_name"]
            applicant.full_name = user["full_name"]
            applicant.username = user["username"]
            application.applicant = applicant
            application.project = project
            application.state = ProjectApplication.OPEN
            application.header_message = "Please select your institute and hit the 'SAML login' button when prompted"
            application.reopen()

            email_link, is_secret = base.get_email_link(application)
            emails.send_invite_email(application, email_link, is_secret)
            success += 1

        print('')
        print('Added:   %s' % success)
        print('Skipped: %s' % skip)
        print('Failed:  %s' % fail_count)

        sys.exit(0)
Exemple #9
0
    def handle(self, *args, **options):
        csvfile = options.get('csvfile')
        verbosity = int(options.get('verbosity', 1))

        try:
            data = csv.DictReader(open(csvfile))
        except csv.Error:
            sys.stderr.write("ERROR: Failed to read CSV file.\n")
            sys.exit(1)

        success = 0
        fail_count = 0
        skip = 0
        for user in data:
            fail = False

            if verbosity >= 1:
                print("Attempting to send an invite to user '%s' at '%s'" %
                      (user.get('username'), user.get('email')))

            if 'username' not in user:
                sys.stderr.write("Error: Failed to find username column.\n")
                fail = True
            if 'password' not in user:
                sys.stderr.write("Error: Failed to find password column.\n")
                fail = True
            if 'short_name' not in user:
                sys.stderr.write("Error: Failed to find short_name column.\n")
                fail = True
            if 'full_name' not in user:
                sys.stderr.write("Error: Failed to find full_name column.\n")
                fail = True
            if 'email' not in user:
                sys.stderr.write("Error: Failed to find email column.\n")
                fail = True
            if 'institute' not in user:
                sys.stderr.write("Error: Failed to find institute column.\n")
                fail = True
            if 'project' not in user:
                sys.stderr.write("Error: Failed to find project column.\n")
                fail = True

            if not RE_VALID_USERNAME.match(user['username']):
                sys.stderr.write("Error: Username is invalid. "
                                 "Use only letters, digits and underscores.\n")
                fail = True

            try:
                validate_email(user['email'])
            except exceptions.ValidationError:
                sys.stderr.write("Error: E-mail address '%s' is invalid.\n" %
                                 user['email'])
                fail = True

            if fail:
                sys.stderr.write(
                    "Skipping row for username '%s' due to errors\n" %
                    user['username'])
                fail_count += 1
                continue

            try:
                institute = Institute.objects.get(name=user['institute'])
                user['institute'] = institute
            except Institute.DoesNotExist:
                sys.stderr.write(
                    "Error: Institute '%s' does not exist. Skipping\n" %
                    user['institute'])
                fail_count += 1
                continue

            project = None
            if user['project']:
                try:
                    project = Project.objects.get(pid=user['project'])
                except Project.DoesNotExist:
                    sys.stderr.write(
                        "Error: Project '%s' does not exist. Skipping\n" %
                        user['project'])
                    fail_count += 1
                    continue

            applicant, existing_person = get_applicant_from_email(
                user['email'])
            if existing_person:
                print("skipping %s:%s, user already exists" %
                      (user['username'], user['email']))
                skip += 1
                continue

            application = ProjectApplication()
            applicant.short_name = user["short_name"]
            applicant.full_name = user["full_name"]
            applicant.username = user["username"]
            application.new_applicant = applicant
            application.project = project
            application.state = ProjectApplication.OPEN
            application.header_message = "Please select your institute and hit the 'AAF login' button when prompted"
            application.reopen()

            email_link, is_secret = base.get_email_link(application)
            emails.send_invite_email(application, email_link, is_secret)
            success += 1

        print('')
        print('Added:   %s' % success)
        print('Skipped: %s' % skip)
        print('Failed:  %s' % fail_count)

        sys.exit(0)