diff --git a/templates/repo.html b/templates/repo.html
index 11d90472c5..1d3acdd97f 100644
--- a/templates/repo.html
+++ b/templates/repo.html
@@ -108,17 +108,20 @@
|
- {% if user_perm == 'rw' %}
+ {% if user_perm %}
- {% endif %}
+ {% endif %}
|
{% endfor %}
diff --git a/urls.py b/urls.py
index bf9822a981..9fccd6eac3 100644
--- a/urls.py
+++ b/urls.py
@@ -40,6 +40,7 @@ urlpatterns = patterns('',
url(r'^repo/revert_file/(?P[^/]+)/$', repo_revert_file, name='repo_revert_file'),
url(r'^repo/revert_dir/(?P[^/]+)/$', repo_revert_dir, name='repo_revert_dir'),
url(r'^repo/star_file/(?P[^/]+)/$', repo_star_file, name='repo_star_file'),
+ url(r'^repo/download_dir/(?P[^/]+)/$', repo_download_dir, name='repo_download_dir'),
(r'^repo/upload_error/(?P[^/]+)/$', upload_file_error),
(r'^repo/update_error/(?P[^/]+)/$', update_file_error),
url(r'^repo/file_revisions/(?P[^/]+)/$', file_revisions, name='file_revisions'),
diff --git a/views.py b/views.py
index d9cf1aea19..d750520556 100644
--- a/views.py
+++ b/views.py
@@ -2628,3 +2628,36 @@ def repo_star_file(request, repo_id):
else:
unstar_file(request.user.username, repo_id, path)
return HttpResponse(json.dumps({'success':True}), content_type=content_type)
+
+@login_required
+def repo_download_dir(request, repo_id):
+ repo = get_repo(repo_id)
+ if not repo:
+ return render_error(request, _(u'Library not exists'))
+
+ try:
+ parent_dir = request.GET['parent']
+ dirname = request.GET['dirname']
+ except KeyError:
+ return render_error(request, _(u'Invalid arguments'))
+
+ path = os.path.join(parent_dir, dirname.rstrip('/'))
+
+ permission = get_user_permission(request, repo_id)
+ if permission:
+ dir_id = seafserv_threaded_rpc.get_dirid_by_path (repo.head_cmmt_id,
+ path.encode('utf-8'))
+ token = seafserv_rpc.web_get_access_token(repo_id,
+ dir_id,
+ 'download-dir',
+ request.user.username)
+ else:
+ return render_permission_error(request, _(u'Unable to access file'))
+
+ if len(path) > 1:
+ filename = os.path.basename(path)
+ else:
+ filename = repo.name
+ url = gen_file_get_url(token, filename)
+
+ return redirect(url)