Revision 3abf6c78

b/snf-astakos-app/astakos/im/activation_backends.py
104 104
    def handle_activation(self, user, \
105 105
                          activation_template_name='im/activation_email.txt', \
106 106
                          greeting_template_name='im/welcome_email.txt', \
107
                          admin_email_template_name='im/admin_notification.txt', \
107
                          admin_email_template_name='im/account_notification.txt', \
108 108
                          switch_accounts_email_template_name='im/switch_accounts_email.txt'):
109 109
        """
110 110
        If the user is already active returns immediately.
......
132 132
                    send_activation(user, activation_template_name)
133 133
                    return VerificationSent()
134 134
            else:
135
                send_admin_notification(user, admin_email_template_name)
135
                send_admin_notification(
136
                    template_name=admin_email_template_name,
137
                    dictionary={'user':user, 'group_creation':True},
138
                    subject='%s alpha2 testing account notification' % SITENAME
139
                )
136 140
                return NotificationSent()
137 141
        except BaseException, e:
138 142
            logger.exception(e)
b/snf-astakos-app/astakos/im/functions.py
105 105
    user.activation_sent = datetime.now()
106 106
    user.save()
107 107

  
108
def send_admin_notification(user, template_name='im/admin_notification.txt'):
108
def send_admin_notification(template_name,
109
    dictionary={},
110
    subject='alpha2 testing notification',
111
):
109 112
    """
110
    Send email to DEFAULT_ADMIN_EMAIL to notify for a new user registration.
113
    Send notification email to DEFAULT_ADMIN_EMAIL.
111 114
    
112 115
    Raises SendNotificationError
113 116
    """
114 117
    if not DEFAULT_ADMIN_EMAIL:
115 118
        return
116
    message = render_to_string(template_name, {
117
            'user': user,
118
            'baseurl': BASEURL,
119
            'site_name': SITENAME,
120
            'support': DEFAULT_CONTACT_EMAIL})
119
    message = render_to_string(template_name, dictionary)
121 120
    sender = DEFAULT_FROM_EMAIL
122 121
    try:
123
        send_mail('%s alpha2 testing account notification' % SITENAME, message, sender, [DEFAULT_ADMIN_EMAIL])
122
        send_mail(subject, message, sender, [DEFAULT_ADMIN_EMAIL])
124 123
    except (SMTPException, socket.error) as e:
125 124
        logger.exception(e)
126 125
        raise SendNotificationError()
127 126
    else:
128
        msg = 'Sent admin notification for user %s' % user.email
127
        msg = 'Sent admin notification for user %s' % dictionary
129 128
        logger._log(LOGGING_LEVEL, msg, [])
130 129

  
131
def send_helpdesk_notification(user, template_name='im/helpdesk_notification.txt'):
130
def send_helpdesk_notification(user, template_name='im/account_notification.txt'):
132 131
    """
133 132
    Send email to DEFAULT_CONTACT_EMAIL to notify for a new user activation.
134 133
    
