Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 37 #1226

Merged
merged 8 commits into from
Nov 15, 2024
17 changes: 17 additions & 0 deletions .bicep/logicapps/workflows/CleanupOrganization/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
},
"runAfter": {},
"trackedProperties": {}
},
"HTTP_DEMOTE_ADMIN_OUTSIDE_COLLABORATORS": {
"inputs": {
"authentication": {
"identity": "@concat('/subscriptions/59d64684-e7c9-4397-8982-6b775a473b74/resourcegroups/OpenTech_GitHub_Mgmt/providers/Microsoft.ManagedIdentity/userAssignedIdentities/', parameters('ManagedIdentityName'))",
"type": "ManagedServiceIdentity"
},
"method": "GET",
"uri": "@concat(parameters('GHMgmDomain'), '/utility/demote-outside-collaborators-admin')"
},
"runAfter": {
"HTTP_ORG_CLEANUP": [
"SUCCEEDED"
]
},
"trackedProperties": {},
"type": "Http"
}
},
"contentVersion": "1.0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package approvaltype

import "net/http"

type ApprovalTypeController interface {
GetApprovalTypeById(w http.ResponseWriter, r *http.Request)
GetApprovalTypes(w http.ResponseWriter, r *http.Request)
}
96 changes: 96 additions & 0 deletions src/goapp/controller/approval-type/approval-type-controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package approvaltype

import (
"encoding/json"
"main/model"
"main/pkg/appinsights_wrapper"
"main/service"
"net/http"
"strconv"

"github.com/gorilla/mux"
)

type approvalTypeController struct {
*service.Service
}

func NewApprovalTypeController(service *service.Service) ApprovalTypeController {
return &approvalTypeController{service}
}

