mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 10:58:33 +00:00
[user-role] Select role when add a user / change role at user admin page;
Limit guest user's operation: can not create group and library.
This commit is contained in:
@@ -2591,6 +2591,7 @@ textarea:-moz-placeholder {/* for FF */
|
||||
display: inline-block;
|
||||
}
|
||||
.share-permission-select,
|
||||
.user-role-select,
|
||||
.user-status-select {
|
||||
position:relative;/*for long text in other lang in 'share admin'*/
|
||||
padding:3px 2px;
|
||||
|
@@ -34,6 +34,13 @@ class UserManager(object):
|
||||
|
||||
return self.get(email=email)
|
||||
|
||||
def update_role(self, email, role):
|
||||
"""
|
||||
If user has a role, update it; or create a role for user.
|
||||
"""
|
||||
ccnet_threaded_rpc.update_role_emailuser(email, role)
|
||||
return self.get(email=email)
|
||||
|
||||
def create_superuser(self, email, password):
|
||||
u = self.create_user(email, password, is_staff=True, is_active=True)
|
||||
return u
|
||||
@@ -72,6 +79,7 @@ class UserManager(object):
|
||||
user.ctime = emailuser.ctime
|
||||
user.org = emailuser.org
|
||||
user.source = emailuser.source
|
||||
user.role = emailuser.role
|
||||
|
||||
return user
|
||||
|
||||
|
@@ -32,6 +32,16 @@ try:
|
||||
except ImportError:
|
||||
MULTI_TENANCY = False
|
||||
|
||||
try:
|
||||
from seahub.constants import DEFAULT_USER
|
||||
except ImportError:
|
||||
DEFAULT_USER = 'default'
|
||||
|
||||
try:
|
||||
from seahub.constants import GUEST_USER
|
||||
except ImportError:
|
||||
GUEST_USER= 'guest'
|
||||
|
||||
def base(request):
|
||||
"""
|
||||
Add seahub base configure to the context.
|
||||
@@ -75,4 +85,6 @@ def base(request):
|
||||
'sysadmin_extra_enabled': ENABLE_SYSADMIN_EXTRA,
|
||||
'grps': grps,
|
||||
'multi_tenancy': MULTI_TENANCY,
|
||||
'default_user': DEFAULT_USER,
|
||||
'guest_user': GUEST_USER,
|
||||
}
|
||||
|
8
seahub/constants.py
Normal file
8
seahub/constants.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default user have common operations,
|
||||
# like creating group and library.
|
||||
DEFUALT_USER = 'default'
|
||||
|
||||
# Guest user have limited operations,
|
||||
# can not create group and library.
|
||||
GUEST_USER = 'guest'
|
||||
|
@@ -14,8 +14,13 @@ class AddUserForm(forms.Form):
|
||||
"""
|
||||
Form for adding a user.
|
||||
"""
|
||||
from seahub import constants
|
||||
DEFAULT_USER = getattr(constants, 'DEFAULT_USER', 'default')
|
||||
GUEST_USER = getattr(constants, 'GUEST_USER', 'guest')
|
||||
|
||||
email = forms.EmailField()
|
||||
role = forms.ChoiceField( \
|
||||
choices=[(DEFAULT_USER, DEFAULT_USER), (GUEST_USER,GUEST_USER)])
|
||||
password1 = forms.CharField(widget=forms.PasswordInput())
|
||||
password2 = forms.CharField(widget=forms.PasswordInput())
|
||||
|
||||
|
@@ -11,7 +11,9 @@
|
||||
<li class="tab"><a href="#grp-repos" class="a">{% trans "Libraries" %}</a></li>
|
||||
<li class="tab long-tab"><a href="#grp-repos-commits" class="a">{% trans "Recent Changes" %}</a></li>
|
||||
</ul>
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
<button id="repo-create" class="fright"><img src="{{ MEDIA_URL }}img/add.png" alt="" class="add vam" /><span class="vam">{% trans "New Library" %}</span></button>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="grp-repos" class="hide">
|
||||
{% if repos %}
|
||||
|
@@ -1,8 +1,16 @@
|
||||
{% load i18n %}
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
<div class="info-item">
|
||||
<h3 class="info-item-top">{% trans "Tips" %}</h3>
|
||||
<div class="info-item-bottom">
|
||||
<p class="not-last">{% trans "After creating a group, you can add members and share libraries into it." %}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
<div class="info-item">
|
||||
<h3 class="info-item-top">{% trans "Tips" %}</h3>
|
||||
<div class="info-item-bottom">
|
||||
<p class="not-last">{% trans "You are a guest user now, can not create group. But group(s) you have joined in will be list right." %}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
@@ -2,7 +2,9 @@
|
||||
{% load url from future %}
|
||||
|
||||
<h3>{% trans "My Groups" %}</h3>
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
<button id="group-add"><img src="{{ MEDIA_URL }}img/add.png" alt="" class="add vam" /><span class="vam">{% trans "New Group" %}</span></button>
|
||||
{% endif %}
|
||||
{% if joined_groups %}
|
||||
<ul class="group-list w100 ovhd">
|
||||
{% for group in joined_groups %}
|
||||
@@ -24,10 +26,17 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
<div class="empty-tips">
|
||||
<h2 class="alc">{% trans "You are not in any groups" %}</h2>
|
||||
<p>{% blocktrans %}You can create a group by clicking "New Group" button. Group is a place for you and your friends leaving messages and collaborating on libraries.{% endblocktrans %}</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-tips">
|
||||
<h2 class="alc">{% trans "You are a guest user" %}</h2>
|
||||
<p class="not-last">{% trans "You are a guest user now, can not create group. But group(s) you have joined in will be list here." %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<form id="group-add-form" action="" method="post" name="group-add-form" class="hide">{% csrf_token %}
|
||||
<h3>{% trans "New Group" %}</h3>
|
||||
|
@@ -9,11 +9,13 @@
|
||||
<ul class="side-textnav-tabs">
|
||||
<li class="tab"><a href="#user-basic-info">{% trans "Profile" %}</a></li>
|
||||
<li class="tab"><a href="#lang-setting">{% trans "Language" %}</a></li>
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
{% if not force_server_crypto %}
|
||||
<li class="tab"><a href="#enc-lib-setting">{% trans "Encrypted Libraries" %}</a></li>
|
||||
{% endif %}
|
||||
<li class="tab"><a href="#sub-lib-setting">{% trans "Sub-library" %}</a></li>
|
||||
<li class="tab"><a href="#default-lib">{% trans "Default Library" %}</a></li>
|
||||
{% endif %}
|
||||
<li class="tab"><a href="#del-account">{% trans "Delete Account" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -72,6 +74,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
{% if not force_server_crypto %}
|
||||
<div class="setting-item" id="enc-lib-setting">
|
||||
<h3>{% trans "Encrypted Libraries Setting" %}</h3>
|
||||
@@ -106,6 +109,7 @@
|
||||
<p>{% trans "Default library is the default place to store your personal documents and pictures." %}</p>
|
||||
<button id="default-lib">{% trans "Choose Default Library" %}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="setting-item" id="del-account">
|
||||
<h3>{% trans "Delete Account" %}</h3>
|
||||
|
@@ -6,7 +6,9 @@
|
||||
<div class="side-tabnav">
|
||||
<div class="hd w100 ovhd">
|
||||
<h3 class="fleft">{% trans "Personal" %}</h3>
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
<img id="enable-mods" class="fright" title="{% trans "Enable Modules" %}" src="{{MEDIA_URL}}img/setting.png" alt="" />
|
||||
{% endif %}
|
||||
</div>
|
||||
<ul class="side-tabnav-tabs">
|
||||
<li class="tab {% block cur_my_lib %}{% endblock %}"><a href="{% url 'myhome' %}" class="lib">{% trans "Libraries" %}</a></li>
|
||||
|
@@ -6,14 +6,17 @@
|
||||
{% block extra_style %}
|
||||
{% if need_guide %}
|
||||
<style type="text/css">
|
||||
#guide-for-guest,
|
||||
#guide-for-new {
|
||||
padding: 0 20px;
|
||||
width: 450px;
|
||||
}
|
||||
#guide-for-guest .icon-lightbulb,
|
||||
#guide-for-new .icon-lightbulb {
|
||||
font-size:6em;
|
||||
color:#feac74;
|
||||
}
|
||||
#guide-for-guest .txt,
|
||||
#guide-for-new .txt {
|
||||
margin-left:6.4em;
|
||||
}
|
||||
@@ -33,15 +36,28 @@
|
||||
|
||||
{% include "snippets/repo_create_form.html" %}
|
||||
|
||||
{% if need_guide %}
|
||||
<div id="guide-for-new" class="hide">
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
{% if need_guide %}
|
||||
<div id="guide-for-new" class="hide">
|
||||
<span class="icon-lightbulb fleft"></span>
|
||||
<div class="txt">
|
||||
<h3>{% trans "Welcome to Seafile!" %}</h3>
|
||||
<p>{% trans "Seafile organizes files into libraries. Each library can be synced and shared separately. We have created a personal library for you. You can create more libraries later." %}</p>
|
||||
<button class="simplemodal-close" style="margin:8px 0 0 0;">{% trans "Close" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if need_guide %}
|
||||
<div id="guide-for-guest" class="hide">
|
||||
<span class="icon-lightbulb fleft"></span>
|
||||
<div class="txt">
|
||||
<h3>{% trans "Welcome to Seafile!" %}</h3>
|
||||
<p>{% trans "You are a guest user, some operations are limited, you can ask system administrator to change you to commom user for full operations." %}</p>
|
||||
<button class="simplemodal-close" style="margin:8px 0 0 0;">{% trans "Close" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if ENABLE_SUB_LIBRARY and sub_lib_enabled %}
|
||||
@@ -62,9 +78,16 @@
|
||||
|
||||
{% block extra_script %}{{block.super}}
|
||||
<script type="text/javascript">
|
||||
{% if need_guide %}
|
||||
$(function() {$('#guide-for-new').modal({appendTo: '#main', focus:false});});
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
{% if need_guide %}
|
||||
$(function() {$('#guide-for-new').modal({appendTo: '#main', focus:false});});
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if need_guide %}
|
||||
$(function() {$('#guide-for-guest').modal({appendTo: '#main', focus:false});});
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% include "snippets/myhome_extra_script.html" %}
|
||||
var cur_tab = $('.ui-tabs-selected .a');
|
||||
var lib_create_btn = $('#repo-create'),
|
||||
|
@@ -8,11 +8,13 @@
|
||||
<li class="nav-item" {% if grps %}style="position:relative;"{% endif %}>
|
||||
<a href="{% url 'group_list' %}" class="a {% block cur_group %}{% endblock %}" {% if grps %}id="top-nav-grp"{% endif %}>{% trans "Groups" %}{% if grps %} <span class="icon-caret-down"></span>{% endif %}</a>
|
||||
</li>
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
{% if request.user.org or not cloud_mode %}
|
||||
<li class="nav-item">
|
||||
<a href="{% url 'pubrepo' %}" class="a {% block cur_pubinfo %}{% endblock %}">{% trans "Organization" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a href="{{ SITE_ROOT }}help/" class="a {% block cur_help %}{% endblock %}">{% trans "Help" %}</a>
|
||||
</li>
|
||||
|
@@ -3,10 +3,12 @@
|
||||
<div id="tabs" class="tab-tabs">
|
||||
<div class="hd ovhd">
|
||||
<ul class="tab-tabs-nav fleft">
|
||||
{% if request.user.role == default_user or request.user.role == None %}
|
||||
<li class="tab"><a href="#my-own-repos" class="a" id="mylib-tab">{% trans "Mine" %}</a></li>
|
||||
{% if ENABLE_SUB_LIBRARY and sub_lib_enabled %}
|
||||
<li class="tab"><a href="#my-sub-repos" class="a" id="sublib-tab">{% trans "Sub-libraries" %}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<li class="tab"><a href="#repos-shared-to-me" class="a" id="shared-lib-tab">{% trans "Shared" %}</a></li>
|
||||
<li class="tab"><a href="#group-repos" class="a" id="grp-lib-tab">{% trans "Group" %}</a></li>
|
||||
</ul>
|
||||
|
@@ -40,6 +40,11 @@
|
||||
<input type="password" name="password1" id="id_password1" class="input" /><br />
|
||||
<label for="id_password2">{% trans "Confirm Password" %}</label><br />
|
||||
<input type="password" name="password2" id="id_password2" class="input" /><br />
|
||||
<label>{% trans "Role:"%} </label>
|
||||
<select name="role">
|
||||
<option value={{default_user}} selected="selected">{% trans "Default"%}</option>
|
||||
<option value={{guest_user}}>{% trans "Guest"%}</option>
|
||||
</select><br />
|
||||
<p class="error hide"></p>
|
||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||
</form>
|
||||
@@ -83,7 +88,8 @@ $('#add-user-form').submit(function() {
|
||||
form_id = $(this).attr('id'),
|
||||
email = $.trim(form.children('[name="email"]').val()),
|
||||
pwd1 = $.trim(form.children('[name="password1"]').val()),
|
||||
pwd2 = $.trim(form.children('[name="password2"]').val());
|
||||
pwd2 = $.trim(form.children('[name="password2"]').val()),
|
||||
role = $('select[name="role"]', form).val();
|
||||
|
||||
if (!email) {
|
||||
apply_form_error(form_id, "{% trans "Email cannot be blank" %}");
|
||||
@@ -113,7 +119,8 @@ $('#add-user-form').submit(function() {
|
||||
data: {
|
||||
'email': email,
|
||||
'password1': pwd1,
|
||||
'password2': pwd2
|
||||
'password2': pwd2,
|
||||
'role': role
|
||||
},
|
||||
success: function(data) {
|
||||
if (data['success']) {
|
||||
|
@@ -40,10 +40,11 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th width="25%">{% trans "Email" %}</th>
|
||||
<th width="15%">{% trans "Status" %}</th>
|
||||
<th width="12%">{% trans "Status" %}</th>
|
||||
<th width="11%">{% trans "Role" %}</th>
|
||||
<th width="15%">{% trans "Space Used" %}</th>
|
||||
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
||||
<th width="23%">{% trans "Operations" %}</th>
|
||||
<th width="15%">{% trans "Operations" %}</th>
|
||||
</tr>
|
||||
|
||||
{% for user in admin_users %}
|
||||
@@ -67,6 +68,23 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
<div class="user-role">
|
||||
{% if user.role == default_user or user.role == None %}
|
||||
<span class="user-role-cur-value">{% trans "Default" %}</span>
|
||||
{% else %}
|
||||
<span class="user-role-cur-value">{% trans "Guest" %}</span>
|
||||
{% endif %}
|
||||
<img src="{{MEDIA_URL}}img/edit_12.png" alt="{% trans "Edit"%}" title="{% trans "Edit"%}" class="user-role-edit-icon cspt vh" />
|
||||
</div>
|
||||
<select name="role" class="user-role-select hide">
|
||||
<option value={{default_user}} {%if user.role == default_user or user.role == None %}selected="selected"{% endif %}>{% trans "Default" %}</option>
|
||||
<option value={{guest_user}} {%if user.role == guest_user %}selected="selected"{% endif %}>{% trans "Guest"%}</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{% if CALC_SHARE_USAGE %}
|
||||
{{ user.self_usage|filesizeformat }} + {{ user.share_usage|filesizeformat }} {% if user.quota > 0 %} / {{ user.quota|filesizeformat }} {% endif %}
|
||||
|
@@ -22,21 +22,29 @@ $('#add-user-btn').click(function() {
|
||||
});
|
||||
$('tr:gt(0)').hover(
|
||||
function() {
|
||||
$(this).find('.user-status-edit-icon').removeClass('vh');
|
||||
$(this).find('.user-status-edit-icon, .user-role-edit-icon').removeClass('vh');
|
||||
},
|
||||
function() {
|
||||
$(this).find('.user-status-edit-icon').addClass('vh');
|
||||
$(this).find('.user-status-edit-icon, .user-role-edit-icon').addClass('vh');
|
||||
}
|
||||
);
|
||||
$('.user-status-edit-icon').click(function() {
|
||||
// show 'user-status(role)-select'
|
||||
$('.user-status-edit-icon, .user-role-edit-icon').click(function() {
|
||||
$(this).parent().addClass('hide');
|
||||
$(this).parent().next().removeClass('hide'); // show 'user-status-select'
|
||||
$(this).parent().next().removeClass('hide');
|
||||
});
|
||||
$('.user-status-select').change(function() {
|
||||
$('.user-status-select, .user-role-select').change(function() {
|
||||
var select = $(this),
|
||||
uid = $(this).parent().prev().attr('data'),
|
||||
select_val = select.val(),
|
||||
class_val = $(this).attr('class');
|
||||
|
||||
if (class_val.indexOf('status') != -1) {
|
||||
var uid = $(this).parent().prev().attr('data'),
|
||||
url = "{{ SITE_ROOT }}useradmin/toggle_status/" + uid + "/?s=" + select_val;
|
||||
} else {
|
||||
var uid = $(this).parent().prev().prev().attr('data'),
|
||||
url = "{{ SITE_ROOT }}useradmin/toggle_role/" + uid + "/?r=" + select_val;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
@@ -53,14 +61,14 @@ $('.user-status-select').change(function() {
|
||||
success: function(data) {
|
||||
if (data['email_sent']) {
|
||||
feedback("{% trans "Edit succeeded, an email has been sent." %}", 'success');
|
||||
select.prev().children('.user-status-cur-value').html(select.children('option[value="' +select.val() + '"]').text());
|
||||
select.prev().children(select).html(select.children('option[value="' +select.val() + '"]').text());
|
||||
|
||||
} else if (data['email_sent'] === false) {
|
||||
feedback("{% trans "Edit succeeded, but failed to send email, please check your email configuration." %}", 'success');
|
||||
select.prev().children('.user-status-cur-value').html(select.children('option[value="' +select.val() + '"]').text());
|
||||
select.prev().children(select).html(select.children('option[value="' +select.val() + '"]').text());
|
||||
} else {
|
||||
feedback("{% trans "Edit succeeded" %}", 'success');
|
||||
select.prev().children('.user-status-cur-value').html(select.children('option[value="' +select.val() + '"]').text());
|
||||
select.prev().children(select).html(select.children('option[value="' +select.val() + '"]').text());
|
||||
}
|
||||
|
||||
select.addClass('hide');
|
||||
@@ -79,8 +87,8 @@ $('.user-status-select').change(function() {
|
||||
$(document).click(function(e) {
|
||||
var target = e.target || event.srcElement;
|
||||
// target can't be edit-icon
|
||||
if (!$('.user-status-edit-icon, .user-status-select').is(target)) {
|
||||
$('.user-status').removeClass('hide');
|
||||
$('.user-status-select').addClass('hide');
|
||||
if (!$('.user-status-edit-icon, .user-status-select, .user-role-edit-icon, .user-role-select').is(target)) {
|
||||
$('.user-status, .user-role').removeClass('hide');
|
||||
$('.user-status-select, .user-role-select').addClass('hide');
|
||||
}
|
||||
});
|
||||
|
@@ -2,10 +2,11 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th width="25%">{% trans "Email" %}</th>
|
||||
<th width="15%">{% trans "Status" %}</th>
|
||||
<th width="12%">{% trans "Status" %}</th>
|
||||
<th width="11%">{% trans "Role" %}</th>
|
||||
<th width="15%">{% trans "Space Used" %}</th>
|
||||
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
||||
<th width="23%">{% trans "Operations" %}</th>
|
||||
<th width="15%">{% trans "Operations" %}</th>
|
||||
</tr>
|
||||
|
||||
{% for user in users %}
|
||||
@@ -28,6 +29,22 @@
|
||||
</select>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
<div class="user-role">
|
||||
{% if user.role == default_user or user.role == None %}
|
||||
<span class="user-role-cur-value">{% trans "Default" %}</span>
|
||||
{% else %}
|
||||
<span class="user-role-cur-value">{% trans "Guest" %}</span>
|
||||
{% endif %}
|
||||
<img src="{{MEDIA_URL}}img/edit_12.png" alt="{% trans "Edit"%}" title="{% trans "Edit"%}" class="user-role-edit-icon cspt vh" />
|
||||
</div>
|
||||
<select name="role" class="user-role-select hide">
|
||||
<option value={{default_user}} {%if user.role == default_user or user.role == None %}selected="selected"{% endif %}>{% trans "Default" %}</option>
|
||||
<option value={{guest_user}} {%if user.role == guest_user %}selected="selected"{% endif %}>{% trans "Guest"%}</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{% if CALC_SHARE_USAGE %}
|
||||
|
@@ -193,6 +193,7 @@ urlpatterns = patterns('',
|
||||
url(r'^useradmin/activate/(?P<user_id>[^/]+)/$', user_activate, name='user_activate'),
|
||||
url(r'^useradmin/deactivate/(?P<user_id>[^/]+)/$', user_deactivate, name='user_deactivate'),
|
||||
url(r'^useradmin/toggle_status/(?P<user_id>[^/]+)/$', user_toggle_status, name='user_toggle_status'),
|
||||
url(r'^useradmin/toggle_role/(?P<user_id>[^/]+)/$', user_toggle_role, name='user_toggle_role'),
|
||||
url(r'^useradmin/(?P<email>[^/]+)/set_quota/$', user_set_quota, name='user_set_quota'),
|
||||
|
||||
url(r'^useradmin/password/reset/(?P<user_id>[^/]+)/$', user_reset, name='user_reset'),
|
||||
|
@@ -975,14 +975,17 @@ def myhome(request):
|
||||
allow_public_share = True
|
||||
|
||||
# user guide
|
||||
from seahub import constants
|
||||
DEFAULT_USER = getattr(constants, 'DEFAULT_USER', 'default')
|
||||
need_guide = False
|
||||
if len(owned_repos) == 0:
|
||||
need_guide = UserOptions.objects.is_user_guide_enabled(username)
|
||||
if need_guide:
|
||||
UserOptions.objects.disable_user_guide(username)
|
||||
# create a default library for user
|
||||
create_default_library(request)
|
||||
|
||||
if request.user.role == DEFAULT_USER or request.user.role == None:
|
||||
create_default_library(request)
|
||||
# refetch owned repos
|
||||
owned_repos = get_owned_repo_list(request)
|
||||
calculate_repos_last_modify(owned_repos)
|
||||
|
@@ -495,6 +495,29 @@ def user_toggle_status(request, user_id):
|
||||
return HttpResponse(json.dumps({'success': False}), status=500,
|
||||
content_type=content_type)
|
||||
|
||||
@login_required_ajax
|
||||
@sys_staff_required
|
||||
def user_toggle_role(request, user_id):
|
||||
content_type = 'application/json; charset=utf-8'
|
||||
|
||||
from seahub import constants
|
||||
DEFAULT_USER = getattr(constants, 'DEFAULT_USER', 'default')
|
||||
|
||||
try:
|
||||
user_role = request.GET.get('r', DEFAULT_USER)
|
||||
except ValueError:
|
||||
user_role = DEFAULT_USER
|
||||
|
||||
try:
|
||||
user = User.objects.get(id=int(user_id))
|
||||
User.objects.update_role(user.email, user_role)
|
||||
|
||||
return HttpResponse(json.dumps({'success': True}),
|
||||
content_type=content_type)
|
||||
except User.DoesNotExist:
|
||||
return HttpResponse(json.dumps({'success': False}), status=500,
|
||||
content_type=content_type)
|
||||
|
||||
def send_user_reset_email(request, email, password):
|
||||
"""
|
||||
Send email when reset user password.
|
||||
@@ -569,15 +592,23 @@ def user_add(request):
|
||||
|
||||
post_values = request.POST.copy()
|
||||
post_email = request.POST.get('email', '')
|
||||
post_values.update({'email': post_email.lower()})
|
||||
post_role = request.POST.get('role', '')
|
||||
post_values.update({
|
||||
'email': post_email.lower(),
|
||||
'role': post_role,
|
||||
})
|
||||
|
||||
form = AddUserForm(post_values)
|
||||
if form.is_valid():
|
||||
email = form.cleaned_data['email']
|
||||
role = form.cleaned_data['role']
|
||||
password = form.cleaned_data['password1']
|
||||
|
||||
user = User.objects.create_user(email, password, is_staff=False,
|
||||
is_active=True)
|
||||
if user:
|
||||
User.objects.update_role(email, role)
|
||||
|
||||
if request.user.org:
|
||||
org_id = request.user.org.org_id
|
||||
url_prefix = request.user.org.url_prefix
|
||||
|
Reference in New Issue
Block a user