......
136 135
    """
137 136
    if not DEFAULT_CONTACT_EMAIL:
138 137
        return
139
    message = render_to_string(template_name, {
140
            'user': user,
141
            'baseurl': BASEURL,
142
            'site_name': SITENAME,
143
            'support': DEFAULT_ADMIN_EMAIL})
138
    message = render_to_string(
139
        template_name,
140
        {'user': user}
141
    )
144 142
    sender = DEFAULT_FROM_EMAIL
145 143
    try:
146
        send_mail('%s alpha2 testing account activated' % SITENAME, message, sender, [DEFAULT_CONTACT_EMAIL])
144
        send_mail(
145
            '%s alpha2 testing account activated' % SITENAME,
146
            message,
147
            sender,
148
            [DEFAULT_CONTACT_EMAIL]
149
        )
147 150
    except (SMTPException, socket.error) as e:
148 151
        logger.exception(e)
149 152
        raise SendNotificationError()
150 153
    else:
151
        msg = 'Sent helpdesk admin notification for user %s' % user.email
154
        msg = 'Sent helpdesk admin notification for %s' % user.email
152 155
        logger._log(LOGGING_LEVEL, msg, [])
153 156

  
154 157
def send_invitation(invitation, template_name='im/invitation.txt'):
b/snf-astakos-app/astakos/im/management/commands/user_add.py
103 103
        if options['active']:
104 104
            user.is_active = True
105 105
        if options['admin']:
106
            user.is_admin = True
106
            user.is_superuser = True
107 107
        
108 108
        try:
109 109
            user.save()
b/snf-astakos-app/astakos/im/models.py
332 332
        logger._log(LOGGING_LEVEL, msg, [])
333 333

  
334 334
    def __unicode__(self):
335
        return self.username
335
        return '%s (%s)' % (self.realname, self.email)
336 336
    
337 337
    def conflicting_email(self):
338 338
        q = AstakosUser.objects.exclude(username = self.username)
b/snf-astakos-app/astakos/im/templates/im/account_notification.txt
1
--- A translation in English follows ---
2

  
3
{% if group_creation %}
4
Έχει δημιουργηθεί ο παρακάτω λογαριασμός:
5
{% else %}
6
Έχει ενεργοποιηθεί ο παρακάτω λογαριασμός:
7
{% endif %}
8

  
9
Email:          {{user.email}}
10
First name:     {{user.first_name}}
11
Last name:      {{user.last_name}}
12
Is active:      {{user.is_active}}
13
Level:          {{user.level}}
14
Invitations:    {{user.invitations}}
15

  
16
{% if group_creation %}
17
Για την ενεργοποίησή του μπορείτε να χρησιμοποιήσετε το command line εργαλείο snf-manage user_send_activation
18
{% endif %}
19
--
20

  
21
{% if group_creation %}
22
The following account has been created:
23
{% else %}
24
The following account has been activated:
25
{% endif %}
26

  
27
Email:          {{user.email}}
28
First name:     {{user.first_name}}
29
Last name:      {{user.last_name}}
30
Is active:      {{user.is_active}}
31
Level:          {{user.level}}
32
Invitations:    {{user.invitations}}
33

  
34
{% if group_creation %}
35
For its activation you can use the command line tool snf-manage user_send_activation
36
{% endif %}
/dev/null
1
--- A translation in English follows ---
2

  
3
Έχει δημιουργηθεί ο παρακάτω λογαριασμός:
4

  
5
Email:          {{user.email}}
6
First name:     {{user.first_name}}
7
Last name:      {{user.last_name}}
8
Is active:      {{user.is_active}}
9
Level:          {{user.level}}
10
Invitations:    {{user.invitations}}
11

  
12
Για την ενεργοποίησή του μπορείτε να χρησιμοποιήσετε το command line εργαλείο snf-manage user_send_activation
13
--
14

  
15
The following account has been created:
16

  
17
Email:          {{user.email}}
18
First name:     {{user.first_name}}
19
Last name:      {{user.last_name}}
20
Is active:      {{user.is_active}}
21
Level:          {{user.level}}
22
Invitations:    {{user.invitations}}
23

  
24
For its activation you can use the command line tool snf-manage user_send_activation
b/snf-astakos-app/astakos/im/templates/im/group_creation_notification.txt
1
--- A translation in English follows ---
2

  
3
Έχει δημιουργηθεί το παρακάτω group:
4

  
5
Id:                 {{group.id}}}
6
Name:               {{group.name}}
7
Type:               {{group.kind}}
8
Issue date:         {{group.issue_date|date:"d/m/Y"}}
9
Expiration date:    {{group.expiration_date|date:"d/m/Y"}}
10
Moderation:         {{group.moderation_enabled}}
11
Owner:              {{owner}}
12
Policies:
13
{% for p in policies %}
14
    {{p}}
15
{% endfor %}
16

  
17
Για την ενεργοποίησή του μπορείτε να χρησιμοποιήσετε το command line εργαλείο:
18
snf-manage group_update <group_id> --enable
19
--
20

  
21
The following account has been created:
22

  
23
Id:                 {{group.id}}}
24
Name:               {{group.name}}
25
Type:               {{group.kind}}
26
Issue date:         {{group.issue_date|date:"d/m/Y"}}
27
Expiration date:    {{group.expiration_date|date:"d/m/Y"}}
28
Moderation:         {{group.moderation_enabled}}
29
Owner:              {{owner}}
30
Policies:
31
{% for p in policies %}
32
    {{p}}
33
{% endfor %}
34

  
35
For its activation you can use the command line tool:
36
snf-manage group_update <group_id> --enable
b/snf-astakos-app/astakos/im/views.py
62 62
from astakos.im.util import get_context, prepare_response, set_cookie, get_query
63 63
from astakos.im.forms import *
64 64
from astakos.im.functions import send_greeting, send_feedback, SendMailError, \
65
    invite as invite_func, logout as auth_logout, activate as activate_func, switch_account_to_shibboleth
65
    invite as invite_func, logout as auth_logout, activate as activate_func, \
66
    switch_account_to_shibboleth, send_admin_notification, SendNotificationError
66 67
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, COOKIE_NAME, COOKIE_DOMAIN, IM_MODULES, SITENAME, LOGOUT_NEXT, LOGGING_LEVEL
67 68

  
68 69
logger = logging.getLogger(__name__)
......
455 456
        return index(request)
456 457
        
457 458
    try:
458
        local_user = AstakosUser.objects.get(~Q(id = user.id), email=user.email, is_active=True)
459
        local_user = AstakosUser.objects.get(
460
            ~Q(id = user.id),
461
            email=user.email,
462
            is_active=True
463
        )
459 464
    except AstakosUser.DoesNotExist:
460 465
        try:
461
            activate_func(user, greeting_email_template_name, helpdesk_email_template_name, verify_email=True)
466
            activate_func(
467
                user,
468
                greeting_email_template_name,
469
                helpdesk_email_template_name,
470
                verify_email=True
471
            )
462 472
            response = prepare_response(request, user, next, renew=True)
463 473
            transaction.commit()
464 474
            return response
......
475 485
            return index(request)
476 486
    else:
477 487
        try:
478
            user = switch_account_to_shibboleth(user, local_user, greeting_email_template_name)
488
            user = switch_account_to_shibboleth(
489
                user,
490
                local_user,
491
                greeting_email_template_name
492
            )
479 493
            response = prepare_response(request, user, next, renew=True)
480 494
            transaction.commit()
481 495
            return response
......
595 609
    except:
596 610
        return HttpResponseBadRequest(_('No such group kind'))
597 611
    
598
    template_name=None,
599 612
    template_loader=loader
600
    extra_context=None
601 613
    post_save_redirect='/im/group/%(id)s/'
602
    login_required=False
603 614
    context_processors=None
604 615
    model, form_class = get_model_and_form_class(
605 616
        model=None,
606 617
        form_class=AstakosGroupCreationForm
607 618
    )
608
    # TODO better approach???
609 619
    resources = dict( (str(r.id), r) for r in Resource.objects.select_related().all() )
620
    policies = []
610 621
    if request.method == 'POST':
611 622
        form = form_class(request.POST, request.FILES, resources=resources)
612 623
        if form.is_valid():
613 624
            new_object = form.save()
625
            
626
            # save owner
614 627
            new_object.owners = [request.user]
628
            
629
            # save quota policies
615 630
            for (rid, limit) in form.resources():
616 631
                try:
617 632
                    r = resources[rid]
618 633
                except KeyError, e:
619 634
                    logger.exception(e)
620
                    # Should I stay or should I go???
635
                    # TODO Should I stay or should I go???
621 636
                    continue
622 637
                else:
623 638
                    new_object.astakosgroupquota_set.create(
624 639
                        resource = r,
625 640
                        limit = limit
626 641
                    )
642
                policies.append('%s %d' % (r, limit))
627 643
            msg = _("The %(verbose_name)s was created successfully.") %\
628 644
                                    {"verbose_name": model._meta.verbose_name}
629 645
            messages.success(request, msg, fail_silently=True)
646
            
647
            # send notification
648
            try:
649
                send_admin_notification(
650
                    template_name='im/group_creation_notification.txt',
651
                    dictionary={
652
                        'group':new_object,
653
                        'owner':request.user,
654
                        'policies':policies,
655
                    },
656
                    subject='%s alpha2 testing group creation notification' % SITENAME
657
                )
658
            except SendNotificationError, e:
659
                messages.error(request, e, fail_silently=True)
630 660
            return redirect(post_save_redirect, new_object)
631 661
    else:
632 662
        now = datetime.now()

Also available in: Unified diff