-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #190 Align APIs to GovStack: Change URL paths for config endpoints
- Loading branch information
1 parent
9521be2
commit 201a850
Showing
65 changed files
with
3,311 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/handler/actionlog_handler.go → src/handlerv1/actionlog_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/consent_handler.go → src/handlerv1/consent_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/consent_handler_helper.go → src/handlerv1/consent_handler_helper.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"time" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/consenthistory_handler.go → src/handlerv1/consenthistory_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/datarequest_handler.go → src/handlerv1/datarequest_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"bytes" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/mobile_handler.go → src/handlerv1/mobile_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/notification_handler.go → src/handlerv1/notification_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import "github.com/bb-consent/api/src/org" | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/handler/orgType_handler.go → src/handlerv1/orgType_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"bytes" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/organization_handler.go → src/handlerv1/organization_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
2 changes: 1 addition & 1 deletion
2
src/handler/webhooks_handler.go → src/handlerv1/webhooks_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlerv1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package handlerv2 | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/asaskevich/govalidator" | ||
"github.com/bb-consent/api/src/common" | ||
"github.com/bb-consent/api/src/config" | ||
"github.com/bb-consent/api/src/org" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
type purpose struct { | ||
Name string `valid:"required"` | ||
Description string `valid:"required"` | ||
LawfulBasisOfProcessing int | ||
PolicyURL string `valid:"required"` | ||
AttributeType int | ||
Jurisdiction string | ||
Disclosure string | ||
IndustryScope string | ||
DataRetention org.DataRetention | ||
Restriction string | ||
Shared3PP bool | ||
SSIID string | ||
} | ||
|
||
type addPurposeReq struct { | ||
purpose | ||
} | ||
|
||
// Check if the lawful usage ID provided is valid | ||
func isValidLawfulBasisOfProcessing(lawfulBasis int) bool { | ||
isFound := false | ||
for _, lawfulBasisOfProcessingMapping := range org.LawfulBasisOfProcessingMappings { | ||
if lawfulBasisOfProcessingMapping.ID == lawfulBasis { | ||
isFound = true | ||
break | ||
} | ||
} | ||
|
||
return isFound | ||
} | ||
|
||
// Fetch the lawful usage based on the lawful basis ID | ||
func getLawfulUsageByLawfulBasis(lawfulBasis int) bool { | ||
if lawfulBasis == org.ConsentBasis { | ||
return false | ||
} else { | ||
return true | ||
} | ||
} | ||
|
||
// AddDataAgreement Adds a single data agreement to the organization | ||
func AddDataAgreement(w http.ResponseWriter, r *http.Request) { | ||
organizationID := r.Header.Get(config.OrganizationId) | ||
|
||
o, err := org.Get(organizationID) | ||
if err != nil { | ||
m := fmt.Sprintf("Failed to fetch organization: %v", organizationID) | ||
common.HandleError(w, http.StatusInternalServerError, m, err) | ||
return | ||
} | ||
|
||
var pReq addPurposeReq | ||
b, _ := ioutil.ReadAll(r.Body) | ||
defer r.Body.Close() | ||
|
||
json.Unmarshal(b, &pReq) | ||
|
||
// validating request payload | ||
valid, err := govalidator.ValidateStruct(pReq) | ||
if !valid { | ||
log.Printf("Missing mandatory fields for a adding consent purpose to org") | ||
common.HandleError(w, http.StatusBadRequest, err.Error(), err) | ||
return | ||
} | ||
|
||
// Proceed if lawful basis of processing provided is valid | ||
if !isValidLawfulBasisOfProcessing(pReq.LawfulBasisOfProcessing) { | ||
m := fmt.Sprintf("Invalid lawful basis of processing provided") | ||
common.HandleError(w, http.StatusBadRequest, m, err) | ||
return | ||
} | ||
|
||
tempLawfulUsage := getLawfulUsageByLawfulBasis(pReq.LawfulBasisOfProcessing) | ||
|
||
newPurpose := org.Purpose{ | ||
ID: primitive.NewObjectID().Hex(), | ||
Name: pReq.Name, | ||
Description: pReq.Description, | ||
LawfulUsage: tempLawfulUsage, | ||
LawfulBasisOfProcessing: pReq.LawfulBasisOfProcessing, | ||
PolicyURL: pReq.PolicyURL, | ||
AttributeType: pReq.AttributeType, | ||
Jurisdiction: pReq.Jurisdiction, | ||
Disclosure: pReq.Disclosure, | ||
IndustryScope: pReq.IndustryScope, | ||
DataRetention: pReq.DataRetention, | ||
Restriction: pReq.Restriction, | ||
Shared3PP: pReq.Shared3PP, | ||
SSIID: pReq.SSIID, | ||
} | ||
o.Purposes = append(o.Purposes, newPurpose) | ||
|
||
_, err = org.UpdatePurposes(o.ID.Hex(), o.Purposes) | ||
if err != nil { | ||
m := fmt.Sprintf("Failed to update purpose to organization: %v", o.Name) | ||
common.HandleError(w, http.StatusInternalServerError, m, err) | ||
return | ||
} | ||
/* | ||
u, err := user.Get(token.GetUserID(r)) | ||
if err != nil { | ||
//notifications.SendPurposeUpdateNotification(u, o.ID.Hex(), ) | ||
} | ||
*/ | ||
response, _ := json.Marshal(newPurpose) | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusCreated) | ||
w.Write(response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package handlerv2 | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/asaskevich/govalidator" | ||
"github.com/bb-consent/api/src/common" | ||
"github.com/bb-consent/api/src/config" | ||
"github.com/bb-consent/api/src/org" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
type template struct { | ||
Consent string `valid:"required"` | ||
PurposeIDs []string `valid:"required"` | ||
} | ||
type templateReq struct { | ||
Templates []template | ||
} | ||
|
||
// AddDataAttribute Adds an organization data attribute | ||
func AddDataAttribute(w http.ResponseWriter, r *http.Request) { | ||
organizationID := r.Header.Get(config.OrganizationId) | ||
|
||
o, err := org.Get(organizationID) | ||
if err != nil { | ||
m := fmt.Sprintf("Failed to fetch organization: %v", organizationID) | ||
common.HandleError(w, http.StatusInternalServerError, m, err) | ||
return | ||
} | ||
|
||
var tReq templateReq | ||
b, _ := ioutil.ReadAll(r.Body) | ||
defer r.Body.Close() | ||
|
||
json.Unmarshal(b, &tReq) | ||
|
||
// validating request payload | ||
valid, err := govalidator.ValidateStruct(tReq) | ||
if !valid { | ||
log.Printf("Missing mandatory fields for adding consent template to org: %v", organizationID) | ||
common.HandleError(w, http.StatusBadRequest, err.Error(), err) | ||
return | ||
} | ||
|
||
// validating purposeIDs provided | ||
for _, t := range tReq.Templates { | ||
// checking if purposeID provided exist in the org | ||
for _, p := range t.PurposeIDs { | ||
_, err = org.GetPurpose(organizationID, p) | ||
if err != nil { | ||
m := fmt.Sprintf("Invalid purposeID:%v provided;Failed to update templates to organization: %v", p, o.Name) | ||
common.HandleError(w, http.StatusBadRequest, m, err) | ||
return | ||
} | ||
} | ||
|
||
// Appending the new template to existing org templates | ||
o.Templates = append(o.Templates, org.Template{ | ||
ID: primitive.NewObjectID().Hex(), | ||
Consent: t.Consent, | ||
PurposeIDs: t.PurposeIDs, | ||
}) | ||
} | ||
|
||
orgResp, err := org.UpdateTemplates(o.ID.Hex(), o.Templates) | ||
if err != nil { | ||
m := fmt.Sprintf("Failed to update templates to organization: %v", o.Name) | ||
common.HandleError(w, http.StatusNotFound, m, err) | ||
return | ||
} | ||
|
||
response, _ := json.Marshal(organization{orgResp}) | ||
w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON) | ||
w.WriteHeader(http.StatusCreated) | ||
w.Write(response) | ||
} |
Oops, something went wrong.