Skip to content

Commit

Permalink
Merge pull request #145 from Avanade/sprint-35
Browse files Browse the repository at this point in the history
Sprint 35
iibuan authored Oct 18, 2024
2 parents 6345cc4 + fa5985b commit 188f833
Showing 41 changed files with 985 additions and 787 deletions.
4 changes: 3 additions & 1 deletion .bicep/webapp/parameters.json
Original file line number Diff line number Diff line change
@@ -41,7 +41,9 @@
"EMAIL_CLIENT_SECRET" : "",
"EMAIL_USER_ID" : "",
"LINK_FOOTERS": "",
"ORGANIZATION_NAME": ""
"ORGANIZATION_NAME": "",
"COMMUNITY_PORTAL_APP_ID": "",
"CALLBACK_RETRY_FREQ": ""
}
}
}
2 changes: 2 additions & 0 deletions .github/workflows/setup-appservice-resource.yml
Original file line number Diff line number Diff line change
@@ -45,6 +45,8 @@ jobs:
parameters.appServiceSettings.value.DOCKER_REGISTRY_SERVER_USERNAME : ${{ secrets.CONTAINER_REGISTRY_SERVER_USERNAME }}
parameters.appServiceSettings.value.DOCKER_REGISTRY_SERVER_PASSWORD : ${{ secrets.CONTAINER_REGISTRY_SERVER_PASSWORD }}
parameters.appServiceSettings.value.APPROVALSYSTEMDB_CONNECTION_STRING : ${{ secrets.DATABASE_CONNECTION_STRING }}
parameters.appServiceSettings.value.COMMUNITY_PORTAL_APP_ID : ${{ vars.COMMUNITY_PORTAL_APP_ID }}
parameters.appServiceSettings.value.CALLBACK_RETRY_FREQ: ${{ vars.CALLBACK_RETRY_FREQ }}

