Commit 5f81dd45 authored by Olga Brani's avatar Olga Brani
Browse files

Merge branch '0.6.4' of https://code.grnet.gr/git/astakos into 0.6.4

Conflicts:
	snf-astakos-app/astakos/im/forms.py
parents 37f14d83 a50d21c8
......@@ -108,11 +108,4 @@ showuser Show user info
To update user credibility from the billing system (Aquarium), enable the queue, install snf-pithos-tools and use ``pithos-dispatcher``::
pithos-dispatcher --exchange=aquarium --callback=astakos.im.endpoints.aquarium.consumer.on_creditevent
Load groups:
------------
To set the initial user groups load the followind fixture:
snf-manage loaddata groups
pithos-dispatcher --exchange=aquarium --callback=astakos.im.endpoints.aquarium.consumer.on_creditevent
\ No newline at end of file
......@@ -98,7 +98,7 @@ def authenticate_old(request, user=None):
if (time() - mktime(user.auth_token_expires.timetuple())) > 0:
raise Unauthorized('Authentication expired')
if not user.signed_terms():
if not user.signed_terms:
raise Unauthorized('Pending approval terms')
response = HttpResponse()
......@@ -109,7 +109,7 @@ def authenticate_old(request, user=None):
'auth_token_created':user.auth_token_created.isoformat(),
'auth_token_expires':user.auth_token_expires.isoformat(),
'has_credits':user.has_credits,
'has_signed_terms':user.signed_terms(),
'has_signed_terms':user.signed_terms,
'groups':[g.name for g in user.groups.all()]}
response.content = json.dumps(user_info)
response['Content-Type'] = 'application/json; charset=UTF-8'
......@@ -133,7 +133,7 @@ def authenticate(request, user=None):
if (time() - mktime(user.auth_token_expires.timetuple())) > 0:
raise Unauthorized('Authentication expired')
if not user.signed_terms():
if not user.signed_terms:
raise Unauthorized('Pending approval terms')
response = HttpResponse()
......
......@@ -43,7 +43,7 @@ if QUEUE_CONNECTION:
exchange_close, UserEvent, Receipt
)
QUEUE_CLIENT_ID = 3 # Astakos.
QUEUE_CLIENT_ID = '3' # Astakos.
INSTANCE_ID = '1'
RESOURCE = 'addcredits'
DEFAULT_CREDITS = 1000
......
......@@ -500,6 +500,7 @@ class AstakosGroupCreationForm(forms.ModelForm):
widget=forms.HiddenInput()
)
name = forms.URLField()
homepage = forms.URLField()
moderation_enabled = forms.BooleanField(
help_text="Check if you want to approve members participation manually",
required=False
......
......@@ -84,7 +84,7 @@ class Command(BaseCommand):
'resources' : user.quota
}
if get_latest_terms():
has_signed_terms = user.signed_terms()
has_signed_terms = user.signed_terms
kv['has_signed_terms'] = format_bool(has_signed_terms)
if has_signed_terms:
kv['date_signed_terms'] = format_date(user.date_signed_terms)
......
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'AstakosGroup.homepage'
db.add_column('im_astakosgroup', 'homepage', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), keep_default=False)
def backwards(self, orm):
# Deleting field 'AstakosGroup.homepage'
db.delete_column('im_astakosgroup', 'homepage')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'im.additionalmail': {
'Meta': {'object_name': 'AdditionalMail'},
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
},
'im.approvalterms': {
'Meta': {'object_name': 'ApprovalTerms'},
'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 9, 6, 16, 11, 52, 429294)', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
'im.astakosgroup': {
'Meta': {'object_name': 'AstakosGroup', '_ormbases': ['auth.Group']},
'approval_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 9, 6, 16, 11, 52, 423356)'}),
'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'estimated_participants': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
'expiration_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'group_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.Group']", 'unique': 'True', 'primary_key': 'True'}),
'homepage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'issue_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'kind': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.GroupKind']"}),
'moderation_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'policy': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosGroupQuota']", 'blank': 'True'})
},
'im.astakosgroupquota': {
'Meta': {'unique_together': "(('resource', 'group'),)", 'object_name': 'AstakosGroupQuota'},
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosGroup']", 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'limit': ('django.db.models.fields.PositiveIntegerField', [], {}),
'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"})
},
'im.astakosuser': {
'Meta': {'unique_together': "(('provider', 'third_party_identifier'),)", 'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'astakos_groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.AstakosGroup']", 'symmetrical': 'False', 'through': "orm['im.Membership']", 'blank': 'True'}),
'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'invitations': ('django.db.models.fields.IntegerField', [], {'default': '100'}),
'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'level': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'owner': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'owner'", 'null': 'True', 'to': "orm['im.AstakosGroup']"}),
'policy': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosUserQuota']", 'symmetrical': 'False'}),
'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'updated': ('django.db.models.fields.DateTimeField', [], {}),
'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
},
'im.astakosuserquota': {
'Meta': {'unique_together': "(('resource', 'user'),)", 'object_name': 'AstakosUserQuota'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'limit': ('django.db.models.fields.PositiveIntegerField', [], {}),
'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
},
'im.emailchange': {
'Meta': {'object_name': 'EmailChange'},
'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 9, 6, 16, 11, 52, 430810)'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchange_user'", 'unique': 'True', 'to': "orm['im.AstakosUser']"})
},
'im.groupkind': {
'Meta': {'object_name': 'GroupKind'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'})
},
'im.invitation': {
'Meta': {'object_name': 'Invitation'},
'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
'consumed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}),
'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
},
'im.membership': {
'Meta': {'unique_together': "(('person', 'group'),)", 'object_name': 'Membership'},
'date_joined': ('django.db.models.fields.DateField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
'date_requested': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2012, 9, 6, 16, 11, 52, 427324)', 'blank': 'True'}),
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosGroup']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
},
'im.resource': {
'Meta': {'object_name': 'Resource'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'meta': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.ResourceMetadata']", 'symmetrical': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Service']"})
},
'im.resourcemetadata': {
'Meta': {'object_name': 'ResourceMetadata'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
'value': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
'im.service': {
'Meta': {'object_name': 'Service'},
'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'icon': ('django.db.models.fields.FilePathField', [], {'max_length': '100', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
'url': ('django.db.models.fields.FilePathField', [], {'max_length': '100'})
}
}
complete_apps = ['im']
......@@ -109,6 +109,7 @@ class GroupKind(models.Model):
class AstakosGroup(Group):
kind = models.ForeignKey(GroupKind)
homepage = models.CharField('Homepage', max_length=255, null=True, blank=True)
desc = models.TextField('Description', null=True)
policy = models.ManyToManyField(Resource, null=True, blank=True,
through='AstakosGroupQuota'
......@@ -149,10 +150,6 @@ class AstakosGroup(Group):
return False
return True
# @property
# def participants(self):
# return len(self.approved_members)
def enable(self):
if self.is_enabled:
return
......@@ -351,6 +348,7 @@ class AstakosUser(User):
if q.count() != 0:
raise ValidationError({'__all__':[_('Another account with the same email & is_active combination found.')]})
@property
def signed_terms(self):
term = get_latest_terms()
if not term:
......
......@@ -68,7 +68,7 @@ def login(request):
if request.user.is_authenticated():
# if user has not signed the approval terms
# redirect to approval terms with next the request path
if not request.user.signed_terms():
if not request.user.signed_terms:
# first build next parameter
parts = list(urlsplit(request.build_absolute_uri()))
params = dict(parse_qsl(parts[3], keep_blank_values=True))
......
......@@ -19,6 +19,8 @@
<dl class="alt-style">
<dt>Name</dt>
<dd>{{object.name}}&nbsp;</dd>
<dt>Homepage</dt>
<dd>{{object.homepage}}&nbsp;</dd>
<dt>Type</dt>
<dd>{{object.kind|capfirst}}&nbsp;</dd>
<dt>Issue date:</dt>
......
......@@ -32,9 +32,10 @@
</ul>
{% endif %}
{% with object_list|enabled:is_search as object_list %}
{% if object_list %}
{% with object_list|filter_groups:user as d %}
{% with d|lookup:'mine' as mine %}
{% with object_list|split:user as d %}
{% with d|lookup:'own' as mine %}
{% if mine %}
<div class="full-dotted">
<table class="alt-style table_sorting" id="">
......@@ -131,6 +132,7 @@
{% if is_search %}
<h2>No groups found!</h2>
{% endif %}
{% endif %}
{% endif %}
{% endwith %}
</div>
{% endblock %}
......@@ -44,11 +44,17 @@ def dkeys(d):
return d.keys()
@register.filter
def filter_groups(object_list, user):
def enabled(object_list, is_search):
if not is_search:
return object_list
return [g for g in object_list if g.is_enabled]
@register.filter
def split(object_list, user):
try:
d = {}
d['mine'] = filter(lambda o: user in o.owner.all(), object_list)
d['other'] = list(set(object_list) - set(d['mine']))
d['own'] = [g for g in object_list if user in g.owner.all()]
d['other'] = list(set(object_list) - set(d['own']))
return d
except:
return {'mine':object_list, 'other':[]}
return {'own':object_list, 'other':()}
\ No newline at end of file
......@@ -105,7 +105,7 @@ def prepare_response(request, user, next='', renew=False):
or user has not a valid token.
"""
renew = renew or (not user.auth_token)
renew = renew or (user.auth_token_expires and user.auth_token_expires < datetime.datetime.now())
renew = renew or (user.auth_token_expires < datetime.datetime.now())
if renew:
user.renew_token()
try:
......@@ -138,9 +138,13 @@ def set_cookie(response, user):
expire_fmt = user.auth_token_expires.strftime('%a, %d-%b-%Y %H:%M:%S %Z')
cookie_value = quote(user.email + '|' + user.auth_token)
response.set_cookie(COOKIE_NAME, value=cookie_value,
expires=expire_fmt, path='/',
domain=COOKIE_DOMAIN, secure=COOKIE_SECURE)
msg = 'Cookie [expiring %s] set for %s' % (user.auth_token_expires, user.email)
expires=expire_fmt, path='/',
domain=COOKIE_DOMAIN, secure=COOKIE_SECURE
)
msg = 'Cookie [expiring %s] set for %s' % (
user.auth_token_expires,
user.email
)
logger.log(LOGGING_LEVEL, msg)
class lazy_string(object):
......@@ -161,4 +165,7 @@ def reserved_email(email):
return AstakosUser.objects.filter(email = email).count() != 0
def get_query(request):
return request.__getattribute__(request.method)
\ No newline at end of file
try:
return request.__getattribute__(request.method)
except AttributeError:
return request.GET
\ No newline at end of file
......@@ -113,7 +113,7 @@ def signed_terms_required(func):
"""
@wraps(func)
def wrapper(request, *args, **kwargs):
if request.user.is_authenticated() and not request.user.signed_terms():
if request.user.is_authenticated() and not request.user.signed_terms:
params = urlencode({'next': request.build_absolute_uri(),
'show_form':''})
terms_uri = reverse('latest_terms') + '?' + params
......@@ -545,7 +545,7 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html'
return HttpResponseRedirect(next)
else:
form = None
if request.user.is_authenticated() and not request.user.signed_terms():
if request.user.is_authenticated() and not request.user.signed_terms:
form = SignApprovalTermsForm(instance=request.user)
return render_response(template_name,
terms = terms,
......@@ -687,7 +687,11 @@ def group_add(request, kind_name='default'):
@login_required
def group_list(request):
list = request.user.astakos_groups.select_related().all()
return object_list(request, queryset=list)
return object_list(request, queryset=list,
extra_context=dict(
is_search=False
)
)
@signed_terms_required
@login_required
......@@ -716,8 +720,7 @@ def group_search(request, extra_context=None, **kwargs):
form = AstakosGroupSearchForm(get_query(request))
if form.is_valid():
q = form.cleaned_data['q'].strip()
q = URLField().to_python(q)
queryset = AstakosGroup.objects.select_related().filter(name=q)
queryset = AstakosGroup.objects.select_related().filter(name__contains=q)
return object_list(
request,
queryset,
......
......@@ -78,7 +78,7 @@ INSTALL_REQUIRES = [
'South>=0.7, <=0.7.3',
'httplib2>=0.6.0',
'snf-common>=0.9.0',
'django-recaptcha',
'recaptcha-client>=1.0.5',
'django-ratelimit==0.1',
'commissioning',
'celery',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment