|
@@ -1,8 +1,10 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
import transaction
|
3
|
3
|
from sqlalchemy.exc import IntegrityError
|
|
4
|
+from tg import config
|
4
|
5
|
|
5
|
6
|
from tracim.command import AppContextCommand, Extender
|
|
7
|
+from tracim.lib.auth.ldap import LDAPAuth
|
6
|
8
|
from tracim.lib.exception import AlreadyExistError, CommandAbortedError
|
7
|
9
|
from tracim.lib.group import GroupApi
|
8
|
10
|
from tracim.lib.user import UserApi
|
|
@@ -88,7 +90,9 @@ class UserCommand(AppContextCommand):
|
88
|
90
|
|
89
|
91
|
def _create_user(self, login, password, **kwargs):
|
90
|
92
|
if not password:
|
91
|
|
- raise CommandAbortedError("You must provide -p/--password parameter")
|
|
93
|
+ if self._password_required():
|
|
94
|
+ raise CommandAbortedError("You must provide -p/--password parameter")
|
|
95
|
+ password = ''
|
92
|
96
|
|
93
|
97
|
try:
|
94
|
98
|
user = User(email=login, password=password, **kwargs)
|
|
@@ -115,6 +119,8 @@ class UserCommand(AppContextCommand):
|
115
|
119
|
print("User created/updated")
|
116
|
120
|
|
117
|
121
|
def _proceed_user(self, parsed_args):
|
|
122
|
+ self._check_context(parsed_args)
|
|
123
|
+
|
118
|
124
|
if self.action == self.ACTION_CREATE:
|
119
|
125
|
try:
|
120
|
126
|
user = self._create_user(login=parsed_args.login, password=parsed_args.password)
|
|
@@ -137,6 +143,19 @@ class UserCommand(AppContextCommand):
|
137
|
143
|
for group_name in parsed_args.remove_from_group:
|
138
|
144
|
self._remove_user_from_named_group(user, group_name)
|
139
|
145
|
|
|
146
|
+ def _password_required(self):
|
|
147
|
+ if config.get('auth_type') == LDAPAuth.name:
|
|
148
|
+ return False
|
|
149
|
+ return True
|
|
150
|
+
|
|
151
|
+ def _check_context(self, parsed_args):
|
|
152
|
+ if config.get('auth_type') == LDAPAuth.name:
|
|
153
|
+ auth_instance = config.get('auth_instance')
|
|
154
|
+ if not auth_instance.ldap_auth.user_exist(parsed_args.login):
|
|
155
|
+ raise LDAPUserUnknown(
|
|
156
|
+ "LDAP is enabled and user with login/email \"%s\" not found in LDAP" % parsed_args.login
|
|
157
|
+ )
|
|
158
|
+
|
140
|
159
|
|
141
|
160
|
class CreateUserCommand(UserCommand):
|
142
|
161
|
action = UserCommand.ACTION_CREATE
|
|
@@ -144,3 +163,7 @@ class CreateUserCommand(UserCommand):
|
144
|
163
|
|
145
|
164
|
class UpdateUserCommand(UserCommand):
|
146
|
165
|
action = UserCommand.ACTION_UPDATE
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+class LDAPUserUnknown(CommandAbortedError):
|
|
169
|
+ pass
|