func (c *approvalTypeController) GetApprovalTypeById(w http.ResponseWriter, r *http.Request) {
logger := appinsights_wrapper.NewClient()
defer logger.EndOperation()

vars := mux.Vars(r)
id, _ := strconv.Atoi(vars["id"])

approvalType, err := c.ApprovalType.GetById(id)
if err != nil {
logger.TrackException(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(approvalType)
}

func (c *approvalTypeController) GetApprovalTypes(w http.ResponseWriter, r *http.Request) {
logger := appinsights_wrapper.NewClient()
defer logger.EndOperation()

var approvalTypes []model.ApprovalType
var total int64
var err error

params := r.URL.Query()
if params.Has("offset") && params.Has("filter") {
filter, _ := strconv.Atoi(params["filter"][0])
offset, _ := strconv.Atoi(params["offset"][0])
opt := model.FilterOptions{
Filter: filter,
Offset: offset,
Search: params.Get("search"),
Orderby: params.Get("orderby"),
Ordertype: params.Get("ordertype"),
}
approvalTypes, total, err = c.ApprovalType.Get(&opt)
if err != nil {
logger.TrackException(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

} else {
approvalTypes, total, err = c.ApprovalType.Get(nil)
if err != nil {
logger.TrackException(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

for i, v := range approvalTypes {
approvers, err := c.Approver.Get(v.Id)
if err != nil {
logger.TrackException(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

approvalTypes[i].Approvers = approvers
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(struct {
Data []model.ApprovalType `json:"data"`
Total int64 `json:"total"`
}{
Data: approvalTypes,
Total: total,
})
}
8 changes: 8 additions & 0 deletions src/goapp/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
cActivity "main/controller/activity"
cActivityType "main/controller/activitytype"
cApprovalType "main/controller/approval-type"
cContributionArea "main/controller/contributionarea"
cExternalLink "main/controller/externallink"
cOssContributionSponsor "main/controller/osscontributionsponsor"
Expand All @@ -12,6 +13,7 @@ import (
type Controller struct {
Activity cActivity.ActivityController
ActivityType cActivityType.ActivityTypeController
ApprovalType cApprovalType.ApprovalTypeController
ContributionArea cContributionArea.ContributionAreaController
ExternalLink cExternalLink.ExternalLinkController
OssContributionSponsor cOssContributionSponsor.OSSContributionSponsorController
Expand Down Expand Up @@ -41,6 +43,12 @@ func NewActivityTypeController(serv *service.Service) ControllerOptionFunc {
}
}

func NewApprovalTypeController(serv *service.Service) ControllerOptionFunc {
return func(c *Controller) {
c.ApprovalType = cApprovalType.NewApprovalTypeController(serv)
}
}

func NewContributionAreaController(serv *service.Service) ControllerOptionFunc {
return func(c *Controller) {
c.ContributionArea = cContributionArea.NewContributionAreaController(serv)
Expand Down
21 changes: 13 additions & 8 deletions src/goapp/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ var (
db database.Database = database.NewDatabase(conf)

repo = r.NewRepository(
r.NewActivity(db),
r.NewActivityContributionArea(db),
r.NewActivityHelp(db),
r.NewActivityType(db),
r.NewContributionArea(db),
r.NewExternalLink(db),
r.NewOssContributionSponsor(db))
r.NewActivity(&db),
r.NewActivityContributionArea(&db),
r.NewActivityHelp(&db),
r.NewActivityType(&db),
r.NewApprovalType(&db),
r.NewApprover(&db),
r.NewContributionArea(&db),
r.NewExternalLink(&db),
r.NewOssContributionSponsor(&db))

serv = s.NewService(
s.NewActivityService(repo),
s.NewActivityTypeService(repo),
s.NewContributionAreaService(repo),
s.NewActivityHelpService(repo),
s.NewApprovalTypeService(repo),
s.NewApproverService(repo),
s.NewContributionAreaService(repo),
s.NewEmailService(conf),
s.NewExternalLinkService(repo),
s.NewOssContributionSponsorService(repo))

cont = c.NewController(
c.NewActivityController(serv),
c.NewActivityTypeController(serv),
c.NewApprovalTypeController(serv),
c.NewContributionAreaController(serv),
c.NewExternalLinkController(serv),
c.NewOssContributionSponsorController(serv))
Expand Down
15 changes: 15 additions & 0 deletions src/goapp/model/approval-type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package model

import "time"

type ApprovalType struct {
Id int `json:"id"`
Name string `json:"name"`
Approvers []RepositoryApprover `json:"approvers"`
IsActive bool `json:"isActive"`
IsArchived bool `json:"isArchived"`
Created time.Time `json:"created"`
CreatedBy string `json:"createdBy"`
Modified time.Time `json:"modified"`
ModifiedBy string `json:"modifiedBy"`
}
9 changes: 9 additions & 0 deletions src/goapp/model/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package model

type FilterOptions struct {
Filter int
Offset int
Search string
Orderby string
Ordertype string
}
7 changes: 7 additions & 0 deletions src/goapp/model/repository-approver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package model

type RepositoryApprover struct {
ApprovalTypeId int `json:"approvalTypeId"`
ApproverEmail string `json:"approverEmail"`
ApproverName string `json:"approverName"`
}
85 changes: 0 additions & 85 deletions src/goapp/pkg/ghmgmtdb/approvalTypesDb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ghmgmt

import (
"fmt"
"strconv"
"time"
)

Expand All @@ -28,89 +26,6 @@ func GetAllActiveApprovers() interface{} {
return result
}

func SelectApprovalTypes() ([]map[string]interface{}, error) {
db := ConnectDb()
defer db.Close()

result, err := db.ExecuteStoredProcedureWithResult("usp_RepositoryApprovalType_Select", nil)
if err != nil {
return nil, err
}

return result, nil
}

func SelectApprovalTypesByFilter(offset, filter int, orderby, ordertype, search string) ([]map[string]interface{}, error) {
db := ConnectDb()
defer db.Close()

param := map[string]interface{}{
"Offset": offset,
"Filter": filter,
"Search": search,
"OrderBy": orderby,
"OrderType": ordertype,
}

result, err := db.ExecuteStoredProcedureWithResult("usp_RepositoryApprovalType_Select_ByOption", param)
if err != nil {
return nil, err
}

return result, nil
}

func SelectTotalApprovalTypes() int {
db := ConnectDb()
defer db.Close()

result, _ := db.ExecuteStoredProcedureWithResult("usp_RepositoryApprovalType_TotalCount", nil)
total, err := strconv.Atoi(fmt.Sprint(result[0]["Total"]))
if err != nil {
return 0
}
return total
}

func SelectApprovalTypeById(id int) (*ApprovalType, error) {
db := ConnectDb()
defer db.Close()

param := map[string]interface{}{
"Id": id,
}

result, err := db.ExecuteStoredProcedureWithResult("usp_RepositoryApprovalType_Select_ById", param)
if err != nil {
return nil, err
}

approvalType := ApprovalType{
Id: int(result[0]["Id"].(int64)),
Name: result[0]["Name"].(string),
IsActive: result[0]["IsActive"].(bool),
IsArchived: result[0]["IsArchived"].(bool),
}

if result[0]["Created"] != nil {
approvalType.Created = result[0]["Created"].(time.Time)
}

if result[0]["CreatedBy"] != nil {
approvalType.CreatedBy = result[0]["CreatedBy"].(string)
}

if result[0]["Modified"] != nil {
approvalType.Modified = result[0]["Modified"].(time.Time)
}

if result[0]["ModifiedBy"] != nil {
approvalType.ModifiedBy = result[0]["ModifiedBy"].(string)
}

return &approvalType, nil
}

func InsertApprovalType(approvalType ApprovalType) (int, error) {
db := ConnectDb()
defer db.Close()
Expand Down
9 changes: 9 additions & 0 deletions src/goapp/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ func GetRepository(repoName string, org string) (*github.Repository, error) {
return repo, nil
}

func GetPermissionLevel(repoOwner string, repoName string, username string) (string, error) {
client := CreateClient(os.Getenv("GH_TOKEN"))
permission, _, err := client.Repositories.GetPermissionLevel(context.Background(), repoOwner, repoName, username)
if err != nil {
return "", err
}
return permission.GetPermission(), nil
}

func GetRepositoryReadmeById(owner, repoName string) (string, error) {
client := CreateClient(os.Getenv("GH_TOKEN"))

Expand Down
4 changes: 2 additions & 2 deletions src/goapp/repository/activity/implement.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

type activityRepository struct {
db.Database
*db.Database
}

func NewActivityRepository(database db.Database) ActivityRepository {
func NewActivityRepository(database *db.Database) ActivityRepository {
return &activityRepository{database}
}

Expand Down
4 changes: 2 additions & 2 deletions src/goapp/repository/activitycontributionarea/implement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

type activityContributionAreaRepository struct {
db.Database
*db.Database
}

func NewActivityContributionAreaRepository(database db.Database) ActivityContributionAreaRepository {
func NewActivityContributionAreaRepository(database *db.Database) ActivityContributionAreaRepository {
return &activityContributionAreaRepository{database}
}

Expand Down
4 changes: 2 additions & 2 deletions src/goapp/repository/activityhelp/implement.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

type activityHelpRepository struct {
db.Database
*db.Database
}

func NewActivityHelpRepository(database db.Database) ActivityHelpRepository {
func NewActivityHelpRepository(database *db.Database) ActivityHelpRepository {
return &activityHelpRepository{database}
}

Expand Down
4 changes: 2 additions & 2 deletions src/goapp/repository/activitytype/implement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

type activityTypeRepository struct {
db.Database
*db.Database
}

func NewActivityTypeRepository(db db.Database) ActivityTypeRepository {
func NewActivityTypeRepository(db *db.Database) ActivityTypeRepository {
return &activityTypeRepository{db}
}

Expand Down
Loading
Loading