mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-02 07:47:32 +00:00
Fixed bug in give/take admin
This commit is contained in:
parent
215c45d65b
commit
97c10bc6f6
@ -16,6 +16,8 @@ from seaserv import ccnet_threaded_rpc, unset_repo_passwd, is_passwd_set
|
||||
from profile.models import Profile
|
||||
from seahub.utils import get_user_repos
|
||||
|
||||
UNUSABLE_PASSWORD = '!' # This will never be a valid hash
|
||||
|
||||
class UserManager(object):
|
||||
def create_user(self, email, password=None, is_staff=False, is_active=False):
|
||||
"""
|
||||
@ -96,14 +98,12 @@ class User(object):
|
||||
def save(self):
|
||||
emailuser = ccnet_threaded_rpc.get_emailuser(self.username)
|
||||
if emailuser:
|
||||
if hasattr(self, 'password'): # setted by set_password()
|
||||
ccnet_threaded_rpc.update_emailuser(emailuser.id,
|
||||
self.password,
|
||||
int(self.is_staff),
|
||||
int(self.is_active))
|
||||
else:
|
||||
# TODO: need a new rpc tp update is_staff and is_active
|
||||
raise NotImplementedError
|
||||
if not hasattr(self, 'password'):
|
||||
self.set_unusable_password()
|
||||
ccnet_threaded_rpc.update_emailuser(emailuser.id,
|
||||
self.password,
|
||||
int(self.is_staff),
|
||||
int(self.is_active))
|
||||
else:
|
||||
ccnet_threaded_rpc.add_emailuser(self.username, self.password,
|
||||
int(self.is_staff),
|
||||
@ -141,6 +141,10 @@ class User(object):
|
||||
# get_hexdigest('sha1', '', raw_password))
|
||||
# return is_correct
|
||||
return (ccnet_threaded_rpc.validate_emailuser(self.username, raw_password) == 0)
|
||||
|
||||
def set_unusable_password(self):
|
||||
# Sets a value that will never be a valid hash
|
||||
self.password = UNUSABLE_PASSWORD
|
||||
|
||||
def email_user(self, subject, message, from_email=None):
|
||||
"Sends an e-mail to this User."
|
||||
|
@ -24,16 +24,16 @@
|
||||
{% if user.props.is_active %}
|
||||
<td>{% trans "Activated" %}</td>
|
||||
{% else %}
|
||||
<td><a href="#" data="{{ SITE_ROOT }}useradmin/activate/{{ user.props.id }}/" class="activate op">{% trans "Active" %}</a></td>
|
||||
<td><a href="{{ SITE_ROOT }}useradmin/activate/{{ user.props.id }}/" class="activate op">{% trans "Active" %}</a></td>
|
||||
{% endif %}
|
||||
<td>
|
||||
{% if not user.is_self %}
|
||||
<a href="#" class="remove-user-btn op" data-url="{{ SITE_ROOT }}useradmin/remove/{{ user.props.id }}/" data-target="{{ user.props.email }}">{% trans "Delete" %}</a>
|
||||
<a href="#" class="reset-user-btn op" data-url="{% url 'user_reset' user.id %}" data-target="{{ user.props.email }}">{% trans "ResetPwd" %}</a>
|
||||
{% if user.is_staff %}
|
||||
<a href="#" class="take-admin-btn op" data="{% url 'user_remove_admin' user.id %}">{% trans "Take Admin" %}</a>
|
||||
<a href="{% url 'user_remove_admin' user.id %}" class="take-admin-btn op">{% trans "Take Admin" %}</a>
|
||||
{% else %}
|
||||
<a href="#" class="give-admin-btn op" data="{% url 'user_make_admin' user.id %}">{% trans "Give Admin" %}</a>
|
||||
<a href="{% url 'user_make_admin' user.id %}" class="give-admin-btn op">{% trans "Give Admin" %}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
@ -73,12 +73,6 @@
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
$('.activate,.give-admin-btn,take-admin-btn').each(function(){
|
||||
$(this).click(function(){
|
||||
location.href = $(this).attr('data');
|
||||
});
|
||||
});
|
||||
|
||||
addConfirmTo($('.remove-user-btn'), {
|
||||
'title':'{% trans "Delete User" %}',
|
||||
'con':'{% trans "Are you sure you want to delete %s ?" %}'
|
||||
|
@ -2114,7 +2114,7 @@ def user_remove(request, user_id):
|
||||
@login_required
|
||||
@sys_staff_required
|
||||
def user_make_admin(request, user_id):
|
||||
"""Remove user, also remove group relationship."""
|
||||
"""Set user as system admin."""
|
||||
try:
|
||||
user = User.objects.get(id=int(user_id))
|
||||
user.is_staff = True
|
||||
@ -2127,7 +2127,7 @@ def user_make_admin(request, user_id):
|
||||
@login_required
|
||||
@sys_staff_required
|
||||
def user_remove_admin(request, user_id):
|
||||
"""Remove user, also remove group relationship."""
|
||||
"""Unset user admin."""
|
||||
try:
|
||||
user = User.objects.get(id=int(user_id))
|
||||
user.is_staff = False
|
||||
|
Loading…
Reference in New Issue
Block a user