Browse Source

feat(nc-gui): add project audit list api

pull/8836/head
Ramesh Mane 1 week ago
parent
commit
fe52c26689
  1. 15
      packages/nocodb/src/controllers/audits.controller.ts
  2. 91
      packages/nocodb/src/models/Audit.ts
  3. 136
      packages/nocodb/src/schema/swagger-v2.json
  4. 136
      packages/nocodb/src/schema/swagger.json
  5. 8
      packages/nocodb/src/services/audits.service.ts

15
packages/nocodb/src/controllers/audits.controller.ts

@ -66,4 +66,19 @@ export class AuditsController {
},
);
}
@Get(['/api/v1/db/meta/projects/audits/', '/api/v2/meta/projects/audits/'])
@Acl('projectAuditList')
async projectAuditList(@Req() req: NcRequest) {
return new PagedResponseImpl(
await this.auditsService.projectAuditList({
query: req.query,
}),
{
count: await this.auditsService.projectAuditCount({
query: req.query,
}),
...req.query,
},
);
}
}

91
packages/nocodb/src/models/Audit.ts

@ -253,4 +253,95 @@ export default class Audit implements AuditType {
.first()
)?.count;
}
static async projectAuditList({
limit = 25,
offset = 0,
sourceId,
user,
baseId,
type,
startDate,
endDate,
orderBy,
}: {
limit?: number;
offset?: number;
sourceId?: string;
user?: string;
baseId?: string;
type?: string;
startDate?: string;
endDate?: string;
orderBy?: {
created_at?: 'asc' | 'desc';
user?: 'asc' | 'desc';
};
}) {
return await Noco.ncMeta.metaList2(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.AUDIT,
{
limit,
offset,
condition: {
...(user ? { user: user } : {}),
...(baseId ? { base_id: baseId } : {}),
...(sourceId ? { source_id: sourceId } : {}),
...(type ? { op_type: type } : {}),
},
orderBy: {
...(orderBy?.created_at
? { created_at: orderBy?.created_at }
: !orderBy?.user
? { created_at: 'desc' }
: {}),
...(orderBy?.user ? { user: orderBy?.user } : {}),
},
xcCondition: {
_and: [
...(startDate ? [{ created_at: { ge: startDate } }] : []),
...(endDate ? [{ created_at: { le: endDate } }] : []),
],
},
},
);
}
static async projectAuditCount({
user,
baseId,
sourceId,
type,
startDate,
endDate,
}: {
user?: string;
baseId?: string;
sourceId?: string;
type?: string;
startDate?: string;
endDate?: string;
}): Promise<number> {
return await Noco.ncMeta.metaCount(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.AUDIT,
{
condition: {
...(user ? { user: user } : {}),
...(baseId ? { base_id: baseId } : {}),
...(sourceId ? { source_id: sourceId } : {}),
...(type ? { op_type: type } : {}),
},
xcCondition: {
_and: [
...(startDate ? [{ created_at: { ge: startDate } }] : []),
...(endDate ? [{ created_at: { le: endDate } }] : []),
],
},
},
);
}
}

136
packages/nocodb/src/schema/swagger-v2.json

@ -8987,6 +8987,142 @@
]
}
},
"/api/v2/meta/projects/audits": {
"parameters": [
{
"$ref": "#/components/parameters/xc-auth"
}
],
"get": {
"summary": "List Audits in Project",
"operationId": "project-audit-list",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"list": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/components/schemas/Audit"
}
},
"pageInfo": {
"$ref": "#/components/schemas/Paginated"
}
},
"required": [
"list",
"pageInfo"
]
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"description": "List all audit data in the given project",
"parameters": [
{
"schema": {
"type": "integer",
"minimum": 0
},
"in": "query",
"name": "offset"
},
{
"schema": {
"type": "integer",
"minimum": 1
},
"in": "query",
"name": "limit"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "user"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "type"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "baseId"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "sourceId"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "startDate"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "endDate"
},
{
"schema": {
"properties": {
"created_at": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
},
"user": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
}
},
"type": "object"
},
"in": "query",
"name": "orderBy"
},
{
"$ref": "#/components/parameters/xc-auth"
}
],
"tags": [
"Utils"
]
}
}
"/api/v2/meta/bases/{baseId}/audits": {
"parameters": [
{

136
packages/nocodb/src/schema/swagger.json

@ -14082,6 +14082,142 @@
]
}
},
"/api/v1/db/meta/projects/audits": {
"parameters": [
{
"$ref": "#/components/parameters/xc-auth"
}
],
"get": {
"summary": "List Audits in Project",
"operationId": "project-audit-list",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"list": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/components/schemas/Audit"
}
},
"pageInfo": {
"$ref": "#/components/schemas/Paginated"
}
},
"required": [
"list",
"pageInfo"
]
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"description": "List all audit data in the given project",
"parameters": [
{
"schema": {
"type": "integer",
"minimum": 0
},
"in": "query",
"name": "offset"
},
{
"schema": {
"type": "integer",
"minimum": 1
},
"in": "query",
"name": "limit"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "user"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "type"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "baseId"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "sourceId"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "startDate"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "endDate"
},
{
"schema": {
"properties": {
"created_at": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
},
"user": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
}
},
"type": "object"
},
"in": "query",
"name": "orderBy"
},
{
"$ref": "#/components/parameters/xc-auth"
}
],
"tags": [
"Utils"
]
}
}
"/api/v1/db/meta/projects/{baseId}/audits": {
"parameters": [
{

8
packages/nocodb/src/services/audits.service.ts

@ -84,4 +84,12 @@ export class AuditsService {
async sourceAuditCount(param: { query: any; sourceId: string }) {
return await Audit.sourceAuditCount(param.sourceId);
}
async projectAuditList(param: { query: any }) {
return await Audit.projectAuditList(param.query);
}
async projectAuditCount(param: { query?: any }) {
return await Audit.projectAuditCount(param.query);
}
}

Loading…
Cancel
Save