mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 15:09:14 +00:00
Modify org
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
{% load group_avatar_tags %}
|
||||
|
||||
{% block nav_group_class %}class="cur"{% endblock %}
|
||||
|
@@ -18,3 +18,4 @@ def base(request):
|
||||
'seahub_title': settings.SEAHUB_TITLE,
|
||||
'account_type': settings.ACCOUNT_TYPE,
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
{% load seahub_tags avatar_tags %}
|
||||
|
||||
{% block nav_group_class %}class="cur"{% endblock %}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
{% load seahub_tags %}
|
||||
|
||||
{% block nav_group_class %}class="cur"{% endblock %}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
{% load seahub_tags avatar_tags %}
|
||||
|
||||
{% block nav_group_class %}class="cur"{% endblock %}
|
||||
|
@@ -64,8 +64,11 @@ def group_remove(request, group_id):
|
||||
seafserv_threaded_rpc.remove_repo_group(group_id_int, None)
|
||||
|
||||
if request.user.org:
|
||||
ccnet_threaded_rpc.remove_org_group(request.user.org.org_id,
|
||||
group_id_int)
|
||||
org_id = request.user.org['org_id']
|
||||
url_prefix = request.user.org['url_prefix']
|
||||
ccnet_threaded_rpc.remove_org_group(org_id, group_id_int)
|
||||
return HttpResponseRedirect(reverse('org_groups',
|
||||
args=[url_prefix]))
|
||||
except SearpcError, e:
|
||||
return go_error(request, e.msg)
|
||||
|
||||
|
0
organizations/__init__.py
Normal file
0
organizations/__init__.py
Normal file
16
organizations/context_processors.py
Normal file
16
organizations/context_processors.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def org(request):
|
||||
"""
|
||||
Add org info and base template that html page will extends to context.
|
||||
"""
|
||||
if hasattr(request.user, 'org') and request.user.org is not None:
|
||||
if request.user.org['is_staff']:
|
||||
base_template = 'org_admin_base.html'
|
||||
else:
|
||||
base_template = 'org_base.html'
|
||||
return {'cur_ctx': 'org',
|
||||
'org': request.user.org,
|
||||
'base_template': base_template}
|
||||
else:
|
||||
return {'cur_ctx': '',
|
||||
'base_template': 'myhome_base.html'}
|
||||
|
19
organizations/forms.py
Normal file
19
organizations/forms.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# encoding: utf-8
|
||||
from django import forms
|
||||
from seaserv import ccnet_threaded_rpc
|
||||
|
||||
class OrgCreateForm(forms.Form):
|
||||
org_name = forms.CharField(max_length=256,
|
||||
widget=forms.TextInput(),
|
||||
label="Organization Name")
|
||||
url_prefix = forms.RegexField(label="Url Prefix", max_length=20,
|
||||
regex=r'^[a-z0-9]+$',
|
||||
error_message="域名前缀只能包含字母或数字")
|
||||
|
||||
def clean_url_prefix(self):
|
||||
url_prefix = self.cleaned_data['url_prefix']
|
||||
org = ccnet_threaded_rpc.get_org_by_url_prefix(url_prefix)
|
||||
if not org:
|
||||
return url_prefix
|
||||
else:
|
||||
raise forms.ValidationError("该域名前缀已被注册")
|
30
organizations/middleware.py
Normal file
30
organizations/middleware.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from django.core.cache import cache
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
from seaserv import get_org_by_url_prefix
|
||||
|
||||
from settings import ORG_CACHE_PREFIX
|
||||
|
||||
class OrganizationMiddleware(object):
|
||||
"""
|
||||
Middleware that add organization info to request when user in organization
|
||||
context.
|
||||
"""
|
||||
|
||||
def process_request(self, request):
|
||||
"""
|
||||
"""
|
||||
org = cache.get(ORG_CACHE_PREFIX + request.user.username)
|
||||
request.user.org = org
|
||||
|
||||
# full_path = request.get_full_path()
|
||||
# if full_path.startswith('/organizations/'):
|
||||
# url_prefix = full_path.split('/')[2]
|
||||
# org = get_org_by_url_prefix(url_prefix)
|
||||
# if org:
|
||||
# request.org = org
|
||||
|
||||
return None
|
||||
|
||||
def process_response(self, request, response):
|
||||
return response
|
3
organizations/models.py
Normal file
3
organizations/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
organizations/settings.py
Normal file
3
organizations/settings.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.conf import settings
|
||||
|
||||
ORG_CACHE_PREFIX = getattr(settings, 'ORG_CACHE_PREFIX', 'ORGANIZATION_')
|
48
organizations/templates/organizations/change_account.html
Normal file
48
organizations/templates/organizations/change_account.html
Normal file
@@ -0,0 +1,48 @@
|
||||
{% extends base_template %}
|
||||
{% load avatar_tags %}
|
||||
|
||||
{% block left_panel %}
|
||||
|
||||
<h3>操作</h3>
|
||||
<ul class="with-bg">
|
||||
<li><a href="{% url organizations.views.create_org %}">创建企业帐号</a></li>
|
||||
<li><a href="{% url organizations.views.change_account %}">切换帐号</a></li>
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block right_panel %}
|
||||
<div id="user-basic-info">
|
||||
<h2>切换帐号</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th width="80%">名称</th>
|
||||
<th width="20%">操作</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ request.user}}</td>
|
||||
<td><button data={% url myhome %} class="account-change-btn">切换</button></td>
|
||||
</tr>
|
||||
{% for org in orgs %}
|
||||
<tr>
|
||||
<td>{{ org.org_name }}</td>
|
||||
<td><button data={% url organizations.views.org_info org.url_prefix %} class="account-change-btn">切换</button></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<form id="account-change-form" action="" method="post" class="hide">
|
||||
<input id="url_prefix" type="text" name="url_prefix" value="" /><br />
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
$('.account-change-btn').click(function() {
|
||||
location.href=$(this).attr('data');
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
20
organizations/templates/organizations/create_org.html
Normal file
20
organizations/templates/organizations/create_org.html
Normal file
@@ -0,0 +1,20 @@
|
||||
{% extends base_template %}
|
||||
{% block main_panel %}
|
||||
<div class="narrow-panel">
|
||||
<h2>创建企业帐号</h2>
|
||||
<form action="" method="post">
|
||||
<label for="id_org_name">企业名称:</label>
|
||||
{{ form.org_name}}
|
||||
<lable for="id_url_prefix">域名前缀:</label>
|
||||
{{ form.url_prefix }}
|
||||
<p class="error hide"></p>
|
||||
{{ form.url_prefix.errors }}
|
||||
<input type="submit" value="提交" class="submit" />
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
</script>
|
||||
{% endblock %}
|
52
organizations/templates/organizations/org_groups.html
Normal file
52
organizations/templates/organizations/org_groups.html
Normal file
@@ -0,0 +1,52 @@
|
||||
{% extends "org_base.html" %}
|
||||
{% load seahub_tags group_avatar_tags %}
|
||||
|
||||
{% block nav_group_class %}class="cur"{% endblock %}
|
||||
{% block left_panel %}
|
||||
<h3>操作</h3>
|
||||
<ul class="with-bg">
|
||||
<li><a id="group-add" href="#">添加小组</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
{% block right_panel %}
|
||||
|
||||
<h3>{{ org.org_name }} 的小组</h3>
|
||||
{% if groups %}
|
||||
<ul class="group-list w100 ovhd">
|
||||
{% for group in groups %}
|
||||
<li class="group fleft">
|
||||
<div class="pic fleft">
|
||||
<a href="{{ SITE_ROOT }}group/{{ group.props.id }}/" class="no-deco">
|
||||
<img src="{% grp_avatar_url group.props.id 48 %}" alt="{{ group.props.group_name }}的图标" title="{{ group.props.group_name }}" class="avatar" />
|
||||
</a>
|
||||
</div>
|
||||
<div class="txt fright">
|
||||
<h4><a href="{{ SITE_ROOT }}group/{{ group.props.id }}/">{{ group.props.group_name }}</a></h4>
|
||||
<p><span class="item-name">创建者:</span>{{ group.props.creator_name }}</p>
|
||||
<p><span class="item-name">创建时间:</span>{{ group.props.timestamp|tsstr_sec }}</p>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>暂无</p>
|
||||
{% endif %}
|
||||
|
||||
<form id="group-add-form" action="" method="post" name="group-add-form" class="hide">
|
||||
<label>小组名称:</label><br />
|
||||
<input id="group_name" name="group_name" value="" /><br />
|
||||
<input type="submit" value="提交" />
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
$("#group-add").click(function() {
|
||||
$("#group-add-form").modal({appendTo: "#main"});
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
82
organizations/templates/organizations/org_info.html
Normal file
82
organizations/templates/organizations/org_info.html
Normal file
@@ -0,0 +1,82 @@
|
||||
{% extends "org_base.html" %}
|
||||
{% load seahub_tags avatar_tags %}
|
||||
|
||||
{% block nav_org_class %}class="cur"{% endblock %}
|
||||
|
||||
{% block main_panel %}
|
||||
<div class="side fright">
|
||||
<h3>企业成员</h3>
|
||||
{% if org_users %}
|
||||
<ul>
|
||||
{% for member in org_users %}
|
||||
<li class="org-member">{% avatar member.user_name 16 %}<span class="org-member-name"><a href="{{ SITE_ROOT }}profile/{{ member.email }}/">{{ member.email|email2nickname }}</a></span></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>暂无</p>
|
||||
{% endif %}
|
||||
|
||||
{% if is_join %}
|
||||
<h3>操作</h3>
|
||||
<ul class="with-bg">
|
||||
{% if is_staff %}
|
||||
<li><a id="group-mgr" href="{{ SITE_ROOT }}group/{{ group.id }}/members/">小组管理</a></li>
|
||||
{% else %}
|
||||
<li><a id="quit-group" href="#" data="{{ SITE_ROOT }}group/{{ group.id }}/?op=quit">退出小组</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="main fleft">
|
||||
<h3>{{ org.org_name }} 公开的同步目录</h3>
|
||||
<button id="repo-create">新建同步目录</button>
|
||||
<table>
|
||||
<tr>
|
||||
<th width="25%">名字</th>
|
||||
<th width="43%">描述</th>
|
||||
<th width="20%">更新时间</th>
|
||||
<th width="12%">操作</th>
|
||||
</tr>
|
||||
{% if repos %}
|
||||
{% for repo in repos %}
|
||||
<tr>
|
||||
<td><a href="{{ SITE_ROOT }}organizations/{{ org.url_prefix }}/repo/{{ repo.props.id }}/">{{ repo.props.name }}</a></td>
|
||||
<td>{{ repo.props.desc }}</td>
|
||||
{% if repo.latest_modify %}
|
||||
<td>{{ repo.latest_modify|translate_commit_time }}</td>
|
||||
{% else %}
|
||||
<td>—— ——</td>
|
||||
{% endif %}
|
||||
<td>
|
||||
<img src="{{ MEDIA_URL }}img/sync-20.png" data="{{ repo.props.id }}" class="download-btn vh" title="同步到本地" alt="同步" />
|
||||
<!-- <img src="{{ MEDIA_URL }}img/share-20.png" data="{{ repo.props.id }}" class="repo-share-btn vh" title="共享" alt="共享" /> -->
|
||||
<img src="{{ MEDIA_URL }}img/delete-20.png" data="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/?next={{ request.path }}" class="repo-delete-btn vh" title="删除" alt="删除" />
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
addConfirmTo($('#quit-group'), '确定要退出?');
|
||||
addConfirmTo($('.cancel-share'), '确定要取消共享该目录?');
|
||||
|
||||
$("table tr:gt(0)").hover(
|
||||
function() {
|
||||
$(this).find('img').css('cursor', 'pointer').removeClass('vh');
|
||||
},
|
||||
function() {
|
||||
$(this).find('img').addClass('vh');
|
||||
}
|
||||
);
|
||||
|
||||
$('.download').click(function() {
|
||||
window.open($(this).attr('data'));
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
16
organizations/tests.py
Normal file
16
organizations/tests.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
20
organizations/urls.py
Normal file
20
organizations/urls.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.conf.urls.defaults import *
|
||||
|
||||
from views import *
|
||||
from seahub.views import repo, repo_history, org_seafadmin, org_useradmin, \
|
||||
org_group_admin
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^create/$', create_org),
|
||||
(r'^change_account/$', change_account),
|
||||
(r'^(?P<url_prefix>[^/]+)/$', org_info),
|
||||
url(r'^(?P<url_prefix>[^/]+)/groups/$', org_groups, name='org_groups'),
|
||||
|
||||
url(r'^([^/]+)/repo/(?P<repo_id>[^/]+)/$', repo, name='repo'),
|
||||
url(r'^([^/]+)/repo/history/(?P<repo_id>[^/]+)/$', repo_history, name='org_repo_history'),
|
||||
|
||||
### Org admin ###
|
||||
url(r'^([^/]+)/seafadmin/$', org_seafadmin, name='org_seafadmin'),
|
||||
url(r'^([^/]+)/useradmin/$', org_useradmin, name='org_useradmin'),
|
||||
url(r'^([^/]+)/groupadmin/$', org_group_admin, name='org_groupadmin'),
|
||||
)
|
19
organizations/utils.py
Normal file
19
organizations/utils.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
from django.core.cache import cache
|
||||
from settings import ORG_CACHE_PREFIX
|
||||
|
||||
def clear_org_ctx(request):
|
||||
"""
|
||||
"""
|
||||
cache.delete(ORG_CACHE_PREFIX + request.user.username)
|
||||
request.user.org = None
|
||||
|
||||
def set_org_ctx(request, org_dict):
|
||||
"""
|
||||
"""
|
||||
cache.set(ORG_CACHE_PREFIX + request.user.username, org_dict, sys.maxint)
|
||||
request.user.org = org_dict
|
||||
|
||||
|
||||
|
||||
|
103
organizations/views.py
Normal file
103
organizations/views.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# encoding: utf-8
|
||||
import sys
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response
|
||||
|
||||
from auth.decorators import login_required
|
||||
from pysearpc import SearpcError
|
||||
from seaserv import ccnet_threaded_rpc, get_orgs_by_user, get_org_repos, \
|
||||
get_org_by_url_prefix, create_org, get_user_current_org
|
||||
|
||||
from forms import OrgCreateForm
|
||||
from settings import ORG_CACHE_PREFIX
|
||||
from utils import set_org_ctx
|
||||
from seahub.views import myhome
|
||||
from seahub.utils import go_error, go_permission_error, validate_group_name
|
||||
|
||||
@login_required
|
||||
def create_org(request):
|
||||
"""
|
||||
|
||||
"""
|
||||
if request.method == 'POST':
|
||||
form = OrgCreateForm(request.POST)
|
||||
if form.is_valid():
|
||||
org_name = form.cleaned_data['org_name']
|
||||
url_prefix = form.cleaned_data['url_prefix']
|
||||
username = request.user.username
|
||||
|
||||
try:
|
||||
# create_org(org_name, url_prefix, username)
|
||||
ccnet_threaded_rpc.create_org(org_name, url_prefix, username)
|
||||
return HttpResponseRedirect(\
|
||||
reverse(org_info, args=[url_prefix]))
|
||||
except SearpcError, e:
|
||||
return go_error(request, e.msg)
|
||||
|
||||
else:
|
||||
form = OrgCreateForm()
|
||||
|
||||
return render_to_response('organizations/create_org.html', {
|
||||
'form': form,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def change_account(request):
|
||||
"""
|
||||
|
||||
"""
|
||||
orgs = get_orgs_by_user(request.user.username)
|
||||
|
||||
return render_to_response('organizations/change_account.html', {
|
||||
'orgs': orgs,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def org_info(request, url_prefix):
|
||||
"""
|
||||
"""
|
||||
org = get_user_current_org(request.user.username, url_prefix)
|
||||
if not org:
|
||||
return HttpResponseRedirect(reverse(myhome))
|
||||
|
||||
set_org_ctx(request, org._dict)
|
||||
|
||||
org_members = ccnet_threaded_rpc.get_org_emailusers(url_prefix,
|
||||
0, sys.maxint)
|
||||
repos = get_org_repos(org.org_id, 0, sys.maxint)
|
||||
return render_to_response('organizations/org_info.html', {
|
||||
'org': org,
|
||||
'org_users': org_members,
|
||||
'repos': repos,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def org_groups(request, url_prefix):
|
||||
"""
|
||||
|
||||
"""
|
||||
org = get_user_current_org(request.user.username, url_prefix)
|
||||
if not org:
|
||||
return HttpResponseRedirect(reverse(myhome))
|
||||
|
||||
if request.method == 'POST':
|
||||
group_name = request.POST.get('group_name')
|
||||
if not validate_group_name(group_name):
|
||||
return go_error(request, u'小组名称只能包含中英文字符,数字及下划线')
|
||||
|
||||
try:
|
||||
group_id = ccnet_threaded_rpc.create_group(group_name.encode('utf-8'),
|
||||
request.user.username)
|
||||
ccnet_threaded_rpc.add_org_group(org.org_id, group_id)
|
||||
except SearpcError, e:
|
||||
error_msg = e.msg
|
||||
return go_error(request, error_msg)
|
||||
|
||||
groups = ccnet_threaded_rpc.get_org_groups(org.org_id, 0, sys.maxint)
|
||||
return render_to_response('organizations/org_groups.html', {
|
||||
'org': org,
|
||||
'groups': groups,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
|
||||
{% block title %}帐号设置{% endblock %}
|
||||
|
||||
|
@@ -2,12 +2,13 @@
|
||||
{% load avatar_tags %}
|
||||
|
||||
{% block left_panel %}
|
||||
<!--
|
||||
|
||||
<h3>操作</h3>
|
||||
<ul class="with-bg">
|
||||
<li><a href="{{ SITE_ROOT }}profile/list_user/">所有已登录的计算机</a></li>
|
||||
<li><a href="{% url organizations.views.create_org %}">创建企业帐号</a></li>
|
||||
<li><a href="{% url organizations.views.change_account %}">切换帐号</a></li>
|
||||
</ul>
|
||||
-->
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block right_panel %}
|
||||
|
@@ -69,6 +69,7 @@ MIDDLEWARE_CLASSES = (
|
||||
'auth.middleware.AuthenticationMiddleware',
|
||||
'seahub.base.middleware.InfobarMiddleware',
|
||||
'seahub.subdomain.middleware.SubdomainMiddleware',
|
||||
'seahub.organizations.middleware.OrganizationMiddleware',
|
||||
)
|
||||
|
||||
SITE_ROOT_URLCONF = 'seahub.urls'
|
||||
@@ -93,6 +94,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
||||
'django.core.context_processors.request',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'seahub.base.context_processors.base',
|
||||
'seahub.organizations.context_processors.org',
|
||||
)
|
||||
|
||||
|
||||
@@ -105,11 +107,12 @@ INSTALLED_APPS = (
|
||||
'django.contrib.messages',
|
||||
'registration',
|
||||
'avatar',
|
||||
'seahub.notifications',
|
||||
'seahub.base',
|
||||
'seahub.profile',
|
||||
'seahub.contacts',
|
||||
'seahub.group',
|
||||
'seahub.notifications',
|
||||
'seahub.organizations',
|
||||
'seahub.profile',
|
||||
'seahub.share',
|
||||
'seahub.subdomain',
|
||||
'seahub.api',
|
||||
|
@@ -30,10 +30,15 @@
|
||||
{% if request.user.is_staff %}
|
||||
<a href="{{ SITE_ROOT }}sys/seafadmin/"
|
||||
{% else %}
|
||||
<a href="{{ SITE_ROOT }}seafadmin/"
|
||||
<a href="{% url org_seafadmin request.user.org.url_prefix %}"
|
||||
{% endif %}
|
||||
{% block top_bar_manager_class %}{% endblock %}>管理员控制台</a>
|
||||
<a href="{{ SITE_ROOT }}home/my/"{% block top_bar_myaccount_class %}{% endblock %}>我的帐号</a>
|
||||
{% if request.user.is_staff %}
|
||||
<a href="{{ SITE_ROOT }}home/my/"
|
||||
{% else %}
|
||||
<a href="{% url organizations.views.org_info request.user.org.url_prefix %}"
|
||||
{% endif %}
|
||||
{% block top_bar_myaccount_class %}{% endblock %}>我的帐号</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
|
||||
{% block title %}错误{% endblock %}
|
||||
|
||||
|
@@ -4,13 +4,13 @@
|
||||
<ul class="nav">
|
||||
{% if request.user.org.is_staff %}
|
||||
<li>
|
||||
<a href="{{ SITE_ROOT }}seafadmin/" {% block nav_seafadmin_class %}{% endblock %}>目录管理</a>
|
||||
<a href="{% url org_seafadmin request.user.org.url_prefix %}" {% block nav_seafadmin_class %}{% endblock %}>目录管理</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ SITE_ROOT }}useradmin/" {% block nav_useradmin_class %}{% endblock %}>用户管理</a>
|
||||
<a href="{% url org_useradmin request.user.org.url_prefix %}" {% block nav_useradmin_class %}{% endblock %}>用户管理</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ SITE_ROOT }}groupadmin/" {% block nav_groupadmin_class %}{% endblock %}>小组管理</a>
|
||||
<a href="{% url org_groupadmin request.user.org.url_prefix %}" {% block nav_groupadmin_class %}{% endblock %}>小组管理</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
|
12
templates/org_base.html
Normal file
12
templates/org_base.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% extends "base.html" %}
|
||||
{% block top_bar_myaccount_class %} class="cur"{% endblock %}
|
||||
{% block nav %}
|
||||
<ul class="nav">
|
||||
<li>
|
||||
<a href="{% url organizations.views.org_info org.url_prefix %}" {% block nav_org_class %}{% endblock %}>企业</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url organizations.views.org_groups org.url_prefix %}" {% block nav_group_class %}{% endblock %}>小组</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
@@ -1,4 +1,4 @@
|
||||
{% extends "org_admin_base.html" %}
|
||||
{% extends base_template %}
|
||||
{% block nav_seafadmin_class %}class="cur"{% endblock %}
|
||||
|
||||
{% block right_panel %}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
|
||||
{% block title %}权限错误{% endblock %}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% extends base_template %}
|
||||
|
||||
{% load seahub_tags %}
|
||||
|
||||
{% block info_bar_message %}
|
||||
@@ -53,7 +54,7 @@
|
||||
<div class="latest-commit">
|
||||
<h3>最新修改
|
||||
{% if request.user.is_authenticated %}
|
||||
<a href="{{ SITE_ROOT }}repo/history/{{repo.props.id}}/" class="more">(更多)</a>
|
||||
<a href="{% url seahub.views.repo_history repo.id %}" class="more">(更多)</a>
|
||||
{% endif %}
|
||||
</h3>
|
||||
<p>{{ current_commit.props.desc|translate_commit_desc }}</p>
|
||||
|
@@ -4,10 +4,12 @@ from service import ccnet_rpc, monitor_rpc, seafserv_rpc, \
|
||||
seafserv_threaded_rpc, ccnet_threaded_rpc
|
||||
from service import send_command
|
||||
from service import get_groups, get_group
|
||||
from service import get_repos, get_repo, get_commits, get_branches
|
||||
from service import get_repos, get_repo, get_commits, get_branches, get_org_repos
|
||||
from service import get_binding_peerids
|
||||
from service import get_ccnetuser
|
||||
from service import get_group_repoids, check_group_staff
|
||||
from service import create_org, get_orgs_by_user, get_org_by_url_prefix, \
|
||||
get_user_current_org
|
||||
|
||||
from service import CCNET_CONF_PATH
|
||||
|
||||
|
@@ -75,8 +75,8 @@ def get_ccnetuser(username=None, userid=None):
|
||||
return None
|
||||
|
||||
# Check whether is business account
|
||||
org = ccnet_threaded_rpc.get_org_by_user(emailuser.email)
|
||||
emailuser.org = org
|
||||
# orgs = ccnet_threaded_rpc.get_orgs_by_user(emailuser.email)
|
||||
# emailuser.org = org
|
||||
|
||||
# And convert to ccnetuser
|
||||
from seahub.base.accounts import convert_to_ccnetuser
|
||||
@@ -108,6 +108,31 @@ def get_group(group_id):
|
||||
group.maintainers = group.props.maintainers.split(" ")
|
||||
return group
|
||||
|
||||
def create_org(org_name, url_prefix, username):
|
||||
ccnet_threaded_rpc.create_org(org_name, url_prefix, username)
|
||||
|
||||
def get_orgs_by_user(user):
|
||||
try:
|
||||
orgs = ccnet_threaded_rpc.get_orgs_by_user(user)
|
||||
except SearpcError:
|
||||
orgs = []
|
||||
|
||||
return orgs
|
||||
|
||||
def get_org_by_url_prefix(url_prefix):
|
||||
try:
|
||||
org = ccnet_threaded_rpc.get_org_by_url_prefix(url_prefix)
|
||||
except SearpcError:
|
||||
org = None
|
||||
|
||||
return org
|
||||
|
||||
def get_user_current_org(user, url_prefix):
|
||||
orgs = get_orgs_by_user(user)
|
||||
for org in orgs:
|
||||
if org.url_prefix == url_prefix:
|
||||
return org
|
||||
return None
|
||||
|
||||
def send_command(command):
|
||||
client = pool.get_client()
|
||||
@@ -126,6 +151,16 @@ def get_repos():
|
||||
"""
|
||||
return seafserv_threaded_rpc.get_repo_list("", 100)
|
||||
|
||||
def get_org_repos(org_id, start, limit):
|
||||
"""
|
||||
"""
|
||||
try:
|
||||
repos = seafserv_threaded_rpc.get_org_repo_list(org_id, start, limit)
|
||||
except SearpcError:
|
||||
repos = []
|
||||
|
||||
return repos
|
||||
|
||||
def get_repo(repo_id):
|
||||
return seafserv_threaded_rpc.get_repo(repo_id)
|
||||
|
||||
@@ -178,3 +213,4 @@ def check_group_staff(group_id_int, user_or_username):
|
||||
user_or_username = user_or_username.username
|
||||
|
||||
return ccnet_threaded_rpc.check_group_staff(group_id_int, user_or_username)
|
||||
|
||||
|
5
urls.py
5
urls.py
@@ -97,6 +97,7 @@ urlpatterns = patterns('',
|
||||
(r'^contacts/', include('contacts.urls')),
|
||||
(r'^group/', include('seahub.group.urls')),
|
||||
url(r'^groups/', group_list, name='group_list'),
|
||||
(r'^organizations/', include('seahub.organizations.urls')),
|
||||
(r'^profile/', include('seahub.profile.urls')),
|
||||
|
||||
### SeaHub admin ###
|
||||
@@ -105,10 +106,6 @@ urlpatterns = patterns('',
|
||||
url(r'^sys/orgadmin/$', sys_org_admin, name='sys_org_admin'),
|
||||
url(r'^sys/groupadmin/$', sys_group_admin, name='sys_group_admin'),
|
||||
|
||||
### Org admin ###
|
||||
(r'^seafadmin/$', org_seafadmin),
|
||||
url(r'^useradmin/$', org_useradmin, name='org_useradmin'),
|
||||
url(r'^groupadmin/$', org_group_admin, name='org_group_admin'),
|
||||
)
|
||||
|
||||
if settings.DEBUG:
|
||||
|
25
views.py
25
views.py
@@ -37,6 +37,7 @@ from seahub.base.accounts import CcnetUser
|
||||
from seahub.base.models import UuidOjbidMap
|
||||
from seahub.contacts.models import Contact
|
||||
from seahub.notifications.models import UserNotification
|
||||
from seahub.organizations.utils import clear_org_ctx
|
||||
from forms import AddUserForm, FileLinkShareForm
|
||||
from utils import go_permission_error, go_error, list_to_string, \
|
||||
get_httpserver_root, get_ccnetapplet_root, gen_token, \
|
||||
@@ -723,6 +724,10 @@ def myhome(request):
|
||||
else:
|
||||
profile = Profile.objects.filter(user=request.user.username)[0]
|
||||
nickname = profile.nickname
|
||||
|
||||
# clear org context in cache and set request.user.org to None
|
||||
clear_org_ctx(request)
|
||||
|
||||
return render_to_response('myhome.html', {
|
||||
"myname": email,
|
||||
"nickname": nickname,
|
||||
@@ -1184,7 +1189,7 @@ def sys_seafadmin(request):
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def org_seafadmin(request):
|
||||
def org_seafadmin(request, url_prefix):
|
||||
if not request.user.org:
|
||||
raise Http404
|
||||
|
||||
@@ -1196,7 +1201,7 @@ def org_seafadmin(request):
|
||||
current_page = 1
|
||||
per_page = 25
|
||||
|
||||
repos_all = seafserv_threaded_rpc.get_org_repo_list(request.user.org.org_id,
|
||||
repos_all = seafserv_threaded_rpc.get_org_repo_list(request.user.org['org_id'],
|
||||
per_page * (current_page -1),
|
||||
per_page + 1)
|
||||
|
||||
@@ -1244,11 +1249,11 @@ def sys_useradmin(request):
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def org_useradmin(request):
|
||||
if not request.user.org.is_staff:
|
||||
def org_useradmin(request, url_prefix):
|
||||
if not request.user.org['is_staff']:
|
||||
raise Http404
|
||||
|
||||
users = ccnet_threaded_rpc.get_org_emailusers(request.user.org.url_prefix,
|
||||
users = ccnet_threaded_rpc.get_org_emailusers(request.user.org['url_prefix'],
|
||||
0, sys.maxint)
|
||||
|
||||
for user in users:
|
||||
@@ -1383,7 +1388,7 @@ def send_user_add_mail(request, email, password):
|
||||
def user_add(request):
|
||||
"""Add a user"""
|
||||
|
||||
if not request.user.is_staff and not request.user.org.is_staff:
|
||||
if not request.user.is_staff and not request.user.org['is_staff']:
|
||||
raise Http404
|
||||
|
||||
base_template = 'org_admin_base.html' if request.user.org else 'admin_base.html'
|
||||
@@ -1399,7 +1404,7 @@ def user_add(request):
|
||||
ccnetuser.save()
|
||||
|
||||
if request.user.org:
|
||||
org_id = request.user.org.org_id
|
||||
org_id = request.user.org['org_id']
|
||||
ccnet_threaded_rpc.add_org_user(org_id, email, 0)
|
||||
if hasattr(settings, 'EMAIL_HOST'):
|
||||
send_user_add_mail(request, email, password)
|
||||
@@ -1469,8 +1474,8 @@ def sys_org_admin(request):
|
||||
'orgs': orgs,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
def org_group_admin(request):
|
||||
if not request.user.is_staff and not request.user.org.is_staff:
|
||||
def org_group_admin(request, url_prefix):
|
||||
if not request.user.is_staff and not request.user.org['is_staff']:
|
||||
raise Http404
|
||||
|
||||
# Make sure page request is an int. If not, deliver first page.
|
||||
@@ -1481,7 +1486,7 @@ def org_group_admin(request):
|
||||
current_page = 1
|
||||
per_page = 25
|
||||
|
||||
groups_plus_one = ccnet_threaded_rpc.get_org_groups (request.user.org.org_id,
|
||||
groups_plus_one = ccnet_threaded_rpc.get_org_groups (request.user.org['org_id'],
|
||||
per_page * (current_page -1),
|
||||
per_page +1)
|
||||
|
||||
|
Reference in New Issue
Block a user