1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-10 08:55:02 +00:00

User seafserv_rpc instead of seafile_rpc and add repo management for staff

This commit is contained in:
plt 2012-01-29 13:05:35 +08:00
parent 56275225aa
commit 14308b7f7b
9 changed files with 207 additions and 113 deletions

View File

@ -2,6 +2,7 @@
from seahub.profile.models import UserProfile
class UseridMiddleware(object):
"""Store ccnet user id in request.user.user_id"""
def process_request(self, request):
if not request.user.is_authenticated():

View File

@ -144,4 +144,4 @@ strong { color:#808; font-weight: normal; }
div.home-page h2 { font-style: italic; }
/* help pages */
.help-page { width: 550px; }
.help-page img { display: block; margin-left: auto; margin: 20px auto; }
.help-page img { display: block; margin: 20px auto; }

View File

@ -4,6 +4,11 @@
<li>
<a href="{{ SITE_ROOT }}home/my/">我的页面</a>
</li>
{% if request.user.is_staff %}
<li>
<a href="{{ SITE_ROOT }}seafadmin/">中继管理</a>
</li>
{% endif %}
<li>
<a href="{{ SITE_ROOT }}help/">使用帮助</a>
</li>

View File

@ -30,12 +30,12 @@
</tr>
</table>
<h3>分支</h3>
<h3>版本</h3>
<table class="branch-list default">
<tr>
<th>分支</th>
<th>Head Commit</th>
<th>版本</th>
<th>最新提交记录</th>
</tr>
{% for branch in branches %}
<tr>
@ -45,12 +45,12 @@
{% endfor %}
</table>
<h3>Commits</h3>
<h3>提交记录</h3>
<table class="commit-list default">
<tr>
<th>ID</th>
<th>Time</th>
<th>Discription</th>
<th>时间</th>
<th>描述</th>
</tr>
{% for commit in commits %}
<tr>

View File

@ -1,18 +1,21 @@
{% extends "base.html" %}
{% extends "myhome_base.html" %}
{% block right_panel %}
<h2>所有文件盒</h2>
<table class="repo-list default">
<tr>
<th>Name</th>
<th>名字</th>
<th>ID</th>
<th>Discription</th>
<th>描述</th>
<th>操作</th>
</tr>
{% for repo in repos %}
<tr>
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}/">{{ repo.props.name }}</a></td>
<td>{{ repo.props.id }}</td>
<td>{{ repo.props.desc }}</td>
<td><a href="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/">删除</a></td>
</tr>
{% endfor %}
</table>

View File

@ -1,18 +1,17 @@
import service
from service import cclient, ccnet_rpc, seamsg_rpc, seafile_rpc, monitor_rpc
from service import cclient, ccnet_rpc, monitor_rpc, seafserv_rpc
from service import translate_peerid, translate_msgtime, translate_groupid, \
translate_userid, translate_msgtime2, translate_time_sec, \
translate_time_usec, get_peer_avatar_url, get_user_avatar_url
translate_time_usec, get_peer_avatar_url, get_user_avatar_url, \
translate_userid_simple, translate_peerid_simple
from service import get_peers_by_role, get_peers_by_myrole, send_command
from service import get_groups, get_group
from service import get_users, get_user, get_events, count_event
from service import get_message, get_user_messages, get_group_messages, \
get_messages, count_message, count_user_message, count_group_message
from service import get_repos, get_repo, get_repo_sinfo, get_commits, \
get_branches, get_commit_tree_block_number, \
get_upload_task_list, get_download_task_list, list_share_info, open_dir, \
checkout, get_repo_status
checkout, get_repo_status, get_diff, list_dir
from service import CCNET_CONF_PATH

View File

