1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 00:17:18 +00:00
seahub/api2/permissions.py

26 lines
660 B
Python
Raw Normal View History

2012-12-19 08:39:50 +00:00
"""
Provides a set of pluggable permission policies.
"""
from rest_framework.permissions import BasePermission
from seaserv import check_permission
2012-12-23 14:27:16 +00:00
SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS']
2012-12-19 08:39:50 +00:00
class IsRepoWritable(BasePermission):
"""
Allows access only for users who has write permission to the repo.
"""
def has_permission(self, request, view, obj=None):
2012-12-23 14:27:16 +00:00
if request.method in SAFE_METHODS:
return True
2012-12-19 08:39:50 +00:00
repo_id = view.kwargs.get('repo_id', '')
user = request.user.username if request.user else ''
if user and check_permission(repo_id, user) == 'rw':
return True
return False