From 380640d8a52574c20dad8390cec5443901fc9e82 Mon Sep 17 00:00:00 2001 From: Vishal Dalwadi Date: Wed, 18 Sep 2024 16:53:39 +0530 Subject: [PATCH 1/5] feat: update email template. --- pro/email/invite.go | 49 ++++++++++++++++++++++++++++++++++++++++----- pro/email/utils.go | 23 +++++++++++++++++++++ 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/pro/email/invite.go b/pro/email/invite.go index c2b39bd2..c6b50e7d 100644 --- a/pro/email/invite.go +++ b/pro/email/invite.go @@ -2,6 +2,7 @@ package email import ( "fmt" + "github.com/gravitl/netmaker/servercfg" ) // UserInvitedMail - mail for users that are invited to a tenant @@ -12,16 +13,54 @@ type UserInvitedMail struct { // GetSubject - gets the subject of the email func (UserInvitedMail) GetSubject(info Notification) string { - return "Netmaker: Pending Invitation" + return "You're invited to join Netmaker" } // GetBody - gets the body of the email func (invite UserInvitedMail) GetBody(info Notification) string { + if servercfg.DeployedByOperator() { + return invite.BodyBuilder. + WithParagraph("Hi there,"). + WithParagraph("
"). + WithParagraph("Great news! Your colleague has invited you to join their Netmaker SaaS Tenant."). + WithParagraph("Click the link below to accept your invitation:"). + WithParagraph("
"). + WithParagraph(fmt.Sprintf("Accept Invitation", invite.InviteURL)). + WithParagraph("
"). + WithParagraph("Why you'll love Netmaker:"). + WithParagraph(""). + WithParagraph("Got questions? Our team is here to help you every step of the way."). + WithParagraph("
"). + WithParagraph("Welcome aboard,"). + WithParagraph("

The Netmaker Team

"). + WithParagraph("P.S. Curious to learn more before accepting? Check out our quick start tutorial at netmaker.io/tutorials"). + Build() + } return invite.BodyBuilder. - WithHeadline("Join Netmaker from this invite!"). - WithParagraph("Hello from Netmaker,"). - WithParagraph("You have been invited to join Netmaker."). - WithParagraph(fmt.Sprintf("Join Using This Invite Link Netmaker", invite.InviteURL)). + WithParagraph("Hi there,"). + WithParagraph("
"). + WithParagraph("Great news! Your colleague has invited you to join their Netmaker network."). + WithParagraph("Click the link below to accept your invitation:"). + WithParagraph("
"). + WithParagraph(fmt.Sprintf("Accept Invitation", invite.InviteURL)). + WithParagraph("
"). + WithParagraph("Why you'll love Netmaker:"). + WithParagraph(""). + WithParagraph("Got questions? Our team is here to help you every step of the way."). + WithParagraph("
"). + WithParagraph("Welcome aboard,"). + WithParagraph("

The Netmaker Team

"). + WithParagraph("P.S. Curious to learn more before accepting? Check out our quick start tutorial at netmaker.io/tutorials"). Build() } diff --git a/pro/email/utils.go b/pro/email/utils.go index 69a58fe0..bfab76e3 100644 --- a/pro/email/utils.go +++ b/pro/email/utils.go @@ -74,6 +74,29 @@ func (b *EmailBodyBuilderWithH1HeadlineAndImage) Build() string { From d2d958435aa029cfe86163ad49d8650dc10a022f Mon Sep 17 00:00:00 2001 From: Vishal Dalwadi Date: Wed, 18 Sep 2024 16:53:39 +0530 Subject: [PATCH 2/5] feat: update email template. --- pro/email/invite.go | 49 ++++++++++++++++++++++++++++++++++++++++----- pro/email/utils.go | 2 +- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/pro/email/invite.go b/pro/email/invite.go index c2b39bd2..86018462 100644 --- a/pro/email/invite.go +++ b/pro/email/invite.go @@ -2,6 +2,7 @@ package email import ( "fmt" + "github.com/gravitl/netmaker/servercfg" ) // UserInvitedMail - mail for users that are invited to a tenant @@ -12,16 +13,54 @@ type UserInvitedMail struct { // GetSubject - gets the subject of the email func (UserInvitedMail) GetSubject(info Notification) string { - return "Netmaker: Pending Invitation" + return "You're invited to join Netmaker" } // GetBody - gets the body of the email func (invite UserInvitedMail) GetBody(info Notification) string { + if servercfg.DeployedByOperator() { + return invite.BodyBuilder. + WithParagraph("Hi there,"). + WithParagraph("
"). + WithParagraph("Great news! Your colleague has invited you to join their Netmaker SaaS Tenant."). + WithParagraph("Click the button to accept your invitation:"). + WithParagraph("
"). + WithParagraph(fmt.Sprintf("Accept Invitation", invite.InviteURL)). + WithParagraph("
"). + WithParagraph("Why you'll love Netmaker:"). + WithParagraph(""). + WithParagraph("Got questions? Our team is here to help you every step of the way."). + WithParagraph("
"). + WithParagraph("Welcome aboard,"). + WithParagraph("

The Netmaker Team

