mirror of
https://github.com/haiwen/seahub.git
synced 2025-06-29 16:37:56 +00:00
User seafserv_rpc instead of seafile_rpc and add repo management for staff
This commit is contained in:
parent
56275225aa
commit
14308b7f7b
@ -2,6 +2,7 @@
|
|||||||
from seahub.profile.models import UserProfile
|
from seahub.profile.models import UserProfile
|
||||||
|
|
||||||
class UseridMiddleware(object):
|
class UseridMiddleware(object):
|
||||||
|
"""Store ccnet user id in request.user.user_id"""
|
||||||
|
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
|
@ -144,4 +144,4 @@ strong { color:#808; font-weight: normal; }
|
|||||||
div.home-page h2 { font-style: italic; }
|
div.home-page h2 { font-style: italic; }
|
||||||
/* help pages */
|
/* help pages */
|
||||||
.help-page { width: 550px; }
|
.help-page { width: 550px; }
|
||||||
.help-page img { display: block; margin-left: auto; margin: 20px auto; }
|
.help-page img { display: block; margin: 20px auto; }
|
@ -4,6 +4,11 @@
|
|||||||
<li>
|
<li>
|
||||||
<a href="{{ SITE_ROOT }}home/my/">我的页面</a>
|
<a href="{{ SITE_ROOT }}home/my/">我的页面</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% if request.user.is_staff %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ SITE_ROOT }}seafadmin/">中继管理</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ SITE_ROOT }}help/">使用帮助</a>
|
<a href="{{ SITE_ROOT }}help/">使用帮助</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -30,12 +30,12 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h3>分支</h3>
|
<h3>版本</h3>
|
||||||
|
|
||||||
<table class="branch-list default">
|
<table class="branch-list default">
|
||||||
<tr>
|
<tr>
|
||||||
<th>分支名</th>
|
<th>版本名</th>
|
||||||
<th>Head Commit</th>
|
<th>最新提交记录</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for branch in branches %}
|
{% for branch in branches %}
|
||||||
<tr>
|
<tr>
|
||||||
@ -45,12 +45,12 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h3>Commits</h3>
|
<h3>提交记录</h3>
|
||||||
<table class="commit-list default">
|
<table class="commit-list default">
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Time</th>
|
<th>时间</th>
|
||||||
<th>Discription</th>
|
<th>描述</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for commit in commits %}
|
{% for commit in commits %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "myhome_base.html" %}
|
||||||
|
|
||||||
{% block right_panel %}
|
{% block right_panel %}
|
||||||
|
|
||||||
|
<h2>所有文件盒</h2>
|
||||||
<table class="repo-list default">
|
<table class="repo-list default">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>名字</th>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Discription</th>
|
<th>描述</th>
|
||||||
|
<th>操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for repo in repos %}
|
{% for repo in repos %}
|
||||||
<tr>
|
<tr>
|
||||||
<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><a href="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/">删除</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
|
|
||||||
import service
|
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, \
|
from service import translate_peerid, translate_msgtime, translate_groupid, \
|
||||||
translate_userid, translate_msgtime2, translate_time_sec, \
|
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_peers_by_role, get_peers_by_myrole, send_command
|
||||||
from service import get_groups, get_group
|
from service import get_groups, get_group
|
||||||
from service import get_users, get_user, get_events, count_event
|
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, \
|
from service import get_repos, get_repo, get_repo_sinfo, get_commits, \
|
||||||
get_branches, get_commit_tree_block_number, \
|
get_branches, get_commit_tree_block_number, \
|
||||||
get_upload_task_list, get_download_task_list, list_share_info, open_dir, \
|
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
|
from service import CCNET_CONF_PATH
|
||||||
|
|
||||||
|
@ -44,20 +44,28 @@ Repo:
|
|||||||
name: Repo Name
|
name: Repo Name
|
||||||
desc: Repo description
|
desc: Repo description
|
||||||
worktree: The full path of the worktree of the repo
|
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
|
head_branch: The name of the head branch
|
||||||
|
enctrypted: True if the repo is encrypted
|
||||||
|
passwd: The password
|
||||||
|
|
||||||
|
|
||||||
Branch:
|
Branch:
|
||||||
name:
|
name:
|
||||||
commit_id:
|
commit_id:
|
||||||
repo_id:
|
repo_id:
|
||||||
|
|
||||||
ShareItem:
|
Commit:
|
||||||
|
|
||||||
id:
|
id:
|
||||||
|
creator_name:
|
||||||
|
creator: The id of the creator
|
||||||
|
desc:
|
||||||
|
ctime:
|
||||||
repo_id:
|
repo_id:
|
||||||
group_id:
|
root_id:
|
||||||
user_id:
|
parent_id:
|
||||||
timestamp:
|
second_parent_id:
|
||||||
|
|
||||||
SyncInfo:
|
SyncInfo:
|
||||||
|
|
||||||
@ -74,13 +82,12 @@ import json
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pysearpc import SearpcError
|
|
||||||
import ccnet
|
import ccnet
|
||||||
import seamsg
|
|
||||||
import seafile
|
import seafile
|
||||||
|
from pysearpc import SearpcError
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if 'win' in sys.platform:
|
||||||
DEFAULT_CCNET_CONF_PATH = "C:\\ccnet"
|
DEFAULT_CCNET_CONF_PATH = "~/ccnet"
|
||||||
else:
|
else:
|
||||||
DEFAULT_CCNET_CONF_PATH = "~/.ccnet"
|
DEFAULT_CCNET_CONF_PATH = "~/.ccnet"
|
||||||
|
|
||||||
@ -89,9 +96,11 @@ if 'CCNET_CONF_DIR' in os.environ:
|
|||||||
else:
|
else:
|
||||||
CCNET_CONF_PATH = DEFAULT_CCNET_CONF_PATH
|
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
|
# (name, id) info
|
||||||
cclient = ccnet.Client()
|
cclient = ccnet.Client()
|
||||||
|
|
||||||
@ -103,9 +112,8 @@ else:
|
|||||||
|
|
||||||
pool = ccnet.ClientPool(CCNET_CONF_PATH)
|
pool = ccnet.ClientPool(CCNET_CONF_PATH)
|
||||||
ccnet_rpc = ccnet.CcnetRpcClient(pool)
|
ccnet_rpc = ccnet.CcnetRpcClient(pool)
|
||||||
seamsg_rpc = seamsg.RpcClient(pool)
|
|
||||||
seafile_rpc = seafile.RpcClient(pool)
|
|
||||||
monitor_rpc = seafile.MonitorRpcClient(pool)
|
monitor_rpc = seafile.MonitorRpcClient(pool)
|
||||||
|
seafserv_rpc = seafile.ServerRpcClient(pool)
|
||||||
|
|
||||||
user_db = {}
|
user_db = {}
|
||||||
|
|
||||||
@ -123,6 +131,22 @@ def translate_userid(user_id):
|
|||||||
else:
|
else:
|
||||||
return user_id[:8]
|
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 = {}
|
peer_db = {}
|
||||||
|
|
||||||
def translate_peerid(peer_id):
|
def translate_peerid(peer_id):
|
||||||
@ -135,7 +159,22 @@ def translate_peerid(peer_id):
|
|||||||
else:
|
else:
|
||||||
return peer_id[:8]
|
return peer_id[:8]
|
||||||
if peer.props.name:
|
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:
|
else:
|
||||||
return peer_id[:8]
|
return peer_id[:8]
|
||||||
|
|
||||||
@ -303,103 +342,133 @@ def send_command(command):
|
|||||||
pool.return_client(client)
|
pool.return_client(client)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
######## seamsg API #####
|
|
||||||
|
|
||||||
def get_message(msgid):
|
######## seafserv API ####
|
||||||
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 ####
|
|
||||||
|
|
||||||
def get_repos():
|
def get_repos():
|
||||||
"""
|
"""
|
||||||
Return repository list.
|
Return repository list.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return seafile_rpc.get_repo_list("", 100)
|
return seafserv_rpc.get_repo_list("", 100)
|
||||||
|
|
||||||
def get_repo(repo_id):
|
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):
|
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):
|
def get_commits(repo_id, offset, limit):
|
||||||
return seafile_rpc.get_commit_list(repo_id, "", 100)
|
"""Get commit lists."""
|
||||||
|
return seafserv_rpc.get_commit_list(repo_id, offset, limit)
|
||||||
|
|
||||||
def get_commit_tree_block_number(commit_id):
|
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):
|
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():
|
def get_upload_task_list():
|
||||||
return seafile_rpc.get_upload_task_list()
|
return seafserv_rpc.get_upload_task_list()
|
||||||
|
|
||||||
def get_download_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):
|
def get_branches(repo_id):
|
||||||
"""Get branches of a given repo"""
|
"""Get branches of a given repo"""
|
||||||
return seafile_rpc.branch_gets(repo_id)
|
return seafserv_rpc.branch_gets(repo_id)
|
||||||
|
|
||||||
def list_share_info():
|
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):
|
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
|
# New Removed Renamed Modified Conflict
|
||||||
cnt = cnt + 1
|
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
|
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 #####
|
######## ccnet-applet API #####
|
||||||
class CcnetError(Exception):
|
class CcnetError(Exception):
|
||||||
@ -415,7 +484,7 @@ def open_dir(path):
|
|||||||
"""Call remote service `opendir`."""
|
"""Call remote service `opendir`."""
|
||||||
client = pool.get_client()
|
client = pool.get_client()
|
||||||
req_id = client.get_request_id()
|
req_id = client.get_request_id()
|
||||||
req = "applet-opendir " + path
|
req = "applet-opendir " + os.path.normpath(path)
|
||||||
client.send_request(req_id, req)
|
client.send_request(req_id, req)
|
||||||
if client.read_response() < 0:
|
if client.read_response() < 0:
|
||||||
raise NetworkError("Read response error")
|
raise NetworkError("Read response error")
|
||||||
|
3
urls.py
3
urls.py
@ -3,7 +3,7 @@ from django.conf import settings
|
|||||||
from django.views.generic.simple import direct_to_template
|
from django.views.generic.simple import direct_to_template
|
||||||
|
|
||||||
from seahub.views import root, home, peers, groups, myhome, myrepos, \
|
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:
|
# Uncomment the next two lines to enable the admin:
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
@ -39,6 +39,7 @@ urlpatterns = patterns('',
|
|||||||
(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'^seafadmin/$', seafadmin),
|
||||||
(r'^avatar/', include('avatar.urls')),
|
(r'^avatar/', include('avatar.urls')),
|
||||||
(r'^profile/', include('seahub.profile.urls')),
|
(r'^profile/', include('seahub.profile.urls')),
|
||||||
)
|
)
|
||||||
|
46
views.py
46
views.py
@ -6,7 +6,8 @@ from django.contrib.auth.decorators import login_required
|
|||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
|
||||||
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, seafile_rpc, get_group
|
get_repo, get_commits, get_branches, \
|
||||||
|
seafserv_rpc
|
||||||
|
|
||||||
from seahub.profile.models import UserProfile
|
from seahub.profile.models import UserProfile
|
||||||
from seahub.group.models import GroupRepo
|
from seahub.group.models import GroupRepo
|
||||||
@ -107,16 +108,16 @@ def group_add_repo(request, group_id):
|
|||||||
def repo(request, repo_id):
|
def repo(request, repo_id):
|
||||||
# TODO: check permission
|
# TODO: check permission
|
||||||
repo = get_repo(repo_id)
|
repo = get_repo(repo_id)
|
||||||
commits = get_commits(repo_id)
|
commits = get_commits(repo_id, 0, 1000)
|
||||||
branches = get_branches(repo_id)
|
branches = get_branches(repo_id)
|
||||||
|
|
||||||
token = ""
|
token = ""
|
||||||
is_owner = False
|
is_owner = False
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
cid = get_user_cid(request.user)
|
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
|
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', {
|
return render_to_response('repo.html', {
|
||||||
"repo": repo,
|
"repo": repo,
|
||||||
@ -138,23 +139,23 @@ def repo_share(request, repo_id):
|
|||||||
@login_required
|
@login_required
|
||||||
def modify_token(request, repo_id):
|
def modify_token(request, repo_id):
|
||||||
cid = get_user_cid(request.user)
|
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]))
|
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
|
||||||
|
|
||||||
token = request.POST.get('token', '')
|
token = request.POST.get('token', '')
|
||||||
if 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]))
|
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def remove_repo(request, repo_id):
|
def remove_repo(request, repo_id):
|
||||||
cid = get_user_cid(request.user)
|
cid = request.user.user_id
|
||||||
if not seafile_rpc.is_repo_owner(cid, repo_id):
|
if not seafserv_rpc.is_repo_owner(cid, repo_id) or not request.user.is_staff:
|
||||||
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
|
return HttpResponseRedirect(reverse(repo, args=[repo_id]))
|
||||||
|
|
||||||
seafile_rpc.remove_repo(repo_id)
|
seafserv_rpc.remove_repo(repo_id)
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse(myhome))
|
return HttpResponseRedirect(reverse(myhome))
|
||||||
|
|
||||||
@ -162,11 +163,12 @@ def remove_repo(request, repo_id):
|
|||||||
@login_required
|
@login_required
|
||||||
def myhome(request):
|
def myhome(request):
|
||||||
owned_repos = []
|
owned_repos = []
|
||||||
user_id = request.user.user_id
|
|
||||||
quota_usage = 0
|
quota_usage = 0
|
||||||
|
|
||||||
|
user_id = request.user.user_id
|
||||||
if user_id:
|
if user_id:
|
||||||
owned_repos = seafile_rpc.list_owned_repos(user_id)
|
owned_repos = seafserv_rpc.list_owned_repos(user_id)
|
||||||
quota_usage = seafile_rpc.get_user_quota_usage(user_id)
|
quota_usage = seafserv_rpc.get_user_quota_usage(user_id)
|
||||||
|
|
||||||
return render_to_response('myhome.html', {
|
return render_to_response('myhome.html', {
|
||||||
"owned_repos": owned_repos,
|
"owned_repos": owned_repos,
|
||||||
@ -183,8 +185,22 @@ def mypeers(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def myrepos(request):
|
def myrepos(request):
|
||||||
cid = request.user.user_id
|
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,
|
'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))
|
||||||
|
Loading…
Reference in New Issue
Block a user