diff --git a/resources/config b/resources/config index 50757de..3fea7ad 160000 --- a/resources/config +++ b/resources/config @@ -1 +1 @@ -Subproject commit 50757def4650ffae1289208215ed83fe008e9ad6 +Subproject commit 3fea7ad570dae08e971db8a4abe3a14b6b7324d1 diff --git a/src/handlerv2/auditagreementlist_handler.go b/src/handlerv2/auditagreementlist_handler.go new file mode 100644 index 0000000..f21c182 --- /dev/null +++ b/src/handlerv2/auditagreementlist_handler.go @@ -0,0 +1,14 @@ +package handlerv2 + +import ( + "net/http" + + "github.com/bb-consent/api/src/config" +) + +func AuditAgreementList(w http.ResponseWriter, r *http.Request) { + + w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON) + w.WriteHeader(http.StatusOK) + +} diff --git a/src/handlerv2/auditconsentrecordlist_handler.go b/src/handlerv2/auditconsentrecordlist_handler.go new file mode 100644 index 0000000..dc19570 --- /dev/null +++ b/src/handlerv2/auditconsentrecordlist_handler.go @@ -0,0 +1,14 @@ +package handlerv2 + +import ( + "net/http" + + "github.com/bb-consent/api/src/config" +) + +func AuditConsentRecordList(w http.ResponseWriter, r *http.Request) { + + w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON) + w.WriteHeader(http.StatusOK) + +} diff --git a/src/handlerv2/auditconsentrecordread_handler.go b/src/handlerv2/auditconsentrecordread_handler.go new file mode 100644 index 0000000..5097000 --- /dev/null +++ b/src/handlerv2/auditconsentrecordread_handler.go @@ -0,0 +1,14 @@ +package handlerv2 + +import ( + "net/http" + + "github.com/bb-consent/api/src/config" +) + +func AuditConsentRecordRead(w http.ResponseWriter, r *http.Request) { + + w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON) + w.WriteHeader(http.StatusOK) + +} diff --git a/src/handlerv2/auditreadrecord_handler.go b/src/handlerv2/auditreadrecord_handler.go new file mode 100644 index 0000000..af96687 --- /dev/null +++ b/src/handlerv2/auditreadrecord_handler.go @@ -0,0 +1,14 @@ +package handlerv2 + +import ( + "net/http" + + "github.com/bb-consent/api/src/config" +) + +func AuditReadRecord(w http.ResponseWriter, r *http.Request) { + + w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON) + w.WriteHeader(http.StatusOK) + +} diff --git a/src/handlerv2/getorglogs_handler.go b/src/handlerv2/getorglogs_handler.go new file mode 100644 index 0000000..1b772e4 --- /dev/null +++ b/src/handlerv2/getorglogs_handler.go @@ -0,0 +1,56 @@ +package handlerv2 + +import ( + "encoding/json" + "fmt" + "net/http" + + "github.com/bb-consent/api/src/actionlog" + "github.com/bb-consent/api/src/common" + "github.com/bb-consent/api/src/config" + "github.com/gorilla/mux" +) + +type orgLog struct { + ID string + Type int + TypeStr string + UserID string + UserName string + TimeStamp string + Log string +} +type orgLogsResp struct { + Logs []orgLog + Links common.PaginationLinks +} + +// GetOrgLogs Get action logs for the organization +func GetOrgLogs(w http.ResponseWriter, r *http.Request) { + orgID := mux.Vars(r)["orgID"] + + startID, limit := common.ParsePaginationQueryParameters(r) + if limit == 0 { + limit = 50 + } + + sanitizedOrgId := common.Sanitize(orgID) + + logs, lastID, err := actionlog.GetAccessLogByOrgID(sanitizedOrgId, startID, limit) + if err != nil { + m := fmt.Sprintf("Failed to get logs for organization: %v", orgID) + common.HandleError(w, http.StatusInternalServerError, m, err) + return + } + + var ls orgLogsResp + for _, l := range logs { + ls.Logs = append(ls.Logs, orgLog{ID: l.ID.Hex(), Type: l.Type, TypeStr: l.TypeStr, + UserID: l.UserID, UserName: l.UserName, TimeStamp: l.ID.Timestamp().String(), Log: l.Action}) + } + + ls.Links = common.CreatePaginationLinks(r, startID, lastID, limit) + response, _ := json.Marshal(ls) + w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON) + w.Write(response) +} diff --git a/src/httppathsv2/audit_paths.go b/src/httppathsv2/audit_paths.go index 4d9bf1a..a7ee263 100644 --- a/src/httppathsv2/audit_paths.go +++ b/src/httppathsv2/audit_paths.go @@ -1 +1,9 @@ package httppathsv2 + +const AuditConsentRecordList = "/v2/audit/consentrecords/" +const AuditConsentRecordRead = "/v2/audit/consentrecord/{consentRecordId}/" +const AuditAgreementList = "/v2/audit/agreements/" +const AuditReadRecord = "/v2/audit/agreement/{agreementId}/" + +// organization action logs +const GetOrgLogs = "/v2/audit/admin/logs" diff --git a/src/httppathsv2/routes.go b/src/httppathsv2/routes.go index d1ee2cf..9f707ca 100644 --- a/src/httppathsv2/routes.go +++ b/src/httppathsv2/routes.go @@ -81,4 +81,14 @@ func SetRoutes(r *mux.Router, e *casbin.Enforcer) { r.Handle(ServiceUpdateIndividualConsentRecord, m.Chain(handler.ServiceCreateIndividualConsentRecord, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("PUT") r.Handle(ServiceListIndividualRecordList, m.Chain(handler.ServiceListIndividualRecordList, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET") r.Handle(ServiceReadIndividualRecordRead, m.Chain(handler.ServiceReadIndividualRecordRead, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET") + + // Audit api(s) + + r.Handle(AuditConsentRecordList, m.Chain(handler.AuditConsentRecordList, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET") + r.Handle(AuditConsentRecordRead, m.Chain(handler.AuditConsentRecordRead, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET") + r.Handle(AuditAgreementList, m.Chain(handler.AuditAgreementList, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET") + r.Handle(AuditReadRecord, m.Chain(handler.AuditReadRecord, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET") + + // organization action logs + r.Handle(GetOrgLogs, m.Chain(handler.GetOrgLogs, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET") }