"). + WithParagraph("P.S. Curious to learn more before accepting? Check out our quick start tutorial at netmaker.io/tutorials"). + Build() + } return invite.BodyBuilder. - WithHeadline("Join Netmaker from this invite!"). - WithParagraph("Hello from Netmaker,"). - WithParagraph("You have been invited to join Netmaker."). - WithParagraph(fmt.Sprintf("Join Using This Invite Link Netmaker", invite.InviteURL)). + WithParagraph("Hi there,"). + WithParagraph("
"). + WithParagraph("Great news! Your colleague has invited you to join their Netmaker network."). + WithParagraph("Click the button to accept your invitation:"). + WithParagraph("
"). + WithParagraph(fmt.Sprintf("Accept Invitation", invite.InviteURL)). + WithParagraph("
"). + WithParagraph("Why you'll love Netmaker:"). + WithParagraph(""). + WithParagraph("Got questions? Our team is here to help you every step of the way."). + WithParagraph("
"). + WithParagraph("Welcome aboard,"). + WithParagraph("

The Netmaker Team

"). + WithParagraph("P.S. Curious to learn more before accepting? Check out our quick start tutorial at netmaker.io/tutorials"). Build() } diff --git a/pro/email/utils.go b/pro/email/utils.go index 69a58fe0..09e508b7 100644 --- a/pro/email/utils.go +++ b/pro/email/utils.go @@ -73,7 +73,7 @@ func (b *EmailBodyBuilderWithH1HeadlineAndImage) Build() string { From 4c117e0d479f6159a2d30dc9182bd0fe50756fbf Mon Sep 17 00:00:00 2001 From: Vishal Dalwadi Date: Thu, 19 Sep 2024 16:08:24 +0530 Subject: [PATCH 3/5] feat: update email template. --- pro/email/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pro/email/utils.go b/pro/email/utils.go index 09e508b7..b689a8be 100644 --- a/pro/email/utils.go +++ b/pro/email/utils.go @@ -73,7 +73,7 @@ func (b *EmailBodyBuilderWithH1HeadlineAndImage) Build() string { From d2afe844f5b2112fafd5983f224603fda9c6f390 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Tue, 24 Sep 2024 20:07:32 +0400 Subject: [PATCH 4/5] create default role and groups for existing networks --- migrate/migrate.go | 1 + 1 file changed, 1 insertion(+) diff --git a/migrate/migrate.go b/migrate/migrate.go index 1675f4ee..a2d9b65d 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -319,6 +319,7 @@ func syncUsers() { nodes, err := logic.GetAllNodes() if err == nil { for _, netI := range networks { + logic.CreateDefaultNetworkRolesAndGroups(models.NetworkID(netI.NetID)) networkNodes := logic.GetNetworkNodesMemory(nodes, netI.NetID) for _, networkNodeI := range networkNodes { if networkNodeI.IsIngressGateway { From d58439ac9dd07ac1b4e2948b2a656f369a4bef68 Mon Sep 17 00:00:00 2001 From: Abhishek K Date: Thu, 26 Sep 2024 11:52:21 +0400 Subject: [PATCH 5/5] api for network with stats (#3111) --- controllers/network.go | 44 ++++++++++++++++++++++++++++++++++++++++++ models/network.go | 5 +++++ 2 files changed, 49 insertions(+) diff --git a/controllers/network.go b/controllers/network.go index acb479ec..03f40cb9 100644 --- a/controllers/network.go +++ b/controllers/network.go @@ -24,6 +24,8 @@ import ( func networkHandlers(r *mux.Router) { r.HandleFunc("/api/networks", logic.SecurityCheck(true, http.HandlerFunc(getNetworks))). Methods(http.MethodGet) + r.HandleFunc("/api/v1/networks/stats", logic.SecurityCheck(true, http.HandlerFunc(getNetworksStats))). + Methods(http.MethodGet) r.HandleFunc("/api/networks", logic.SecurityCheck(true, checkFreeTierLimits(limitChoiceNetworks, http.HandlerFunc(createNetwork)))). Methods(http.MethodPost) r.HandleFunc("/api/networks/{networkname}", logic.SecurityCheck(true, http.HandlerFunc(getNetwork))). @@ -74,6 +76,48 @@ func getNetworks(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(allnetworks) } +// @Summary Lists all networks with stats +// @Router /api/v1/networks/stats [get] +// @Tags Networks +// @Security oauth +// @Produce json +// @Success 200 {object} models.SuccessResponse +// @Failure 500 {object} models.ErrorResponse +func getNetworksStats(w http.ResponseWriter, r *http.Request) { + + var err error + allnetworks, err := logic.GetNetworks() + if err != nil && !database.IsEmptyRecord(err) { + slog.Error("failed to fetch networks", "error", err.Error()) + logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal")) + return + } + if r.Header.Get("ismaster") != "yes" { + username := r.Header.Get("user") + user, err := logic.GetUser(username) + if err != nil { + logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal")) + return + } + allnetworks = logic.FilterNetworksByRole(allnetworks, *user) + } + allNodes, err := logic.GetAllNodes() + if err != nil { + logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal")) + return + } + netstats := []models.NetworkStatResp{} + logic.SortNetworks(allnetworks[:]) + for _, network := range allnetworks { + netstats = append(netstats, models.NetworkStatResp{ + Network: network, + Hosts: len(logic.GetNetworkNodesMemory(allNodes, network.NetID)), + }) + } + logger.Log(2, r.Header.Get("user"), "fetched networks.") + logic.ReturnSuccessResponseWithJson(w, r, netstats, "fetched networks with stats") +} + // @Summary Get a network // @Router /api/networks/{networkname} [get] // @Tags Networks diff --git a/models/network.go b/models/network.go index c29b45d7..32d95f86 100644 --- a/models/network.go +++ b/models/network.go @@ -97,3 +97,8 @@ func (network *Network) GetNetworkNetworkCIDR6() *net.IPNet { _, netCidr, _ := net.ParseCIDR(network.AddressRange6) return netCidr } + +type NetworkStatResp struct { + Network + Hosts int `json:"hosts"` +}