Skip to content

Commit

Permalink
starting with file uploads endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienParis committed Jul 21, 2018
1 parent 5b653f0 commit c777a83
Show file tree
Hide file tree
Showing 47 changed files with 1,244 additions and 244 deletions.
2 changes: 1 addition & 1 deletion solidata_api/_auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .auth_decorators import (
# import custom decorators
anonymous_required,
admin_required, current_user_required,
admin_required, current_user_required, guest_required,
renew_pwd_required, reset_pwd_required,
confirm_email_required
) # token_required
Expand Down
25 changes: 23 additions & 2 deletions solidata_api/_auth/auth_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def add_claims_to_access_token(user):
'infos' : user["infos"],
'auth' : user["auth"],
# 'datasets' : user["datasets"],
# 'preferences' : user["preferences"],
# 'profile' : user["profile"],
# 'profile' : user["profile"],
# 'professional' : user["professional"],
}

Expand Down Expand Up @@ -175,6 +174,28 @@ def wrapper(*args, **kwargs):



def guest_required(func):
"""
Check if user is not logged yet in access_token
and has a 'guest' or 'anonymous' role
"""
@wraps(func)
def wrapper(*args, **kwargs):

log.debug("-@- anonymous checker")

verify_jwt_in_request()
claims = get_jwt_claims()
log.debug("claims : \n %s", pformat(claims) )

if claims["auth"]["role"] not in ['admin', 'guest', 'registred', "staff" ] :
return { "msg" : "Registred users only !!! " }, 403
else:
return func(*args, **kwargs)

return wrapper


def admin_required(func):
"""
Check if user has admin level in access_token
Expand Down
4 changes: 4 additions & 0 deletions solidata_api/_choices/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

from ._choices_files import *
from ._choices_licences import *
from ._choices_user import *
22 changes: 22 additions & 0 deletions solidata_api/_choices/_choices_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-

"""
_choices_files.py
- all choices related to files
"""


from log_config import log, pformat

log.debug("... loading _choices_files.py ...")


authorized_filetypes = [
"csv", "xls", "xlsx", "xml" # ...
]

authorized_mimetype = [
"application/xls", "application/vnd.ms-excel",
"text/csv", "application/csv", "text/x-csv",
"application/xml",
]
File renamed without changes.
File renamed without changes.
Empty file.
2 changes: 2 additions & 0 deletions solidata_api/_core/queries_db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### declaring collections as app variables

mongo_tags = mongo.db[ app.config["MONGO_COLL_TAGS"] ]
mongo_users = mongo.db[ app.config["MONGO_COLL_USERS"] ]
mongo_projects = mongo.db[ app.config["MONGO_COLL_PROJECTS"] ]
mongo_datamodels_templates = mongo.db[ app.config["MONGO_COLL_DATAMODELS_TEMPLATES"] ]
Expand All @@ -35,6 +36,7 @@


db = {
"mongo_tags" : mongo_tags,
"mongo_users" : mongo_users,
"mongo_projects" : mongo_projects,
"mongo_datamodels_templates" : mongo_datamodels_templates,
Expand Down
3 changes: 2 additions & 1 deletion solidata_api/_core/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

from .app_logs import *
from .app_logs import *
from .app_auth_files import *
22 changes: 22 additions & 0 deletions solidata_api/_core/utils/app_auth_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-

"""
app_auth_files.py
"""


from log_config import log, pformat

log.debug("... loading app_auth_files.py ...")

from werkzeug.utils import secure_filename
from solidata_api._choices import *


def get_file_extension(filename) :
return filename.rsplit('.', 1)[1].lower()


def allowed_file(filename):
return '.' in filename and \
get_file_extension(filename) in authorized_filetypes
22 changes: 17 additions & 5 deletions solidata_api/_core/utils/app_logs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# -*- encoding: utf-8 -*-

"""
app_logs.py
"""


from log_config import log, pformat

log.debug("... loading app_logs.py ...")


from datetime import datetime, timedelta

def create_modif_log( doc,
action,
field="log",
nested_field="modified_log",
dt=datetime.utcnow(),
by=None ) :
dt = datetime.utcnow(),
by = None,
val = None,
) :
"""
Create a simple dict for modif_log
and insert it into document
Expand All @@ -20,7 +29,10 @@ def create_modif_log( doc,
### add author of modif
if by != None :
modif["modif_by"] = by

if val != None :
modif["modif_val"] = val

doc[field][nested_field].insert(0, modif)
doc["modif_log"].insert(0, modif)

return doc
86 changes: 86 additions & 0 deletions solidata_api/_models/models_dataset_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- encoding: utf-8 -*-

"""
_models/models_projects.py
- provides the models for all api routes
"""

from log_config import log, pformat

log.debug("... loading models_projects.py ...")


from flask_restplus import fields

### import data serializers
from solidata_api._serializers.schema_logs import *
from solidata_api._serializers.schema_generic import *
from solidata_api._serializers.schema_projects import *

### import generic models functions
from solidata_api._models.models_generic import *

### create models from serializers
# nested models : https://github.com/noirbizarre/flask-restplus/issues/8
# model_user_infos = ns.model( "User model", user_infos) #, mask="{name,surname,email}" )



class Dsi_infos :
"""
Model to display / marshal
specific projects's infos
"""

def __init__(self, ns_) :

### SELF MODULES
self.basic_infos = create_model_basic_infos(ns_, model_name="Dsi_infos")
self.log = create_model_log(ns_, model_name="Dsi_log",include_is_running=True, include_is_loaded=True )
self.modif_log = create_model_modif_log(ns_, model_name="Dsi_modif_log")
self.specs = create_model_specs(ns_, model_name="Dsi_specs", include_src_link=True)
self.team = create_model_team(ns_, model_name="Dsi_team")
self.uses = create_uses(ns_, model_name="Dsi_uses", schema_list=["usr","prj"])

### IN / complete data to enter in DB
self.mod_complete_in = ns_.model('Project_in', {

'infos' : self.basic_infos,
'specs' : self.specs ,
'log' : self.log ,
'modif_log' : self.modif_log ,
'uses' : self.uses,

### team and edition levels
'team' : self.team ,

})

### OUT / complete data to enter in DB
# self.mod_complete_out = ns_.model('Project_out', {

# 'infos' : self.basic_infos,
# 'log' : self.project_log ,

# ### team and edition levels
# # 'project_team' : fields.List(self.collaborator) ,
# 'proj_team' : self.collaborators ,

# ### datasets
# 'datamodel' : oid,
# 'dataset_inputs' : fields.List(oid),
# 'correspondance_dicts' : fields.List(oid),
# 'recipes' : fields.List(oid),

# })


@property
def model_complete_in(self):
return self.mod_complete_in

# @property
# def model_complete_out(self):
# return self.mod_complete_out


Loading

0 comments on commit c777a83

Please sign in to comment.