diff --git a/k4ever/api2/decorators.py b/k4ever/api2/decorators.py
index e90c59f..9d60333 100644
--- a/k4ever/api2/decorators.py
+++ b/k4ever/api2/decorators.py
@@ -73,8 +73,9 @@ def requirePlugin(apiFunc):
if request.user:
group = request.user.groups.get(name="Plugin")
# no exception, exec apiFunc!
+ request.plugin = Plugin.objects.get(user=request.user)
return apiFunc(self, request, *args, **kwargs)
- except Groups.DoesNotExist:
+ except Group.DoesNotExist:
pass
ret = rc.FORBIDDEN
diff --git a/k4ever/api2/handlers.py b/k4ever/api2/handlers.py
index 0baf20d..fe2c79c 100644
--- a/k4ever/api2/handlers.py
+++ b/k4ever/api2/handlers.py
@@ -136,6 +136,26 @@ class AuthBlobHandler(BaseHandler):
# model =
pass
+class AuthUserHandler(BaseHandler):
+ allowed_methods = ('GET')
+ fields = ('id', 'username')
+
+ @requirePlugin
+ def read(self, request):
+ if not request.plugin.uniqueAuthblob:
+ ret = rc.BAD_REQUEST
+ ret.write("\nThis plugin does not support unique auth blobs, therefore we can't identify an user uniquely by its authblob\n")
+ return ret
+
+ if not request.GET.has_key('authblob'):
+ return rc.BAD_REQUEST
+
+ try:
+ perm = PluginPermission.objects.get(plugin=request.plugin, authblob=request.GET['authblob'])
+ return perm.user
+ except PluginPermission.DoesNotExist:
+ return rc.NOT_FOUND
+
class ConfigHandler(BaseHandler):
allowed_methods = ('GET',)
diff --git a/k4ever/api2/urls.py b/k4ever/api2/urls.py
index 52ea539..c61a026 100644
--- a/k4ever/api2/urls.py
+++ b/k4ever/api2/urls.py
@@ -22,6 +22,7 @@ accountBalanceRes = CsrfExemptResource(handler=AccountBalanceHandler, **ad)
authBlobRes = CsrfExemptResource(handler=AuthBlobHandler, **ad)
+authUserRes = CsrfExemptResource(handler=AuthUserHandler, **ad)
configRes = CsrfExemptResource(handler=ConfigHandler, **ad)
@@ -37,6 +38,7 @@ urlpatterns = patterns('',
url(r'account/balance/?$', accountBalanceRes),
url(r'auth/blob/?$', authBlobRes),
+ url(r'auth/user/?$', authUserRes),
url(r'config/?$', configRes),
)
diff --git a/k4ever/main/models.py b/k4ever/main/models.py
index 27f20be..107363e 100644
--- a/k4ever/main/models.py
+++ b/k4ever/main/models.py
@@ -19,12 +19,21 @@ def createUserProfile(sender, instance, created, **kwargs):
post_save.connect(createUserProfile, sender=User)
class Plugin(models.Model):
- name = models.CharField(max_length=40)
user = models.ForeignKey(User, unique=True)
+
+ # plugin info
+ name = models.CharField(max_length=40)
author = models.CharField(max_length=40)
version = models.CharField(max_length=40)
descr = models.TextField(default='')
+
+ # plugin config
uniqueAuthblob = models.BooleanField(default=False)
+ userCanWriteAuthblob = models.BooleanField(default=True)
+ # automatically set when write is allowed
+ userCanReadAuthblob = models.BooleanField(default=True)
+ pluginCanWriteAuthblob = models.BooleanField(default=False)
+ pluginCanReadAuthblob = models.BooleanField(default=False)
def __unicode__(self):
return self.name
@@ -32,7 +41,7 @@ class Plugin(models.Model):
class PluginPermission(models.Model):
user = models.ForeignKey(User)
plugin = models.ForeignKey('Plugin')
- authBlob = models.TextField(default='')
+ authblob = models.TextField(default='')
def __unicode__(self):
return "%s allows %s" % (self.user, self.plugin)
diff --git a/k4ever/main/templates/main/startpage.html b/k4ever/main/templates/main/startpage.html
index 33d9986..e327d96 100644
--- a/k4ever/main/templates/main/startpage.html
+++ b/k4ever/main/templates/main/startpage.html
@@ -4,7 +4,7 @@
{% if allMost %}
Am beliebtesten ist:
{% for buyable in allMost %}
- {{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal)
+ {{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal)
{% endfor %}
{% else %}
@@ -15,7 +15,7 @@
{% if usersMost %}
Am oeftesten hattest du:
{% for buyable in usersMost %}
- {{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal)
+ {{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal)
{% endfor %}
{% else %}
@@ -26,7 +26,7 @@
{% if usersLast %}
Als letztes hattest du:
{% for buyable in usersLast %}
- {{ buyable.buyable__name }}
+ {{ buyable.buyable__name }}
{% endfor %}
{% else %}
diff --git a/k4ever/main/templates/settings/settings.html b/k4ever/main/templates/settings/settings.html
index 0206990..2559542 100644
--- a/k4ever/main/templates/settings/settings.html
+++ b/k4ever/main/templates/settings/settings.html
@@ -9,89 +9,57 @@
-
- + {% if pluginerror %} + {{ pluginerror|safe }} + {% endif %} + {% if pluginmsg %} + {{ pluginmsg|safe }} + {% endif %}
Name | +Author | +Version | +Beschreibung | AuthBlob | -Optionen | +Erlauben/Verbieten | |||
---|---|---|---|---|---|---|---|---|---|
{{ p.plugin.name }} | +{{ p.plugin.author }} | +{{ p.plugin.version }} | +{{ p.plugin.descr }} | ++ {% if p.plugin.userCanWriteAuthblob %} + + {% else %} + {% if p.plugin.userCanReadAuthblob %} + {{ p.authblob }} + {% else %} + --- + {% endif %} {% endif %} - | |||||
{{ pperm.plugin }} | -- - | -- - | - | ||||||
Du hast bisher keinem Plugin zugriff auf deinen Account gewährt | -
-
Name | -AuthBlob | -Optionen | -|||||||
---|---|---|---|---|---|---|---|---|---|
{{ plugin }} | -- {%if plugin not in unallowedplugins %} - - {%endif%} - | -- - | - | ||||||
Du hast bisher keinem Plugin zugriff auf deinen Account gewährt | -Plugin verbieten | + + {% endfor %} + {% for plugin in unallowed %} +||||||||
{{ plugin.name }} | +{{ plugin.author }} | +{{ plugin.version }} | +{{ plugin.descr }} | ++ | Plugin erlauben | +