forked from superdesk/newsroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
65 lines (47 loc) · 1.57 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
from flask_script import Manager
from newsroom import Newsroom
from superdesk import get_resource_service
from newsroom.elastic_utils import rebuild_elastic_index
from newsroom.mongo_utils import index_elastic_from_mongo
app = Newsroom()
manager = Manager(app)
@manager.command
def create_user(email, password, first_name, last_name, is_admin):
new_user = {
'email': email,
'password': password,
'first_name': first_name,
'last_name': last_name,
'email': email,
'user_type': 'administrator' if is_admin else 'public',
'is_enabled': True,
'is_approved': True
}
with app.test_request_context('/users', method='POST'):
user = get_resource_service('users').find_one(email=email, req=None)
if user:
print('user already exists %s' % str(new_user))
else:
print('creating user %s' % str(new_user))
get_resource_service('users').post([new_user])
print('user saved %s' % (new_user))
return new_user
@manager.command
def elastic_rebuild():
rebuild_elastic_index()
@manager.command
def elastic_init():
app.data.init_elastic(app)
@manager.command
def index_from_mongo():
print('Checking if elastic index exists, a new one will be created if not')
app.data.init_elastic(app)
print('Elastic index check has been completed')
index_elastic_from_mongo()
@manager.command
def content_reset():
app.data.remove('items')
app.data.remove('items_versions')
if __name__ == "__main__":
manager.run()