Skip to content

Commit

Permalink
Add #166 Ability to configure privacy dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 25, 2023
1 parent 9bf79a6 commit 8c3543a
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ type User struct {
Password string `valid:"required"`
}

type PrivacyDashboard struct {
Hostname string
Version string
}

// Configuration data type
type Configuration struct {
DataBase struct {
Expand All @@ -97,16 +102,17 @@ type Configuration struct {
UserName string
Password string
}
ApplicationMode string
Organization Organization
Type OrgType
User User
ApiSecretKey string
Iam Iam
Twilio Twilio
Firebase Firebase
Smtp SmtpConfig
Webhooks WebhooksConfig
ApplicationMode string
Organization Organization
Type OrgType
User User
ApiSecretKey string
Iam Iam
Twilio Twilio
PrivacyDashboard PrivacyDashboard
Firebase Firebase
Smtp SmtpConfig
Webhooks WebhooksConfig
}

// Load the config file
Expand Down
5 changes: 5 additions & 0 deletions src/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
v2HttpPaths "github.com/bb-consent/api/src/v2/http_path"
"github.com/bb-consent/api/src/v2/iam"
"github.com/bb-consent/api/src/v2/middleware"
pd "github.com/bb-consent/api/src/v2/privacy_dashboard"
"github.com/bb-consent/api/src/v2/sms"
v2token "github.com/bb-consent/api/src/v2/token"
v2wh "github.com/bb-consent/api/src/v2/webhook"
Expand Down Expand Up @@ -81,6 +82,10 @@ func startAPICmdHandlerfunc(cmd *cobra.Command, args []string) {
firebaseUtils.Init(loadedConfig)
log.Println("Firebase initialized")

// Privacy Dashboard
pd.Init(loadedConfig)
log.Println("Privacy Dashboard initialized")

// Application mode
middleware.ApplicationModeInit(loadedConfig)
log.Println("Application mode initialized")
Expand Down
40 changes: 40 additions & 0 deletions src/v2/handler/privacy_dashboard/config_read_privacy_dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package privacydashboard

import (
"encoding/json"
"net/http"

pd "github.com/bb-consent/api/src/v2/privacy_dashboard"
)

type readPrivacyDashboardResp struct {
HostName string `json:"hostname"`
Version string `json:"version"`
Status int `json:"status"`
StatusStr string `json:"statusStr"`
}

// ConfigReadPrivacyDashboard Gets the privacy dashboard related info of the organization
func ConfigReadPrivacyDashboard(w http.ResponseWriter, r *http.Request) {

var resp readPrivacyDashboardResp
if pd.PrivacyDashboard.Hostname == "" {
resp = readPrivacyDashboardResp{
HostName: pd.PrivacyDashboard.Hostname,
Version: pd.PrivacyDashboard.Version,
Status: pd.DashboardNotConfigured,
StatusStr: pd.DashboardDeploymentStatuses[0].Str,
}
} else {
resp = readPrivacyDashboardResp{
HostName: pd.PrivacyDashboard.Hostname,
Version: pd.PrivacyDashboard.Version,
Status: pd.DashboardDeployed,
StatusStr: pd.DashboardDeploymentStatuses[2].Str,
}
}

response, _ := json.Marshal(resp)
w.Header().Set("Content-Type", "application/json")
w.Write(response)
}
2 changes: 2 additions & 0 deletions src/v2/http_path/config_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ const ConfigCreateApiKey = "/v2/config/admin/apikey"
const ConfigUpdateApiKey = "/v2/config/admin/apikey/{apiKeyId}"
const ConfigDeleteApiKey = "/v2/config/admin/apikey/{apiKeyId}"
const ConfigListApiKey = "/v2/config/admin/apikeys"

const ConfigReadPrivacyDashboard = "/v2/config/privacy-dashboard"
3 changes: 3 additions & 0 deletions src/v2/http_path/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
individualHandler "github.com/bb-consent/api/src/v2/handler/individual"
onboardHandler "github.com/bb-consent/api/src/v2/handler/onboard"
policyHandler "github.com/bb-consent/api/src/v2/handler/policy"
privacyDashboardHandler "github.com/bb-consent/api/src/v2/handler/privacy_dashboard"
serviceHandler "github.com/bb-consent/api/src/v2/handler/service"
webhookHandler "github.com/bb-consent/api/src/v2/handler/webhook"
m "github.com/bb-consent/api/src/v2/middleware"
Expand Down Expand Up @@ -78,6 +79,8 @@ func SetRoutes(r *mux.Router, e *casbin.Enforcer) {

r.Handle(ConfigCreateIndividualsInBulk, m.Chain(individualHandler.ConfigCreateIndividualsInBulk, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate(), m.AddContentType())).Methods("POST")

r.Handle(ConfigReadPrivacyDashboard, m.Chain(privacyDashboardHandler.ConfigReadPrivacyDashboard, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate(), m.AddContentType())).Methods("GET")

// Service api(s)

// Data agreements
Expand Down
30 changes: 30 additions & 0 deletions src/v2/privacy_dashboard/privacy_dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package privacydashboard

import "github.com/bb-consent/api/src/config"

// DashboardDeploymentStatus id and string of status
type DashboardDeploymentStatus struct {
ID int
Str string
}

const (
DashboardNotConfigured = 0
DashboardRequested = 1
DashboardDeployed = 2
)

var PrivacyDashboard config.PrivacyDashboard

// Init Initialize the Privacy Dashboard
func Init(config *config.Configuration) {
PrivacyDashboard = config.PrivacyDashboard
}

// Note: Dont change the ID(s) if new type is needed then add at the end

// DashboardDeploymentStatuses Array of id and string
var DashboardDeploymentStatuses = []DashboardDeploymentStatus{
{ID: DashboardNotConfigured, Str: "Not Configured"},
{ID: DashboardRequested, Str: "Requested"},
{ID: DashboardDeployed, Str: "Deployed"}}

0 comments on commit 8c3543a

Please sign in to comment.