Skip to content

Commit

Permalink
fix usertool imports (#102)
Browse files Browse the repository at this point in the history
Tested manually with 
```
FLASK_APP=tourist TOURIST_ENV=local flask --debug usertool list-users
FLASK_APP=tourist TOURIST_ENV=local flask --debug usertool set-user-edit 25 true
```
which seemed to work.
  • Loading branch information
TomGoBravo authored Oct 9, 2023
1 parent 684c048 commit a1c66b0
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions tourist/scripts/usertool.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
from typing import Dict, Iterable, List, Set
from shapely.geometry import asShape
from geoalchemy2.shape import from_shape, to_shape
from flask.cli import AppGroup
import click
from tourist.models import tstore, attrib
from shapely.geometry import mapping as shapely_mapping
from geoalchemy2.shape import to_shape
import attr
from collections import defaultdict
import json
from tourist.models import tstore


usertool_cli = AppGroup('usertool')


@usertool_cli.command('list-users')
def list_users():
for user in sqlalchemy.User.query.all():
for user in tstore.User.query.all():
print(f'{user.id}: {user.username} {user.name} {user.email} Editor: {user.edit_granted}')
for oa in user.oauth:
print(f' {oa.provider} {oa.created_at} {oa.provider_user_id} {oa.provider_user_login}')
Expand All @@ -26,13 +18,13 @@ def list_users():
@click.argument('user_id')
@click.argument('edit_granted')
def set_user_edit(user_id, edit_granted: str):
user = sqlalchemy.User.query.filter_by(id=int(user_id)).one()
user = tstore.User.query.filter_by(id=int(user_id)).one()
new_edit_granted = edit_granted.lower() in ('true', 'yes', '1', 'set')

if user.edit_granted == new_edit_granted:
click.echo('No change')
else:
user.edit_granted = new_edit_granted
click.echo(f'Saving {user.id} {user.username} {user.name} with Editor: {user.edit_granted}')
sqlalchemy.db.session.add(user)
sqlalchemy.db.session.commit()
tstore.db.session.add(user)
tstore.db.session.commit()

0 comments on commit a1c66b0

Please sign in to comment.