Skip to content

Commit

Permalink
Merge pull request #269 from saidone75/dev
Browse files Browse the repository at this point in the history
list-node-audit-entry
  • Loading branch information
saidone75 authored May 18, 2024
2 parents 3fd5d27 + ba23eca commit 188c923
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
43 changes: 31 additions & 12 deletions src/cral/api/core/audit.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
GetAuditEntryQueryParams
ListAuditApplicationEntriesQueryParams
ListAuditApplicationsQueryParams
ListNodeAuditEntryQueryParams
UpdateAuditApplicationInfoBody
UpdateAuditApplicationInfoQueryParams)))

Expand Down Expand Up @@ -81,22 +82,22 @@
:content-type :json}
opts)))

(defn list-audit-application-entries
"Gets a list of audit entries for audit application `auditApplication-id`.
(defn list-application-audit-entries
"Gets a list of audit entries for audit application `audit-application-id`.
You can use the include parameter in `query-params` to return additional values information.
The list can be filtered by one or more of:
- **created-by-user** person id
- **created-at** inclusive time period
- **createdByUser** person id
- **createdAt** inclusive time period
- **id** inclusive range of ids
- **values-key** audit entry values contains the exact matching key
- **values-value** audit entry values contains the exact matching value
- **valuesKey** audit entry values contains the exact matching key
- **valuesValue** audit entry values contains the exact matching value
- SiteContributor\n\n
The default sort order is **created-at** ascending, but you can use an optional **ASC** or **DESC** modifier to specify an ascending or descending sort order.
For example, specifying `order-by=created-at DESC` returns audit entries in descending **created-at** order.
The default sort order is **createdAt** ascending, but you can use an optional **ASC** or **DESC** modifier to specify an ascending or descending sort order.
For example, specifying `order-by=createdAt DESC` returns audit entries in descending **createdAt** order.
You must have admin rights to retrieve audit information.\\
More info [here](https://api-explorer.alfresco.com/api-explorer/?urls.primaryName=Core%20API#/audit/listAuditEntriesForAuditApp)."
([^Ticket ticket ^String audit-application-id]
(list-audit-application-entries ticket audit-application-id nil))
(list-application-audit-entries ticket audit-application-id nil))
([^Ticket ticket ^String audit-application-id ^ListAuditApplicationEntriesQueryParams query-params & [^PersistentHashMap opts]]
(utils/call-rest
client/get
Expand All @@ -105,9 +106,10 @@
{:query-params query-params}
opts)))

(defn delete-audit-application-entries
"Permanently delete audit entries for an audit application `auditApplication-id`.
The `where` clause must be specified, either with an inclusive time period or for an inclusive range of ids. The delete is within the context of the given audit application.
(defn delete-application-audit-entries
"Permanently delete audit entries for an audit application `audit-application-id`.
The `where` clause must be specified, either with an inclusive time period or for an inclusive range of ids.
The delete is within the context of the given audit application.
For example:
- ```where=(createdAt BETWEEN ('2024-01-01T00:00:00' , '2024-02-01T00:00:00'))```
- ```where=(id BETWEEN ('1234', '4321'))```\n\n
Expand Down Expand Up @@ -146,3 +148,20 @@
{}
opts)))

(defn list-node-audit-entry
"Gets a list of audit entries for node `node-id`.
The list can be filtered by **createdByUser** and for a given inclusive time period.
The default sort order is **createdAt** ascending, but you can use an optional **ASC** or **DESC** modifier to specify an ascending or descending sort order.
For example, specifying `order-by=createdAt DESC` returns audit entries in descending **createdAt** order.
This relies on the pre-configured 'alfresco-access' audit application.\\
More info [here](https://api-explorer.alfresco.com/api-explorer/?urls.primaryName=Core%20API#/audit/listAuditEntriesForNode)."
([^Ticket ticket ^String node-id]
(list-node-audit-entry ticket node-id nil))
([^Ticket ticket ^String node-id ^ListNodeAuditEntryQueryParams query-params & [^PersistentHashMap opts]]
(utils/call-rest
client/get
(format "%s/nodes/%s/audit-entries" (config/get-url 'core) node-id)
ticket
{:query-params query-params}
opts)))

8 changes: 8 additions & 0 deletions src/cral/model/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
(defrecord GetAuditEntryQueryParams
[^PersistentVector fields])

(defrecord ListNodeAuditEntryQueryParams
[^Integer skip-count
^PersistentVector order-by
^Integer max-items
^String where
^PersistentVector include
^PersistentVector fields])

;; activities
(defrecord ListActivitiesQueryParams
[^Integer skip-count
Expand Down
8 changes: 4 additions & 4 deletions test/cral/audit_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@
(let [ticket (get-in (auth/create-ticket c/user c/password) [:body :entry])
;; get an audit application id
audit-application-id (get-in (rand-nth (get-in (audit/list-audit-applications ticket) [:body :list :entries])) [:entry :id])]
(is (= (:status (audit/list-audit-application-entries ticket audit-application-id)) 200))))
(is (= (:status (audit/list-application-audit-entries ticket audit-application-id)) 200))))

(deftest delete-audit-application-entries-test
(let [ticket (get-in (auth/create-ticket c/user c/password) [:body :entry])
;; get an audit application id
audit-application-id (get-in (rand-nth (get-in (audit/list-audit-applications ticket) [:body :list :entries])) [:entry :id])]
(is (= (:status (->> (model/map->DeleteAuditApplicationEntriesQueryParams
{:where "(createdAt BETWEEN ('2024-01-01T00:00:00', '2024-02-01T00:00:00'))"})
(audit/delete-audit-application-entries ticket audit-application-id)) 204)))))
(audit/delete-application-audit-entries ticket audit-application-id)) 204)))))

(deftest get-audit-entry-test
(let [ticket (get-in (auth/create-ticket c/user c/password) [:body :entry])
;; get an audit application id
list-audit-application-entries-response (audit/list-audit-application-entries ticket alfresco-access)
list-audit-application-entries-response (audit/list-application-audit-entries ticket alfresco-access)
entry (rand-nth (get-in list-audit-application-entries-response [:body :list :entries]))
get-audit-entry-response (audit/get-audit-entry ticket alfresco-access (get-in entry [:entry :id]))]
(is (= (:status get-audit-entry-response) 200))))

(deftest delete-audit-entry-test
(let [ticket (get-in (auth/create-ticket c/user c/password) [:body :entry])
;; get an audit application id
list-audit-application-entries-response (audit/list-audit-application-entries ticket alfresco-access)
list-audit-application-entries-response (audit/list-application-audit-entries ticket alfresco-access)
entry (rand-nth (get-in list-audit-application-entries-response [:body :list :entries]))]
(is (= (:status (audit/delete-audit-entry ticket alfresco-access (get-in entry [:entry :id]))) 204))))

0 comments on commit 188c923

Please sign in to comment.