133 lines
2.8 KiB
Plaintext
133 lines
2.8 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
userorgid = await get_userorgid()
|
|
if not userorgid:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Authorization Error",
|
|
"timeout":3,
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"message":"Please login"
|
|
}
|
|
}
|
|
ns['org_id'] = userorgid
|
|
ns['userorgid'] = userorgid
|
|
|
|
debug(f'get_sd_project_repos.dspy:{ns=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
|
|
ns['sort'] = ["created_at desc"]
|
|
|
|
|
|
|
|
sql = '''select * from sd_project_repos where 1=1 [[filterstr]]'''
|
|
|
|
|
|
filterjson = None
|
|
fields_str=r'''[
|
|
{
|
|
"name": "id",
|
|
"title": "主键ID",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "project_id",
|
|
"title": "项目ID",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "repo_name",
|
|
"title": "仓库别名",
|
|
"type": "str",
|
|
"length": 100,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "repo_url",
|
|
"title": "Git地址",
|
|
"type": "str",
|
|
"length": 500,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "default_branch",
|
|
"title": "默认分支",
|
|
"type": "str",
|
|
"length": 100,
|
|
"nullable": "no",
|
|
"default": "'main'"
|
|
},
|
|
{
|
|
"name": "local_path",
|
|
"title": "本地相对路径",
|
|
"type": "str",
|
|
"length": 200
|
|
},
|
|
{
|
|
"name": "org_id",
|
|
"title": "组织ID",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no",
|
|
"default": "'0'"
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"title": "创建时间",
|
|
"type": "timestamp",
|
|
"nullable": "no"
|
|
}
|
|
]'''
|
|
ori_fields = json.loads(fields_str)
|
|
fields = [ f['name'] for f in ori_fields ]
|
|
filterjson = default_filterjson(fields, ns)
|
|
|
|
|
|
# 确保 logined 过滤条件始终生效
|
|
if filterjson:
|
|
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
|
|
filterjson = {'AND': [filterjson] if filterjson else []}
|
|
|
|
filterjson['AND'].append({'field': 'org_id', 'op': '=', 'var': '__logined_orgid__'})
|
|
ns['__logined_orgid__'] = userorgid
|
|
|
|
|
|
|
|
filterdic = ns.copy()
|
|
filterdic['filterstr'] = ''
|
|
filterdic['userorgid'] = '${userorgid}$'
|
|
filterdic['userid'] = '${userid}$'
|
|
if filterjson:
|
|
dbf = DBFilter(filterjson)
|
|
conds = dbf.gen(ns)
|
|
if conds:
|
|
ns.update(dbf.consts)
|
|
conds = f' and {conds}'
|
|
filterdic['filterstr'] = conds
|
|
ac = ArgsConvert('[[', ']]')
|
|
vars = ac.findAllVariables(sql)
|
|
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
|
|
filterdic.update(NameSpace)
|
|
sql = ac.convert(sql, filterdic)
|
|
|
|
debug(f'{sql=}')
|
|
db = DBPools()
|
|
dbname = get_module_dbname('pipeline-sdlc')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
} |