forked from ScoDoc/ScoDoc
commandes Flask pour creer utilisateurs de test
This commit is contained in:
parent
369b45a8c4
commit
3da9bb6914
@ -23,18 +23,10 @@
|
||||
<li><a href="{{ url_for('main.formsemestre_status', dept_id='RT') }}"><tt>formsemestre_status</tt></a> : a-t-on
|
||||
le rôle EnsRT ?
|
||||
</li>
|
||||
<li><a href="ScoDoc/RO/Scolarite/sco_exemple?etudid=E123"><tt>sco_exemple?etudid=E123</tt> : test "scodoc", url
|
||||
<li><a href="ScoDoc/RT/Scolarite/Notes/essai"><tt>Notes/essai</tt> : test "notes", url
|
||||
manuelle</a></li>
|
||||
<li><a href="{{ url_for('notes.sco_exemple2' , scodoc_dept='RT') }}"><tt>sco_exemple2</tt></a> : test appel
|
||||
entre vues
|
||||
</li>
|
||||
|
||||
<li><a href="{{ url_for('notes.sco_get_version' , scodoc_dept='RT') }}"><tt>sco_get_version</tt></a> : test
|
||||
appel vers ScoDoc interne (arg. REQUEST positionnel).
|
||||
</li>
|
||||
|
||||
<li><a href="{{ url_for('notes.sco_test_view' , scodoc_dept='RT') }}"><tt>sco_get_version</tt></a> : vue
|
||||
protégée par perm. VIEW.
|
||||
<li><a href="{{ url_for('notes.essai2' , scodoc_dept='RT') }}"><tt>Notes/essai2</tt></a> : permission
|
||||
ScoImplement dans RT
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
@ -160,7 +160,7 @@ def essai2(context):
|
||||
return essai_(context, "sans request")
|
||||
|
||||
|
||||
sco_publish("/essai2", essai2, Permission.ScoView)
|
||||
sco_publish("/essai2", essai2, Permission.ScoImplement)
|
||||
|
||||
# ---------------------
|
||||
|
||||
|
57
scodoc.py
57
scodoc.py
@ -10,7 +10,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from pprint import pprint as pp
|
||||
|
||||
import sys
|
||||
|
||||
import click
|
||||
import flask
|
||||
@ -40,7 +40,7 @@ def make_shell_context():
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def inituserdb():
|
||||
def user_db_init():
|
||||
"""Initialize the users database."""
|
||||
click.echo("Init the db")
|
||||
# Create roles:
|
||||
@ -62,14 +62,59 @@ def inituserdb():
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def clearuserdb():
|
||||
def user_db_clear():
|
||||
"""Erase (drop) all tables of users database !"""
|
||||
click.echo("Erasing the db !")
|
||||
_cleardb()
|
||||
click.echo("Erasing the users database !")
|
||||
_clear_users_db()
|
||||
|
||||
|
||||
def _cleardb():
|
||||
def _clear_users_db():
|
||||
"""Erase (drop) all tables of users database !"""
|
||||
click.confirm("This will erase all users.\nDo you want to continue?", abort=True)
|
||||
db.reflect()
|
||||
db.drop_all()
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
@click.argument("username")
|
||||
@click.argument("role")
|
||||
@click.argument("dept")
|
||||
def user_create(username, role, dept):
|
||||
"Create a new user"
|
||||
r = Role.get_named_role(role)
|
||||
if not r:
|
||||
sys.stderr.write("user_create: role {r} does not exists".format(r=r))
|
||||
return 1
|
||||
u = User.query.filter_by(username=username).first()
|
||||
if u:
|
||||
sys.stderr.write("user_create: user {u} already exists".format(u=u))
|
||||
return 2
|
||||
u = User(username=username)
|
||||
u.add_role(r, dept)
|
||||
db.session.add(u)
|
||||
db.session.commit()
|
||||
click.echo(
|
||||
"created user, login: {u.username}, with role {r} in dept. {dept}".format(
|
||||
u=u, r=r, dept=dept
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
@click.argument("username")
|
||||
@click.password_option()
|
||||
def user_password(username, password=None):
|
||||
"Set (or change) user's password"
|
||||
if not password:
|
||||
sys.stderr.write("user_password: missing password")
|
||||
return 1
|
||||
u = User.query.filter_by(username=username).first()
|
||||
if not u:
|
||||
sys.stderr.write("user_password: user {} does not exists".format(username))
|
||||
return 1
|
||||
|
||||
u.set_password(password)
|
||||
db.session.add(u)
|
||||
db.session.commit()
|
||||
click.echo("changed password for user {}".format(u))
|
||||
|
Loading…
Reference in New Issue
Block a user