@@ -65,15 +65,16 @@ export default class Project {
6565 let message = `You have been invited to the TPEN project ${ projectTitle } .
6666 View project <a href='${ process . env . TPENINTERFACES } project?projectID=${ this . data . _id } '>here</a>.`
6767 if ( user ) {
68+ // FIXME this does not have the functionality of an 'invite'.
6869 await this . inviteExistingTPENUser ( user . _id , roles )
6970 }
7071 else {
7172 const inviteData = await this . inviteNewTPENUser ( email , roles )
7273 const returnTo = encodeURIComponent ( `${ process . env . TPENINTERFACES } project?projectID=${ this . data . _id } &inviteCode=${ inviteData . tpenUserID } ` )
7374 // Signup starting at the TPEN3 public site
7475 const signup = `${ process . env . TPENTHREE } login?inviteCode=${ inviteData . tpenUserID } &returnTo=${ returnTo } `
75- // TODO decline endpoint in TPEN Services
76- const decline = `${ process . env . TPENINTERFACES } project/decline?inviteCode =${ inviteData . tpenUserID } &groupID =${ inviteData . tpenGroupID } `
76+ // Decline endpoint in TPEN Services
77+ const decline = `${ process . env . TPENINTERFACES } project/decline?email =${ encodeURIComponent ( email ) } &user= ${ inviteData . tpenUserID } &project =${ this . data . _id } &projectTitle= ${ encodeURIComponent ( projectTitle ) } `
7778 message += `
7879 <p>
7980 Click the button below to get started with your project</p>
@@ -138,12 +139,19 @@ export default class Project {
138139 return roles
139140 }
140141
142+ /**
143+ * Invite an existing TPEN3 User to the project.
144+ * FIXME this does not have the functionality of an 'invite'. The User is added to the project.
145+ * There is no step for them to accept or decline.
146+ */
141147 async inviteExistingTPENUser ( userId , roles ) {
142- const group = new Group ( this . data . group )
143- await group . addMember ( userId , roles )
148+ await this . addMember ( userId , roles )
144149 return this
145150 }
146151
152+ /**
153+ * Add a new temporary user to the users collection and send the invite E-mail.
154+ */
147155 async inviteNewTPENUser ( email , roles ) {
148156 const user = new User ( )
149157 const inviteCode = user . _id
@@ -152,15 +160,44 @@ export default class Project {
152160 const _sub = `temp-${ user . _id } ` // This is a temporary sub for the user until they verify their email
153161 user . data = { email, _sub, profile, agent, inviteCode }
154162 await user . save ( )
163+ // FIXME this does not have the functionality of an 'invite'.
155164 await this . inviteExistingTPENUser ( user . _id , roles )
156165 return { "tpenUserID" :user . _id , "tpenGroupID" :this . data . group }
157166 }
158167
168+ /**
169+ * Add a member to the Project Group.
170+ *
171+ * @param userId The User/member _id to add to the Group.
172+ */
173+ async addMember ( userId , roles ) {
174+ try {
175+ const group = new Group ( this . data . group )
176+ await group . addMember ( userId , roles )
177+ } catch ( error ) {
178+ throw {
179+ status : error . status || 500 ,
180+ message : error . message || "An error occurred while adding the member."
181+ }
182+ }
183+
184+ }
185+
186+ /**
187+ * Remove a member from the Project Group.
188+ * If the member is an invitee (temporary) User, delete that User from the db.
189+ *
190+ * @param userId The User/member _id to remove from the Group and perhaps delete from the db.
191+ */
159192 async removeMember ( userId ) {
160193 try {
161194 const group = new Group ( this . data . group )
162195 await group . removeMember ( userId )
163196 await group . update ( )
197+ // Don't leave orphaned invitees in the db.
198+ const member = new User ( userId )
199+ const memberData = await member . getSelf ( )
200+ if ( memberData ?. inviteCode ) member . delete ( )
164201 return this
165202 } catch ( error ) {
166203 throw {
0 commit comments