-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
460 additions
and
36 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
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 |
---|---|---|
|
@@ -10,13 +10,11 @@ describe('Organisation details', () => { | |
cy.contains("td", "[email protected]").parent().within(() => { | ||
cy.contains("Kamal Singh") | ||
cy.contains("Invite pending") | ||
cy.contains("a", "Resend invite") | ||
}) | ||
|
||
cy.contains("td", "[email protected]").parent().within(() => { | ||
cy.contains("Jo Alessi") | ||
cy.contains("Invite pending") | ||
cy.contains("a", "Resend invite") | ||
}) | ||
|
||
cy.contains("Team members") | ||
|
@@ -33,4 +31,23 @@ describe('Organisation details', () => { | |
cy.contains("Active") | ||
}) | ||
}); | ||
|
||
it('shows resend invite when expired', () => { | ||
cy.visit('/fixtures/supporter?organisation=1&redirect=/manage-organisation/manage-team-members&invitedMembers=1&permission=admin&expireInvites=1'); | ||
|
||
cy.checkA11yApp(); | ||
cy.contains("a", "Manage team members").click() | ||
|
||
cy.contains("Invited team members") | ||
|
||
cy.contains("td", "[email protected]").parent().within(() => { | ||
cy.contains("button", "Resend invite").click({force: true}) | ||
}) | ||
|
||
cy.url().should("contain", "/manage-organisation/manage-team-members"); | ||
cy.checkA11yApp(); | ||
|
||
cy.contains(".govuk-notification-banner--success", "[email protected]"); | ||
cy.get("main").should("not.contain", "Resend invite"); | ||
}); | ||
}); |
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
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
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
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"encoding/base64" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
@@ -25,7 +26,7 @@ type MemberStore interface { | |
CreateMemberInvite(ctx context.Context, organisation *actor.Organisation, firstNames, lastname, email, code string, permission actor.Permission) error | ||
} | ||
|
||
func Supporter(sessionStore sesh.Store, organisationStore OrganisationStore, donorStore DonorStore, memberStore MemberStore) page.Handler { | ||
func Supporter(sessionStore sesh.Store, organisationStore OrganisationStore, donorStore DonorStore, memberStore MemberStore, dynamoClient DynamoClient) page.Handler { | ||
return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { | ||
var ( | ||
invitedMembers = r.FormValue("invitedMembers") | ||
|
@@ -35,6 +36,7 @@ func Supporter(sessionStore sesh.Store, organisationStore OrganisationStore, don | |
redirect = r.FormValue("redirect") | ||
asMember = r.FormValue("asMember") | ||
permission = r.FormValue("permission") | ||
expireInvites = r.FormValue("expireInvites") == "1" | ||
|
||
supporterSub = random.String(16) | ||
supporterSessionID = base64.StdEncoding.EncodeToString([]byte(supporterSub)) | ||
|
@@ -75,15 +77,43 @@ func Supporter(sessionStore sesh.Store, organisationStore OrganisationStore, don | |
|
||
if invitedMembers != "" { | ||
n, err := strconv.Atoi(invitedMembers) | ||
if err != nil { | ||
return fmt.Errorf("invitedMembers should be a number") | ||
} | ||
|
||
for i, member := range invitedOrgMemberNames { | ||
if i == n { | ||
break | ||
} | ||
|
||
if err = memberStore.CreateMemberInvite(page.ContextWithSessionData(r.Context(), &page.SessionData{OrganisationID: org.ID}), org, member.Firstnames, member.Lastname, strings.ToLower(fmt.Sprintf("%s-%[email protected]", member.Firstnames, member.Lastname)), random.String(12), actor.Admin); err != nil { | ||
return err | ||
email := strings.ToLower(fmt.Sprintf("%s-%[email protected]", member.Firstnames, member.Lastname)) | ||
|
||
now := time.Now() | ||
if expireInvites { | ||
now = now.Add(time.Hour * -time.Duration(48)) | ||
log.Println(now) | ||
} | ||
|
||
invite := &actor.MemberInvite{ | ||
PK: "ORGANISATION#" + org.ID, | ||
SK: "MEMBERINVITE#" + base64.StdEncoding.EncodeToString([]byte(email)), | ||
CreatedAt: now, | ||
OrganisationID: org.ID, | ||
OrganisationName: org.Name, | ||
Email: email, | ||
FirstNames: member.Firstnames, | ||
LastName: member.Lastname, | ||
Permission: actor.Admin, | ||
ReferenceNumber: random.String(12), | ||
} | ||
|
||
if err := dynamoClient.Create(page.ContextWithSessionData(r.Context(), &page.SessionData{OrganisationID: org.ID}), invite); err != nil { | ||
return fmt.Errorf("error creating member invite: %w", err) | ||
} | ||
|
||
//if err = memberStore.CreateMemberInvite(page.ContextWithSessionData(r.Context(), &page.SessionData{OrganisationID: org.ID}), org, member.Firstnames, member.Lastname, strings.ToLower(fmt.Sprintf("%s-%[email protected]", member.Firstnames, member.Lastname)), random.String(12), actor.Admin); err != nil { | ||
// return err | ||
//} | ||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.