- name: Deploy App Service Plan and Web App
uses: azure/arm-deploy@v1
3 changes: 2 additions & 1 deletion src/goapp/.env.template
Original file line number Diff line number Diff line change
@@ -16,4 +16,5 @@ EMAIL_CLIENT_SECRET=<Client Secret>
EMAIL_ENABLED=<Email enabled. default: false>
EMAIL_USER_ID=<Email user id>
LINK_FOOTERS=""
ORGANIZATION_NAME=""
ORGANIZATION_NAME=""
COMMUNITY_PORTAL_APP_ID=""
4 changes: 4 additions & 0 deletions src/goapp/config/config.go
Original file line number Diff line number Diff line change
@@ -17,4 +17,8 @@ type ConfigManager interface {
GetTenantID() string
GetClientID() string
GetClientSecret() string
GetLinkFooters() string
GetOrganizationName() string
GetCommunityPortalAppId() string
GetCallbackRetryFreq() string
}
16 changes: 16 additions & 0 deletions src/goapp/config/env-config.go
Original file line number Diff line number Diff line change
@@ -66,3 +66,19 @@ func (ecm *envConfigManager) GetClientID() string {
func (ecm *envConfigManager) GetClientSecret() string {
return os.Getenv("CLIENT_SECRET")
}

func (ecm *envConfigManager) GetLinkFooters() string {
return os.Getenv("LINK_FOOTERS")
}

func (ecm *envConfigManager) GetOrganizationName() string {
return os.Getenv("ORGANIZATION_NAME")
}

func (ecm *envConfigManager) GetCommunityPortalAppId() string {
return os.Getenv("COMMUNITY_PORTAL_APP_ID")
}

func (ecm *envConfigManager) GetCallbackRetryFreq() string {
return os.Getenv("CALLBACK_RETRY_FREQ")
}
10 changes: 10 additions & 0 deletions src/goapp/controller/controller.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"main/config"
cApplicationModule "main/controller/app-module"
cItem "main/controller/item"
cUser "main/controller/user"
@@ -9,6 +10,7 @@ import (

type Controller struct {
Item cItem.ItemController
ItemPage cItem.ItemPageController
ApplicationModule cApplicationModule.ApplicationModuleController
User cUser.UserController
}
@@ -42,3 +44,11 @@ func NewUserController(svc *service.Service) ControllerOptionFunc {
c.User = cUser.NewUserController(svc)
}
}

// PAGES

func NewItemPageController(svc *service.Service, conf config.ConfigManager) ControllerOptionFunc {
return func(c *Controller) {
c.ItemPage = cItem.NewItemPageController(svc, conf)
}
}
15 changes: 15 additions & 0 deletions src/goapp/controller/item/item-controller-dto.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package item

import "main/model"

type ReassignItemCallback struct {
Id string `json:"Id"`
ApproverEmail string `json:"ApproverEmail"`
@@ -9,3 +11,16 @@ type ReassignItemCallback struct {
ApproveText string `json:"ApproveText"`
RejectText string `json:"RejectText"`
}

type RespondePageData struct {
ApplicationId string
ApplicationModuleId string
ItemId string
ApproverEmail string
IsApproved string
Data model.Item
RequireRemarks bool
Response string
ApproveText string
RejectText string
}
7 changes: 7 additions & 0 deletions src/goapp/controller/item/item-controller-interface.go
Original file line number Diff line number Diff line change
@@ -8,3 +8,10 @@ type ItemController interface {
ProcessResponse(w http.ResponseWriter, r *http.Request)
ReassignItem(w http.ResponseWriter, r *http.Request)
}

type ItemPageController interface {
MyRequests(w http.ResponseWriter, r *http.Request)
MyApprovals(w http.ResponseWriter, r *http.Request)
RespondToItem(w http.ResponseWriter, r *http.Request)
ReassignApproval(w http.ResponseWriter, r *http.Request)
}
258 changes: 258 additions & 0 deletions src/goapp/controller/item/item-page-controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
package item

import (
"encoding/json"
"fmt"
"main/config"
"main/model"
"main/pkg/session"
"main/service"
"net/http"

"github.com/gorilla/mux"
)

type itemPageController struct {
*service.Service
CommunityPortalAppId string
}

func NewItemPageController(s *service.Service, conf config.ConfigManager) ItemPageController {
return &itemPageController{
Service: s,
CommunityPortalAppId: conf.GetCommunityPortalAppId(),
}
}

func (c *itemPageController) MyRequests(w http.ResponseWriter, r *http.Request) {
session, err := session.Store.Get(r, "auth-session")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

var profile map[string]interface{}
u := session.Values["profile"]
profile, ok := u.(map[string]interface{})
if !ok {
http.Error(w, "Error getting user data", http.StatusInternalServerError)
return
}
user := model.AzureUser{
Name: profile["name"].(string),
Email: profile["preferred_username"].(string),
}

application, err := c.Service.Application.GetApplicationById(c.CommunityPortalAppId)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

b, err := json.Marshal(application)
if err != nil {
fmt.Println(err)
return
}

t, d := c.Service.Template.UseTemplate("myrequests", r.URL.Path, user, string(b))

err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

func (c *itemPageController) MyApprovals(w http.ResponseWriter, r *http.Request) {
session, err := session.Store.Get(r, "auth-session")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

var profile map[string]interface{}
u := session.Values["profile"]
profile, ok := u.(map[string]interface{})
if !ok {
http.Error(w, "Error getting user data", http.StatusInternalServerError)
return
}
user := model.AzureUser{
Name: profile["name"].(string),
Email: profile["preferred_username"].(string),
}

application, err := c.Service.Application.GetApplicationById(c.CommunityPortalAppId)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

b, err := json.Marshal(application)
if err != nil {
fmt.Println(err)
return
}

t, d := c.Service.Template.UseTemplate("myapprovals", r.URL.Path, user, string(b))

err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

func (c *itemPageController) RespondToItem(w http.ResponseWriter, r *http.Request) {
session, _ := session.Store.Get(r, "auth-session")

var profile map[string]interface{}
u := session.Values["profile"]
profile, ok := u.(map[string]interface{})
if !ok {
http.Error(w, "Error getting user data", http.StatusInternalServerError)
return
}
user := model.AzureUser{
Name: profile["name"].(string),
Email: profile["preferred_username"].(string),
}

params := mux.Vars(r)

itemIsAuthorized, err := c.Service.Item.ItemIsAuthorized(
params["appGuid"],
params["appModuleGuid"],
params["itemGuid"],
user.Email,
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

if !itemIsAuthorized.IsAuthorized {
t, d := c.Service.Template.UseTemplate("Unauthorized", r.URL.Path, user, nil)
err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
} else {
if itemIsAuthorized.IsApproved != nil {
var text string
if itemIsAuthorized.IsApproved.Value {
text = "approved"
} else {
text = "rejected"
}

data := RespondePageData{
Response: text,
}

t, d := c.Service.Template.UseTemplate("already-processed", r.URL.Path, user, data)
err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
} else {
item, err := c.Service.Item.GetItemById(params["itemGuid"])
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

data := RespondePageData{
ApplicationId: params["appGuid"],
ApplicationModuleId: params["appModuleGuid"],
ItemId: params["itemGuid"],
ApproverEmail: user.Email,
IsApproved: params["isApproved"],
Data: *item,
RequireRemarks: itemIsAuthorized.RequireRemarks,
}

t, d := c.Service.Template.UseTemplate("response", r.URL.Path, user, data)
err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
}

func (c *itemPageController) ReassignApproval(w http.ResponseWriter, r *http.Request) {
session, _ := session.Store.Get(r, "auth-session")

var profile map[string]interface{}
u := session.Values["profile"]
profile, ok := u.(map[string]interface{})
if !ok {
http.Error(w, "Error getting user data", http.StatusInternalServerError)
return
}
user := model.AzureUser{
Name: profile["name"].(string),
Email: profile["preferred_username"].(string),
}

params := mux.Vars(r)

itemIsAuthorized, err := c.Service.Item.ItemIsAuthorized(
params["appGuid"],
params["appModuleGuid"],
params["itemGuid"],
user.Email,
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

if !itemIsAuthorized.IsAuthorized {
t, d := c.Service.Template.UseTemplate("Unauthorized", r.URL.Path, user, nil)
err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
} else {
if itemIsAuthorized.IsApproved != nil {
var text string
if itemIsAuthorized.IsApproved.Value {
text = "approved"
} else {
text = "rejected"
}

data := RespondePageData{
Response: text,
}

t, d := c.Service.Template.UseTemplate("already-processed", r.URL.Path, user, data)
err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
} else {
item, err := c.Service.Item.GetItemById(params["itemGuid"])
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

data := RespondePageData{
ApplicationId: params["appGuid"],
ApplicationModuleId: params["appModuleGuid"],
ItemId: params["itemGuid"],
Data: *item,
ApproveText: params["ApproveText"],
RejectText: params["RejectText"],
}

t, d := c.Service.Template.UseTemplate("reassign", r.URL.Path, user, data)
err = t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
}
Loading

0 comments on commit 188f833

Please sign in to comment.