Ejemplo n.º 1
0
def dbtdel(desc):
    if request.method == "DELETE":
        try:
            auth_token = request.headers.get('Authorization')
            current_user_id = Users.decode_auth_token(auth_token)
            del_data_table_id = request.json.get("dmp_data_table_id")
            if del_data_table_id:
                del_data_table = DataTable.get(del_data_table_id)
                if del_data_table:
                    is_user = Users.get(
                        DataTable.get(del_data_table_id).dmp_user_id
                    ).id == current_user_id
                    is_user_leader = Users.get(
                        DataTable.get(del_data_table_id).dmp_user_id
                    ).leader_dmp_user_id == current_user_id
                    is_admin = Users.get(current_user_id).dmp_group_id == 1
                    if is_user or is_user_leader or is_admin:
                        del_data_table.delete()
                        current_app.logger.info("del db table complete!")
                        return resp_hanlder(result="OK")
                    else:
                        return resp_hanlder(code=302)
                else:
                    return resp_hanlder(code=404)
            else:
                return resp_hanlder(code=101)
        except Exception as err:
            return resp_hanlder(err=err)
Ejemplo n.º 2
0
def form_permission(user_id):
    user = Users.get(user_id)
    usergroup_id = user.groups.id
    approve_id = Permissions.query.filter_by(route="/form/approve/").first().id
    p_ids = [p.id for p in user.groups.permissions]
    if usergroup_id == 1:
        return 3
    elif approve_id in p_ids:
        return 2
    elif approve_id not in p_ids:
        return 1
Ejemplo n.º 3
0
def info(desc):
    if request.method == "GET":
        auth_token = request.headers.get('Authorization')
        current_user_id = Users.decode_auth_token(auth_token)
        try:
            database_id = request.json.get("dmp_database_id") if request.json else None
            if database_id:
                data = Database.query.get(database_id).__json__()
            else:
                data = []
                if Users.get(current_user_id).dmp_group_id == 1:
                    data = [d.__json__() for d in Database.query.all()]
                else:
                    user_ids = [u.id for u in Users.query.filter_by(leader_dmp_user_id=current_user_id).all()]
                    user_ids.append(current_user_id)
                    # current_app.logger.info(user_ids)
                    data = [d.__json__() for d in
                            Database.query.filter(Database.dmp_user_id.in_(user_ids) | Database.ispublic == True).all()]
                # current_app.logger.info(data)
            return resp_hanlder(result=data)
        except Exception as err:
            return resp_hanlder(code=999, err=err)
Ejemplo n.º 4
0
def put(desc):
    if request.method == "PUT":
        auth_token = request.headers.get('Authorization')
        current_user_id = Users.decode_auth_token(auth_token)
        dbt_info = request.json
        dbt_id = dbt_info.get("dmp_data_table_id")

        dbt = DataTable.get(dbt_id)
        if dbt:
            dmp_user_id = dbt.dmp_user_id
            if current_user_id == 1 or current_user_id == dmp_user_id or Users.get(
                    dmp_user_id).leader_dmp_user_id == current_user_id:
                if "dmp_data_table_name" in dbt_info.keys():
                    dbt.dmp_data_table_name = dbt_info.get(
                        "dmp_data_table_name")
                if "description" in dbt_info.keys():
                    dbt.description = dbt_info.get("description")
                dbt.put()
                return resp_hanlder(result="OK!")
            else:
                return resp_hanlder(code=301)
        else:
            return resp_hanlder(code=404)
Ejemplo n.º 5
0
 def dmp_user_name(self):
     from dmp.models import Users
     u = Users.get(self.dmp_user_id)
     user_name = u.dmp_username if u else "-"
     return user_name
Ejemplo n.º 6
0
 def approve_dmp_username(self):
     from dmp.models import Users
     u = Users.get(self.approve_dmp_user_id)
     a_u_name = u.dmp_username if u else "-"
     return a_u_name
Ejemplo n.º 7
0
 def submit_dmp_username(self):
     from dmp.models import Users
     u = Users.get(self.submit_dmp_user_id)
     s_u_name = u.dmp_username if u else "-"
     return s_u_name