1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-10 19:32:25 +00:00

view public repo on myhome page

This commit is contained in:
xiez 2012-03-29 15:36:15 +08:00
parent 43780a8551
commit 52591e4b71
6 changed files with 160 additions and 8 deletions

View File

@ -145,3 +145,6 @@ LOGIN_URL = SITE_ROOT + 'accounts/login'
# profile # profile
#AUTH_PROFILE_MODULE = "profile.UserProfile" #AUTH_PROFILE_MODULE = "profile.UserProfile"
# seafile httpserver address and port
HTTP_SERVER_ROOT = "http://localhost:8082"

View File

@ -24,7 +24,14 @@
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td> <td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td>
<td>{{ repo.props.id }}</td> <td>{{ repo.props.id }}</td>
<td>{{ repo.props.desc }}</td> <td>{{ repo.props.desc }}</td>
<td><button data="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/" class="repo-delete-btn">删除</button></td> <td>
{% if repo.is_public %}
<a href="{{ SITE_ROOT }}repo/dir/{{ repo.props.id }}/">查看目录</a>
{% else %}
查看目录
{% endif %}
<a href="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/">删除</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
@ -47,7 +54,14 @@
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td> <td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}">{{ repo.props.name }}</a></td>
<td>{{ repo.props.id }}</td> <td>{{ repo.props.id }}</td>
<td>{{ repo.props.desc }}</td> <td>{{ repo.props.desc }}</td>
<td><button data="{{ SITE_ROOT }}repo/removefetched/{{ user.username }}/{{ repo.props.id }}/" class="repo-delete-btn">删除</button></td> <td>
{% if repo.is_public %}
<a href="{{ SITE_ROOT }}repo/dir/{{ repo.props.id }}/">查看目录</a>
{% else %}
查看目录
{% endif %}
<button data="{{ SITE_ROOT }}repo/removefetched/{{ user.user_id }}/{{ repo.props.id }}/" class="repo-delete-btn">删除</button>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -36,6 +36,18 @@
<td>只有同步目录拥有者可见</td> <td>只有同步目录拥有者可见</td>
{% endif %} {% endif %}
</tr> </tr>
<tr>
<td>公共访问</td>
{% if is_owner %}
{% if is_public %}
<td><input type="checkbox" id="public-access-ckbx" checked>允许任何人查看该同步目录</td>
{% else %}
<td><input type="checkbox" id="public-access-ckbx">允许任何人查看该同步目录</td>
{% endif %}
{% else %}
<td>只有拥有者可选</td>
{% endif %}
</tr>
</table> </table>
</div> </div>
@ -98,5 +110,12 @@ $('#token-show-switch').click(function() {
} }
}); });
$('#tabs').tabs({cookie: {expires: 1}}); $('#tabs').tabs({cookie: {expires: 1}});
$("#public-access-ckbx").click(function() {
if($("#public-access-ckbx").get(0).checked) {
location.href = "{{ SITE_ROOT }}repo/setpublic/{{ repo.props.id }}/";
} else {
location.href = "{{ SITE_ROOT }}repo/unsetpublic/{{ repo.props.id }}/";
}
})
</script> </script>
{% endblock %} {% endblock %}

37
templates/repo_dir.html Normal file
View File

@ -0,0 +1,37 @@
{% extends "myhome_base.html" %}
{% block nav_home_class %}class="cur"{% endblock %}
{% block left_panel %}
<h3>已用空间</h3>
<p>{{ quota_usage|filesizeformat }} / 4 GB</p>
{% endblock %}
{% block right_panel %}
<h3>目录列表</h3>
{% if dirs %}
<table class="repo-list default">
<tr>
<th width="80%">名字</th>
<th width="20%">操作</th>
</tr>
{% for dirent in dirs %}
<tr>
{% if dirent.is_dir %}
<td><a href="{{ SITE_ROOT }}repo/dir/{{ repo_id }}/?root_id={{ dirent.props.obj_id }}">{{ dirent.props.obj_name }}</a></td>
<td></td>
{% else %}
<td>{{ dirent.props.obj_name }}</td>
<td><a href="{{ http_server_root }}/{{ repo_id }}?id={{ dirent.props.obj_id }}&filename={{ dirent.props.obj_name }}">下载</a></td>
{% endif %}
</tr>
{% endfor %}
</table>
{% else %}
<p>暂无</p>
{% endif %}
{% endblock %}

View File

