Skip to content

Commit

Permalink
Merge pull request #52 from mekanix/feature/ldap
Browse files Browse the repository at this point in the history
Feature/ldap
  • Loading branch information
mekanix authored Mar 29, 2020
2 parents da40354 + f6567d3 commit 5b5d04a
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ build
cbsd.conf
coverage.xml
database.db
fstab
local_config.py
project.mk
site.retry
Expand Down
17 changes: 14 additions & 3 deletions bin/freenit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ set -e


NAME="${1}"
if [ -z "${NAME}" ]; then
echo "Usage: $0 <project name>" >&2
TYPE="${2}"
if [ -z "${NAME}" -o -z "${TYPE}" ]; then
echo "Usage: $0 <project name> <project type>" >&2
exit 1
fi


PROJECT_ROOT=`python${PY_VERSION} -c 'import os; import freenit; print(os.path.dirname(os.path.abspath(freenit.__file__)))'`
echo "here"
SED_CMD="sed -i"

case `uname` in
*BSD)
SED_CMD="sed -i ''"
;;
esac


mkdir ${NAME}
cd ${NAME}
echo 'freenit' >requirements.txt
echo "freenit[${TYPE}]" >requirements.txt
cp -r ${PROJECT_ROOT}/project/* .
${SED_CMD} -e "s/TYPE/${TYPE}/g" project/models/role.py
${SED_CMD} -e "s/TYPE/${TYPE}/g" project/models/user.py
mv project ${NAME}
echo "app_name=\"${NAME}\" # noqa: E225" >name.py
echo "ipdb" >requirements_dev.txt
Expand Down
10 changes: 5 additions & 5 deletions freenit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def sqlinit(app):
from .db import db
db.init_app(app)
app.db = db
User = import_module(f"{app.config['NAME']}.models.sql.user").User
role_module = import_module(f"{app.config['NAME']}.models.sql.role")
User = import_module(f"{app.config['NAME']}.models.user").User
role_module = import_module(f"{app.config['NAME']}.models.role")
Role = role_module.Role
UserRoles = role_module.UserRoles
app.user_datastore = PeeweeUserDatastore(
Expand All @@ -35,8 +35,8 @@ def mongoinit(app):
from flask_security import MongoEngineUserDatastore
from flask_mongoengine import MongoEngine
app.db = MongoEngine(app)
User = import_module(f"{app.config['NAME']}.models.mongo.user").User
Role = import_module(f"{app.config['NAME']}.models.mongo.role").Role
User = import_module(f"{app.config['NAME']}.models.user").User
Role = import_module(f"{app.config['NAME']}.models.role").Role
app.user_datastore = MongoEngineUserDatastore(app.db, User, Role)


Expand All @@ -56,7 +56,7 @@ def send_media(path):
app.sendmail = lambda message: sendmail(app.config, message)
app.collect = Collect(app)
app.dbtype = dbtype
if dbtype == 'sql':
if dbtype in ['sql', 'all']:
sqlinit(app)
elif dbtype == 'mongo':
mongoinit(app)
Expand Down
2 changes: 2 additions & 0 deletions freenit/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get(self, user_id):
@blueprint.arguments(UserSchema(partial=True))
@blueprint.response(UserSchema)
def patch(self, args, user_id):
"""Edit user details"""
User = current_app.user_datastore.user_model
try:
if current_app.dbtype == 'sql':
Expand All @@ -67,6 +68,7 @@ def patch(self, args, user_id):

@blueprint.response(UserSchema)
def delete(self, user_id):
"""Delete user"""
User = current_app.user_datastore.user_model
try:
if current_app.dbtype == 'sql':
Expand Down
2 changes: 1 addition & 1 deletion freenit/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from flask import current_app
from flask.cli import AppGroup
from flask_security.utils import hash_password
from peewee_migrate import Router

admin_group = AppGroup('admin', short_help='Manage admin users')
migration = AppGroup('migration', short_help='Migration operations')
Expand Down Expand Up @@ -30,6 +29,7 @@ def create():


def register_migration(app):
from peewee_migrate import Router
project_root = app.config.get('PROJECT_ROOT', '')
migrate_dir = f'{project_root}/migrations'
router = Router(
Expand Down
7 changes: 6 additions & 1 deletion freenit/project/bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ export OFFLINE=${OFFLINE:=no}
BIN_DIR=`dirname $0`
. ${BIN_DIR}/common.sh


if [ ! -e "${BIN_DIR}/../migrations/main/001_initial.py" ]; then
flask migration create initial
fi


if [ "${OFFLINE}" = "yes" ]; then
setup no
else
setup
fi
flask migration run
flask admin create
flask gallery create
2 changes: 1 addition & 1 deletion freenit/project/common_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Config:
OPENAPI_REDOC_PATH = '/redoc'
OPENAPI_SWAGGER_UI_PATH = '/swaggerui'
OPENAPI_SWAGGER_UI_URL = '/static/swaggerui/'
OPENAPI_VERSION = '2.0.0'
OPENAPI_VERSION = '3.0.2'
MEDIA_URL = '/media'
MEDIA_PATH = 'media'
ACCOUNT_REQUEST_EXPIRY = 24 # in hours
Expand Down
4 changes: 2 additions & 2 deletions freenit/project/project/models/role.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from freenit.models.role import Role as BaseRole
from freenit.models.role import UserRoles as BaseUserRoles
from freenit.models.TYPE.role import Role as BaseRole
from freenit.models.TYPE.role import UserRoles as BaseUserRoles


class Role(BaseRole):
Expand Down
2 changes: 1 addition & 1 deletion freenit/project/project/models/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from freenit.models.user import User as BaseUser
from freenit.models.TYPE.user import User as BaseUser


class User(BaseUser):
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

PROJECT_ROOT = pathlib.Path(__file__).parent
README = (PROJECT_ROOT / 'README.md').read_text()

ldap = ['ldap3']
mongo = ['flask-mongoengine']
sql = [
'peewee',
'peewee-migrate>=1.1.6',
]
mongo = ['flask-mongoengine']

setup(
name='freenit',
version='0.1.2',
version='0.1.3',
description='REST API framework based on Flask-Smorest',
long_description=README,
long_description_content_type='text/markdown',
Expand Down Expand Up @@ -54,7 +56,7 @@
'flask-smorest>=0.18.2',
],
extras_require={
'all': sql + mongo,
'all': ldap + mongo + sql,
'sql': sql,
'mongo': mongo,
},
Expand Down

0 comments on commit 5b5d04a

Please sign in to comment.