@ -44,20 +44,28 @@ Repo:
name: Repo Name
desc: Repo description
worktree: The full path of the worktree of the repo
worktree_changed: True if the worktree is changed
worktree_checktime: The last check time of whether worktree is changed
head_branch: The name of the head branch
enctrypted: True if the repo is encrypted
passwd: The password
Branch:
name:
commit_id:
repo_id:
ShareItem:
Commit:
id:
creator_name:
creator: The id of the creator
desc:
ctime:
repo_id:
group_id:
user_id:
timestamp:
root_id:
parent_id:
second_parent_id:
SyncInfo:
@ -74,14 +82,13 @@ import json
import os
import sys
from pysearpc import SearpcError
import ccnet
import seamsg
import seafile
from pysearpc import SearpcError
if sys.platform == 'win32':
DEFAULT_CCNET_CONF_PATH = "C:\\ccnet"
else:
if 'win' in sys.platform:
DEFAULT_CCNET_CONF_PATH = "~/ccnet"
else:
DEFAULT_CCNET_CONF_PATH = "~/.ccnet"
if 'CCNET_CONF_DIR' in os.environ:
@ -89,9 +96,11 @@ if 'CCNET_CONF_DIR' in os.environ:
else:
CCNET_CONF_PATH = DEFAULT_CCNET_CONF_PATH
CCNET_CONF_PATH = os.path.expanduser(CCNET_CONF_PATH)
print "Load config from " + CCNET_CONF_PATH
CCNET_CONF_PATH = os.path.normpath(os.path.expanduser(CCNET_CONF_PATH))
# this is not connect daemon, used for the web to display
# This does not connect daemon, used for the web to display
# (name, id) info
cclient = ccnet.Client()
@ -103,9 +112,8 @@ else:
pool = ccnet.ClientPool(CCNET_CONF_PATH)
ccnet_rpc = ccnet.CcnetRpcClient(pool)
seamsg_rpc = seamsg.RpcClient(pool)
seafile_rpc = seafile.RpcClient(pool)
monitor_rpc = seafile.MonitorRpcClient(pool)
seafserv_rpc = seafile.ServerRpcClient(pool)
user_db = {}
@ -123,6 +131,22 @@ def translate_userid(user_id):
else:
return user_id[:8]
def translate_userid_simple(user_id):
try:
user = user_db[user_id]
except:
user = ccnet_rpc.get_user(user_id)
if user:
user_db[user_id] = user
else:
return user_id[:8]
if user.props.name:
return user.props.name
else:
return user_id[:8]
peer_db = {}
def translate_peerid(peer_id):
@ -135,7 +159,22 @@ def translate_peerid(peer_id):
else:
return peer_id[:8]
if peer.props.name:
return peer.props.name + "(" + peer_id[:4] + ")"
return peer.props.name
else:
return peer_id[:8]
def translate_peerid_simple(peer_id):
try:
peer = peer_db[peer_id]
except:
peer = ccnet_rpc.get_peer(peer_id)
if peer:
peer_db[peer_id] = peer
else:
return peer_id[:8]
if peer.props.name:
return peer.props.name
else:
return peer_id[:8]
@ -303,103 +342,133 @@ def send_command(command):
pool.return_client(client)
return ret
######## seamsg API #####
def get_message(msgid):
return seamsg_rpc.get_message_by_id(msgid)
def get_user_messages(user, offset, limit):
"""Get messages sent to or received from `user`.
For example:
get_user_message('eb812fd276432eff33bcdde7506f896eb4769da0', 0, 10)
fetches the lastest 10 messages from the given user.
:param user: user ID.
:param offset: offset of the first message.
:param limit: only fetch `limit` messages.
"""
return seamsg_rpc.get_user_messages(user, offset, limit)
def get_group_messages(group, offset, limit):
"""Get messages of `group`."""
return seamsg_rpc.get_group_messages(group, offset, limit)
def get_messages(offset, limit):
"""Get messages start at `offset`."""
return seamsg_rpc.get_messages(offset, limit)
def count_message():
return seamsg_rpc.count_message()
def count_user_message(user):
return seamsg_rpc.count_user_message(user)
def count_group_message(group):
return seamsg_rpc.count_group_message(group)
######## seafile API ####
######## seafserv API ####
def get_repos():
"""
Return repository list.
"""
return seafile_rpc.get_repo_list("", 100)
return seafserv_rpc.get_repo_list("", 100)
def get_repo(repo_id):
return seafile_rpc.get_repo(repo_id)
return seafserv_rpc.get_repo(repo_id)
def get_repo_sinfo(repo_id):
return seafile_rpc.get_repo_sinfo(repo_id)
return seafserv_rpc.get_repo_sinfo(repo_id)
def get_commits(repo_id):
return seafile_rpc.get_commit_list(repo_id, "", 100)
def get_commits(repo_id, offset, limit):
"""Get commit lists."""
return seafserv_rpc.get_commit_list(repo_id, offset, limit)
def get_commit_tree_block_number(commit_id):
return seafile_rpc.get_commit_tree_block_number(commit_id);
return seafserv_rpc.get_commit_tree_block_number(commit_id);
def checkout(repo_id, commit_id):
return seafile_rpc.checkout(repo_id, commit_id)
return seafile_threaded_rpc.checkout(repo_id, commit_id)
def get_upload_task_list():
return seafile_rpc.get_upload_task_list()
return seafserv_rpc.get_upload_task_list()
def get_download_task_list():
return seafile_rpc.get_download_task_list()
return seafserv_rpc.get_download_task_list()
def get_branches(repo_id):
"""Get branches of a given repo"""
return seafile_rpc.branch_gets(repo_id)
return seafserv_rpc.branch_gets(repo_id)
def list_share_info():
return seafile_rpc.list_share_info(0, 100)
return seafserv_rpc.list_share_info(0, 100)
def get_filename(start, ent):
i = start + 1
lenidx = start - 1
while i <= len(ent):
tmp = " ".join(ent[start:i])
if len(tmp) == int(ent[lenidx]):
return (tmp, i)
i = i + 1
return ("", 0)
def add_to_status_list(lists, status_ent):
if status_ent[1] == 'A':
filename, index = get_filename(4, status_ent)
lists[0].append(filename)
elif status_ent[1] == 'D':
filename, index = get_filename(4, status_ent)
lists[1].append(filename)
elif status_ent[1] == 'R':
filename1, index1 = get_filename(4, status_ent)
filename2, index2 = get_filename(index1 + 1, status_ent)
lists[2].append(filename1 + " was moved to " + filename2)
elif status_ent[1] == 'M':
filename, index = get_filename(4, status_ent)
lists[3].append(filename)
elif status_ent[1] == 'U':
if int(status_ent[2]) == 3:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Modified by others but removed by me")
elif int(status_ent[2]) == 4:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Modified by me but removed by others")
elif int(status_ent[2]) == 6:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Others change it from directory to a "\
"file while I modified files under that directory")
elif int(status_ent[2]) == 5:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": I change it from file to a "\
"directory while others modified this file")
elif int(status_ent[2]) == 2:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Newly added by me and others, with different content")
elif int(status_ent[2]) == 1:
filename, index = get_filename(4, status_ent)
lists[4].append(filename + ": Modified by me and others, with different content")
def get_repo_status(repo_id):
status = seafile_rpc.get_repo_status(repo_id)
lists = ([], [], [], [])
cnt = 0
i = 0;
s = status.split("\n")
print s
while cnt < 4:
if int(s[i]) != 0:
tmpcnt = int(s[i]) + i
while i < tmpcnt:
i = i + 1
lists[cnt].append(s[i])
i = i + 1
cnt = cnt + 1
# New Removed Renamed Modified Conflict
lists = ([], [], [], [], [])
fmt_status = seafile_threaded_rpc.get_repo_status(repo_id)
if fmt_status == "":
return lists
status_result = fmt_status[:len(fmt_status)-1]
for status_ent in status_result.split("\n"):
tmp = status_ent.split(" ")
# Only display changes in worktree
if tmp[0] == 'W':
add_to_status_list(lists, tmp)
return lists
def get_diff(repo_id, arg1, arg2):
# New Removed Renamed Modified Conflict
# conflict is not used
lists = ([], [], [], [], [])
diff_result = seafserv_rpc.get_diff(repo_id, arg1, arg2)
if diff_result == "":
return lists;
diff_result = diff_result[:len(diff_result)-1]
for d in diff_result.split("\n"):
tmp = d.split(" ")
if tmp[0] == 'C':
add_to_status_list(lists, tmp)
return lists
def list_dir(root_id):
dirent_list = seafserv_rpc.list_dir(root_id);
return dirent_list
######## ccnet-applet API #####
class CcnetError(Exception):
@ -415,7 +484,7 @@ def open_dir(path):
"""Call remote service `opendir`."""
client = pool.get_client()
req_id = client.get_request_id()
req = "applet-opendir " + path
req = "applet-opendir " + os.path.normpath(path)
client.send_request(req_id, req)
if client.read_response() < 0:
raise NetworkError("Read response error")

