From 0da0fa73a55ea943e16012eb4ab8ef8864c8a179 Mon Sep 17 00:00:00 2001 From: xiez Date: Sat, 5 May 2012 19:52:36 +0800 Subject: [PATCH 1/4] Fix bug in view repo as anonymous user, and clean code --- views.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/views.py b/views.py index 237626b221..fd8f2cfe8d 100644 --- a/views.py +++ b/views.py @@ -9,6 +9,7 @@ from django.views.decorators.csrf import csrf_protect from auth.forms import AuthenticationForm, PasswordResetForm, SetPasswordForm, PasswordChangeForm from auth.tokens import default_token_generator +from pysearpc import SearpcError from seaserv import cclient, ccnet_rpc, get_groups, get_users, get_repos, \ get_repo, get_commits, get_branches, \ seafserv_threaded_rpc, seafserv_rpc, get_binding_peerids, get_ccnetuser @@ -161,33 +162,36 @@ def validate_emailuser(email): return False -@login_required def repo(request, repo_id): - # if user is not staff and not owner and not fetch this repo + # get repo web access property, if no repo access property in db, then + # assume repo ap is 'own' + repo_ap = seafserv_threaded_rpc.repo_query_access_property(repo_id) + if repo_ap == None: + repo_ap = 'own' + + # if repo is 'own' and user is not staff and is not owner # and not shared this repo, then goto 404 page.. - if not validate_owner(request, repo_id) and not check_shared_repo(request, repo_id) \ - and not request.user.is_staff: + if cmp(repo_ap, 'own') == 0 and not validate_owner(request, repo_id) \ + and not check_shared_repo(request, repo_id) and not request.user.is_staff: raise Http404 repo = get_repo(repo_id) - + if repo == None: + raise Http404 + recent_commits = get_commits(repo_id, 0, 3) - token = "" is_owner = False - repo_ap = "" - if request.user.is_authenticated(): if validate_owner(request, repo_id): is_owner = True - token = seafserv_threaded_rpc.get_repo_token(repo_id) - repo_ap = seafserv_threaded_rpc.repo_query_access_property(repo_id) - repo_size = seafserv_threaded_rpc.server_repo_size(repo_id) + + repo_size = seafserv_threaded_rpc.server_repo_size(repo_id) dirs = [] if not repo.props.encrypted: if not request.GET.get('root_id'): - # ..use HEAD commit's root id + # use HEAD commit's root id commit = seafserv_rpc.get_commit(repo.props.head_cmmt_id) root_id = commit.props.root_id else: @@ -209,7 +213,6 @@ def repo(request, repo_id): "is_owner": is_owner, "repo_ap": repo_ap, "repo_size": repo_size, - "token": token, "dirs": dirs, }, context_instance=RequestContext(request)) @@ -371,7 +374,6 @@ def repo_list_dir(request, repo_id): }, context_instance=RequestContext(request)) -@login_required def repo_operation_file(request, op, repo_id, obj_id): if repo_id: # any person visit private repo, go to 404 page From c560463eb8df3bf747a133afd6ac4832ab1ab32b Mon Sep 17 00:00:00 2001 From: llj Date: Sat, 5 May 2012 20:35:08 +0800 Subject: [PATCH 2/4] improved repo; modified header --- media/css/seahub.css | 33 +++++++-------------- templates/base.html | 2 +- templates/repo.html | 68 +++++++++++++++++++++----------------------- views.py | 6 ++-- 4 files changed, 48 insertions(+), 61 deletions(-) diff --git a/media/css/seahub.css b/media/css/seahub.css index 11404f33ed..f29b3f213f 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -17,6 +17,7 @@ ul > li { list-style:none; } .label { color:#333; font-size:12px; font-style:normal; } a { color:#ee8833; text-decoration:none; font-weight:bold; } a:hover { color: #ff9933; text-decoration: underline; } +img { border:none; } /* table */ table { border-spacing: 0; border-collapse: collapse; width:100%; table-layout:fixed; margin:3px 0 5px; } td, th { padding: 3px; word-break:break-word; } @@ -44,7 +45,7 @@ tr.first { background-color: #00FF00; } #other-info { color: #ccc; text-align:right; } #other-info .wish { font-style:italic; margin-bottom:10px; } #other-info .version { font-size: 12px; } -#header .nav { border-bottom: 1px solid #ddd; } +#header .nav { border-bottom: 1px solid #ddd; margin-top:8px; } #header .nav li { float: left; height: 18px; padding: 0px 25px 4px 0; background: none; } #header .nav a, #header .nav a:visited { color:#8A948F; font-weight:bold; text-decoration:none; } #header .nav a.cur { color: #000; } @@ -55,13 +56,11 @@ tr.first { background-color: #00FF00; } h2 { font-size:18px; color:#808; margin-bottom:8px; } h3 { font-size:14px; color:#808; font-weight:normal; } ol { margin:0; padding:0px 0 0 2em; list-style-position:inside; } -ul { padding:0 0 0 0; margin: 8px 0 8px 0; } ul > li { background: url('../img/li.gif') no-repeat scroll; background-position:left 6px; padding-left:10px; } /* #main ul.ui-tabs-nav > li { background: none; } */ #main ol > li { } #main li { line-height:20px; } #main img.click { margin-left:2px; cursor:pointer; } - /* profile */ .avatar_op .pic { float:left; margin-right:15px; } .avatar_op .text { float:left; } @@ -198,38 +197,28 @@ input.ccnet_id { width: 400px; } margin-bottom: 12px; } /*repo page*/ +#repo-page h2 { + margin-bottom:16px; +} #repo-page .side { color:#333; - padding-top:33px; - width:230px; + width:260px; } #repo-page .main { - width:680px; + width:650px; } #repo-page .more { font-weight:normal; font-size:12px; color:#080; } -#repo-page h2 { - margin-bottom:12px; +.latest-commit { + word-wrap:break-word; } -#repo-page h3 { - margin-top:24px; -} -.recent-commit { - margin:0; -} -.recent-commit li { - padding:0; - background:none; - color:#222; -} -.recent-commit .author { +.latest-commit .author { font-style:italic; - margin-left:4px; } -.recent-commit .time { +.latest-commit .time { color:#666; margin-left:2px; } diff --git a/templates/base.html b/templates/base.html index 79139112e4..9cdec9fe71 100644 --- a/templates/base.html +++ b/templates/base.html @@ -36,7 +36,7 @@