@@ -60,8 +60,13 @@ class ConsentBackend {
6060 InvalidInputException .checkUlid (consentId, 'consentId' );
6161 final c = await _lookupAndCheck (consentId, user);
6262 final action = _actions[c.kind]! ;
63- final invitingUserEmail =
64- (await accountBackend.getEmailOfUserId (c.fromUserId! ))! ;
63+ final fromAgent = c.fromAgent! ;
64+ late String invitingUserEmail;
65+ if (looksLikeUserId (fromAgent)) {
66+ invitingUserEmail = (await accountBackend.getEmailOfUserId (fromAgent))! ;
67+ } else {
68+ invitingUserEmail = fromAgent;
69+ }
6570 return api.Consent (
6671 titleText: action.renderInviteTitleText (invitingUserEmail, c.args! ),
6772 descriptionHtml: action.renderInviteHtml (
@@ -106,7 +111,6 @@ class ConsentBackend {
106111 required String kind,
107112 required List <String > args,
108113 required AuditLogRecord auditLogRecord,
109- required bool createdBySiteAdmin,
110114 }) async {
111115 return retry (() async {
112116 // First check for existing consents with identical dedupId.
@@ -138,7 +142,7 @@ class ConsentBackend {
138142 email: email,
139143 kind: kind,
140144 args: args,
141- createdBySiteAdmin: createdBySiteAdmin ,
145+ createdBySiteAdmin: activeAgent is SupportAgent ,
142146 );
143147 await _db.commit (inserts: [
144148 consent,
@@ -154,7 +158,6 @@ class ConsentBackend {
154158 required User activeUser,
155159 required String packageName,
156160 required String uploaderEmail,
157- bool createdBySiteAdmin = false ,
158161 }) async {
159162 return await _invite (
160163 activeAgent: agent,
@@ -167,7 +170,6 @@ class ConsentBackend {
167170 package: packageName,
168171 uploaderEmail: uploaderEmail,
169172 ),
170- createdBySiteAdmin: createdBySiteAdmin,
171173 );
172174 }
173175
@@ -186,7 +188,6 @@ class ConsentBackend {
186188 args: [publisherId, contactEmail],
187189 auditLogRecord: await AuditLogRecord .publisherContactInvited (
188190 user: user, publisherId: publisherId, contactEmail: contactEmail),
189- createdBySiteAdmin: false ,
190191 );
191192 }
192193
@@ -196,7 +197,6 @@ class ConsentBackend {
196197 required User activeUser,
197198 required String publisherId,
198199 required String invitedUserEmail,
199- bool createdBySiteAdmin = false ,
200200 }) async {
201201 return await _invite (
202202 activeAgent: authenticatedAgent,
@@ -209,7 +209,6 @@ class ConsentBackend {
209209 publisherId: publisherId,
210210 memberEmail: invitedUserEmail,
211211 ),
212- createdBySiteAdmin: createdBySiteAdmin,
213212 );
214213 }
215214
@@ -330,19 +329,16 @@ class _PackageUploaderAction extends ConsentAction {
330329 Future <void > onAccept (Consent consent) async {
331330 final packageName = consent.args! [0 ];
332331 final createdBySiteAdmin = consent.createdBySiteAdmin ?? false ;
333- final fromUserId = consent.fromUserId! ;
334- final fromUserEmail = (await accountBackend.getEmailOfUserId (fromUserId))! ;
335332 final currentUser = await requireAuthenticatedWebUser ();
336333 if (currentUser.email? .toLowerCase () != consent.email? .toLowerCase ()) {
337334 throw NotAcceptableException (
338335 'Current user and consent user does not match.' );
339336 }
340337
341338 await packageBackend.confirmUploader (
342- fromUserId,
343- fromUserEmail,
344339 packageName,
345340 currentUser.user,
341+ consentRequestFromAgent: consent.fromAgent! ,
346342 consentRequestCreatedBySiteAdmin: createdBySiteAdmin,
347343 );
348344 }
@@ -352,7 +348,7 @@ class _PackageUploaderAction extends ConsentAction {
352348 final packageName = consent.args! [0 ];
353349 await withRetryTransaction (dbService, (tx) async {
354350 tx.insert (await AuditLogRecord .uploaderInviteRejected (
355- fromUserId : consent.fromUserId ,
351+ fromAgent : consent.fromAgent ,
356352 package: packageName,
357353 uploaderEmail: user? .email ?? consent.email! ,
358354 userId: user? .userId,
@@ -365,7 +361,7 @@ class _PackageUploaderAction extends ConsentAction {
365361 final packageName = consent.args! [0 ];
366362 await withRetryTransaction (dbService, (tx) async {
367363 tx.insert (await AuditLogRecord .uploaderInviteExpired (
368- fromUserId : consent.fromUserId ,
364+ fromAgent : consent.fromAgent ,
369365 package: packageName,
370366 uploaderEmail: consent.email! ,
371367 ));
@@ -408,7 +404,7 @@ class _PublisherContactAction extends ConsentAction {
408404 await publisherBackend.updateContactWithVerifiedEmail (
409405 publisherId,
410406 contactEmail,
411- consentRequestFromUserId : consent.fromUserId ! ,
407+ consentRequestFromAgent : consent.fromAgent ! ,
412408 consentRequestCreatedBySiteAdmin: consent.createdBySiteAdmin ?? false ,
413409 );
414410 }
@@ -418,7 +414,7 @@ class _PublisherContactAction extends ConsentAction {
418414 final publisherId = consent.args! [0 ];
419415 await withRetryTransaction (dbService, (tx) async {
420416 tx.insert (await AuditLogRecord .publisherContactInviteRejected (
421- fromUserId : consent.fromUserId ,
417+ fromAgent : consent.fromAgent ,
422418 publisherId: publisherId,
423419 contactEmail: consent.email! ,
424420 userEmail: user? .email,
@@ -432,7 +428,7 @@ class _PublisherContactAction extends ConsentAction {
432428 final publisherId = consent.args! [0 ];
433429 await withRetryTransaction (dbService, (tx) async {
434430 tx.insert (await AuditLogRecord .publisherContactInviteExpired (
435- fromUserId : consent.fromUserId ,
431+ fromAgent : consent.fromAgent ,
436432 publisherId: publisherId,
437433 contactEmail: consent.email! ,
438434 ));
@@ -488,7 +484,7 @@ class _PublisherMemberAction extends ConsentAction {
488484 await publisherBackend.inviteConsentGranted (
489485 publisherId,
490486 currentUser.userId,
491- consentRequestFromUserId : consent.fromUserId ! ,
487+ consentRequestFromAgent : consent.fromAgent ! ,
492488 consentRequestCreatedBySiteAdmin: consent.createdBySiteAdmin ?? false ,
493489 );
494490 }
@@ -498,7 +494,7 @@ class _PublisherMemberAction extends ConsentAction {
498494 final publisherId = consent.args! [0 ];
499495 await withRetryTransaction (dbService, (tx) async {
500496 tx.insert (await AuditLogRecord .publisherMemberInviteRejected (
501- fromUserId : consent.fromUserId ,
497+ fromAgent : consent.fromAgent ,
502498 publisherId: publisherId,
503499 memberEmail: user? .email ?? consent.email! ,
504500 userId: user? .userId,
@@ -511,7 +507,7 @@ class _PublisherMemberAction extends ConsentAction {
511507 final publisherId = consent.args! [0 ];
512508 await withRetryTransaction (dbService, (tx) async {
513509 tx.insert (await AuditLogRecord .publisherMemberInviteExpired (
514- fromUserId : consent.fromUserId ,
510+ fromAgent : consent.fromAgent ,
515511 publisherId: publisherId,
516512 memberEmail: consent.email! ,
517513 ));
0 commit comments