View File

@ -3,7 +3,7 @@ from django.conf import settings
from django.views.generic.simple import direct_to_template
from seahub.views import root, home, peers, groups, myhome, myrepos, \
repo, group, group_add_repo, modify_token, remove_repo
repo, group, group_add_repo, modify_token, remove_repo, seafadmin
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
@ -39,6 +39,7 @@ urlpatterns = patterns('',
(r'^repo/token/modify/(?P<repo_id>[^/]+)/$', modify_token),
(r'^repo/remove/(?P<repo_id>[^/]+)/$', remove_repo),
(r'^seafadmin/$', seafadmin),
(r'^avatar/', include('avatar.urls')),
(r'^profile/', include('seahub.profile.urls')),
)

View File

@ -6,7 +6,8 @@ from django.contrib.auth.decorators import login_required
from django.db import IntegrityError
from seaserv import cclient, ccnet_rpc, get_groups, get_users, get_repos, \
get_repo, get_commits, get_branches, seafile_rpc, get_group
get_repo, get_commits, get_branches, \
seafserv_rpc
from seahub.profile.models import UserProfile
from seahub.group.models import GroupRepo
@ -107,16 +108,16 @@ def group_add_repo(request, group_id):
def repo(request, repo_id):
# TODO: check permission
repo = get_repo(repo_id)
commits = get_commits(repo_id)
commits = get_commits(repo_id, 0, 1000)
branches = get_branches(repo_id)
token = ""
is_owner = False
if request.user.is_authenticated():
cid = get_user_cid(request.user)
if seafile_rpc.is_repo_owner(cid, repo_id):
if seafserv_rpc.is_repo_owner(cid, repo_id):
is_owner = True
token = seafile_rpc.get_repo_token(repo_id)
token = seafserv_rpc.get_repo_token(repo_id)
return render_to_response('repo.html', {
"repo": repo,
@ -138,23 +139,23 @@ def repo_share(request, repo_id):
@login_required
def modify_token(request, repo_id):
cid = get_user_cid(request.user)
if not seafile_rpc.is_repo_owner(cid, repo_id):
if not seafserv_rpc.is_repo_owner(cid, repo_id):
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
token = request.POST.get('token', '')
if token:
seafile_rpc.set_repo_token(repo_id, token)
seafserv_rpc.set_repo_token(repo_id, token)
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
@login_required
def remove_repo(request, repo_id):
cid = get_user_cid(request.user)
if not seafile_rpc.is_repo_owner(cid, repo_id):
cid = request.user.user_id
if not seafserv_rpc.is_repo_owner(cid, repo_id) or not request.user.is_staff:
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
seafile_rpc.remove_repo(repo_id)
seafserv_rpc.remove_repo(repo_id)
return HttpResponseRedirect(reverse(myhome))
@ -162,11 +163,12 @@ def remove_repo(request, repo_id):
@login_required
def myhome(request):
owned_repos = []
user_id = request.user.user_id
quota_usage = 0
user_id = request.user.user_id
if user_id:
owned_repos = seafile_rpc.list_owned_repos(user_id)
quota_usage = seafile_rpc.get_user_quota_usage(user_id)
owned_repos = seafserv_rpc.list_owned_repos(user_id)
quota_usage = seafserv_rpc.get_user_quota_usage(user_id)
return render_to_response('myhome.html', {
"owned_repos": owned_repos,
@ -183,8 +185,22 @@ def mypeers(request):
@login_required
def myrepos(request):
cid = request.user.user_id
owned_repos = seafile_rpc.list_owned_repos(cid)
owned_repos = seafserv_rpc.list_owned_repos(cid)
return render_to_response('myrepos.html', {
return render_to_response(
'myrepos.html', {
'owned_repos': owned_repos,
}, context_instance=RequestContext(request))
},
context_instance=RequestContext(request))
@login_required
def seafadmin(request):
if not request.user.is_staff:
raise Http404
repos = seafserv_rpc.get_repo_list("", 1000)
return render_to_response(
'repos.html', {
'repos': repos,
},
context_instance=RequestContext(request))