@ -5,7 +5,8 @@ from django.views.generic.simple import direct_to_template
from seahub.views import root, peers, groups, myhome, \ from seahub.views import root, peers, groups, myhome, \
repo, group, modify_token, remove_repo, seafadmin, useradmin, \ repo, group, modify_token, remove_repo, seafadmin, useradmin, \
role_add, role_remove, activate_user, user_add, user_remove, \ role_add, role_remove, activate_user, user_add, user_remove, \
ownerhome, remove_fetched_repo, user_info ownerhome, remove_fetched_repo, repo_set_public, repo_unset_public, \
repo_list_dir
# Uncomment the next two lines to enable the admin: # Uncomment the next two lines to enable the admin:
#from django.contrib import admin #from django.contrib import admin
@ -31,7 +32,10 @@ urlpatterns = patterns('',
(r'^repo/(?P<repo_id>[^/]+)/$', repo), (r'^repo/(?P<repo_id>[^/]+)/$', repo),
(r'^repo/token/modify/(?P<repo_id>[^/]+)/$', modify_token), (r'^repo/token/modify/(?P<repo_id>[^/]+)/$', modify_token),
(r'^repo/remove/(?P<repo_id>[^/]+)/$', remove_repo), (r'^repo/remove/(?P<repo_id>[^/]+)/$', remove_repo),
(r'^repo/removefetched/(?P<username>[^/]+)/(?P<repo_id>[^/]+)/$', remove_fetched_repo), (r'^repo/removefetched/(?P<user_id>[^/]+)/(?P<repo_id>[^/]+)/$', remove_fetched_repo),
(r'^repo/setpublic/(?P<repo_id>[^/]+)/$', repo_set_public),
(r'^repo/unsetpublic/(?P<repo_id>[^/]+)/$', repo_unset_public),
(r'^repo/dir/(?P<repo_id>[^/]+)/$', repo_list_dir),
(r'^seafadmin/$', seafadmin), (r'^seafadmin/$', seafadmin),
url(r'^useradmin/$', useradmin, name='useradmin'), url(r'^useradmin/$', useradmin, name='useradmin'),

View File

@ -10,13 +10,16 @@ from auth.forms import AuthenticationForm, PasswordResetForm, SetPasswordForm, P
from seaserv import cclient, ccnet_rpc, get_groups, get_users, get_repos, \ from seaserv import cclient, ccnet_rpc, get_groups, get_users, get_repos, \
get_repo, get_commits, get_branches, \ get_repo, get_commits, get_branches, \
seafserv_threaded_rpc, get_binding_userids, get_ccnetuser seafserv_threaded_rpc, seafserv_rpc, get_binding_userids, get_ccnetuser
from seahub.share.models import GroupShare, UserShare from seahub.share.models import GroupShare, UserShare
from seahub.share.forms import GroupAddRepoForm from seahub.share.forms import GroupAddRepoForm
from seahub.base.accounts import CcnetUser from seahub.base.accounts import CcnetUser
from forms import AddUserForm from forms import AddUserForm
import stat
import time
import settings
@login_required @login_required
def root(request): def root(request):
@ -123,9 +126,15 @@ def repo(request, repo_id):
token = "" token = ""
is_owner = False is_owner = False
if request.user.is_authenticated() and validate_owner(request, repo_id):
if request.user.is_authenticated():
if validate_owner(request, repo_id):
is_owner = True is_owner = True
token = seafserv_threaded_rpc.get_repo_token(repo_id) token = seafserv_threaded_rpc.get_repo_token(repo_id)
if seafserv_threaded_rpc.repo_is_public(repo_id) > 0:
is_public = True
else:
is_public = False
return render_to_response('repo.html', { return render_to_response('repo.html', {
"repo": repo, "repo": repo,
@ -137,6 +146,7 @@ def repo(request, repo_id):
'page_next': page_next, 'page_next': page_next,
"branches": branches, "branches": branches,
"is_owner": is_owner, "is_owner": is_owner,
"is_public": is_public,
"token": token, "token": token,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@ -195,6 +205,18 @@ def myhome(request):
except: except:
pass pass
for repo in owned_repos:
if seafserv_threaded_rpc.repo_is_public(repo.props.id):
repo.is_public = True
else:
repo.is_public = False
for repo in fetched_repos:
if seafserv_threaded_rpc.repo_is_public(repo.props.id):
repo.is_public = True
else:
repo.is_public = False
return render_to_response('myhome.html', { return render_to_response('myhome.html', {
"owned_repos": owned_repos, "owned_repos": owned_repos,
"quota_usage": quota_usage, "quota_usage": quota_usage,
@ -224,6 +246,59 @@ def ownerhome(request, owner_name):
"owner": owner_name, "owner": owner_name,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@login_required
def repo_set_public(request, repo_id):
if repo_id:
seafserv_threaded_rpc.repo_set_public(repo_id)
return HttpResponseRedirect(request.META['HTTP_REFERER'])
@login_required
def repo_unset_public(request, repo_id):
if repo_id:
seafserv_threaded_rpc.repo_unset_public(repo_id)
return HttpResponseRedirect(request.META['HTTP_REFERER'])
@login_required
def repo_list_dir(request, repo_id):
if repo_id:
# Not public repo, go to 404 page
if not seafserv_threaded_rpc.repo_is_public(repo_id):
raise Http404
repo = seafserv_threaded_rpc.get_repo(repo_id)
if not request.GET.get('root_id'): # No root id..?
# ..use HEAD commit's root id
commit = seafserv_threaded_rpc.get_commit(repo.props.head_cmmt_id)
root_id = commit.props.root_id
else:
root_id = request.GET.get('root_id')
dirs = seafserv_threaded_rpc.list_dir(root_id)
for dirent in dirs:
if stat.S_ISDIR(dirent.props.mode):
dirent.is_dir = True
else:
dirent.is_dir = False
# Get user quota usage
user_id = request.user.user_id
if user_id:
quota_usage = seafserv_threaded_rpc.get_user_quota_usage(user_id)
# Get seafile http server address and port from settings.py,
# and cut out last '/'
if settings.HTTP_SERVER_ROOT[-1] == '/':
http_server_root = settings.HTTP_SERVER_ROOT[:-1]
else:
http_server_root = settings.HTTP_SERVER_ROOT
return render_to_response('repo_dir.html', {
"repo_id": repo_id,
"dirs": dirs,
"quota_usage": quota_usage,
"http_server_root": http_server_root,
},
context_instance=RequestContext(request))
@login_required @login_required
def mypeers(request): def mypeers(request):