Skip to content

Commit

Permalink
Do not use Consent.fromUserId for re-authorization.
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Jun 7, 2024
1 parent c0ad99b commit 5b44f9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
7 changes: 3 additions & 4 deletions app/lib/account/consent_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,16 @@ class _PackageUploaderAction extends ConsentAction {
Future<void> onAccept(Consent consent) async {
final packageName = consent.args![0];
final createdBySiteAdmin = consent.createdBySiteAdmin ?? false;
final fromUserId = consent.fromUserId!;
final currentUser = await requireAuthenticatedWebUser();
if (currentUser.email?.toLowerCase() != consent.email?.toLowerCase()) {
throw NotAcceptableException(
'Current user and consent user does not match.');
}

await packageBackend.confirmUploader(
fromUserId,
packageName,
currentUser.user,
consentRequestFromAgent: consent.fromAgent!,
consentRequestCreatedBySiteAdmin: createdBySiteAdmin,
);
}
Expand Down Expand Up @@ -411,7 +410,7 @@ class _PublisherContactAction extends ConsentAction {
await publisherBackend.updateContactWithVerifiedEmail(
publisherId,
contactEmail,
consentRequestFromUserId: consent.fromUserId!,
consentRequestFromAgent: consent.fromAgent!,
consentRequestCreatedBySiteAdmin: consent.createdBySiteAdmin ?? false,
);
}
Expand Down Expand Up @@ -491,7 +490,7 @@ class _PublisherMemberAction extends ConsentAction {
await publisherBackend.inviteConsentGranted(
publisherId,
currentUser.userId,
consentRequestFromUserId: consent.fromUserId!,
consentRequestFromAgent: consent.fromAgent!,
consentRequestCreatedBySiteAdmin: consent.createdBySiteAdmin ?? false,
);
}
Expand Down
7 changes: 4 additions & 3 deletions app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1494,20 +1494,21 @@ class PackageBackend {
}

Future<void> confirmUploader(
String fromUserId,
String packageName,
User uploader, {
required String consentRequestFromAgent,
required bool consentRequestCreatedBySiteAdmin,
}) async {
await withRetryTransaction(db, (tx) async {
final packageKey = db.emptyKey.append(Package, id: packageName);
final package = (await tx.lookup([packageKey])).first as Package;

if (!consentRequestCreatedBySiteAdmin) {
if (!consentRequestCreatedBySiteAdmin &&
consentRequestFromAgent != KnownAgents.pubSupport) {
await _validatePackageUploader(
packageName,
package,
fromUserId,
consentRequestFromAgent,
);
}
if (package.containsUploader(uploader.userId)) {
Expand Down
15 changes: 9 additions & 6 deletions app/lib/publisher/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:_pub_shared/data/publisher_api.dart' as api;
import 'package:clock/clock.dart';
import 'package:gcloud/service_scope.dart' as ss;
import 'package:logging/logging.dart';
import 'package:pub_dev/account/agent.dart';

import '../account/auth_provider.dart';
import '../account/backend.dart';
Expand Down Expand Up @@ -356,12 +357,13 @@ class PublisherBackend {
Future updateContactWithVerifiedEmail(
String publisherId,
String contactEmail, {
required String consentRequestFromUserId,
required String consentRequestFromAgent,
required bool consentRequestCreatedBySiteAdmin,
}) async {
checkPublisherIdParam(publisherId);
if (!consentRequestCreatedBySiteAdmin) {
await requirePublisherAdmin(publisherId, consentRequestFromUserId);
if (!consentRequestCreatedBySiteAdmin &&
consentRequestFromAgent != KnownAgents.pubSupport) {
await requirePublisherAdmin(publisherId, consentRequestFromAgent);
}
final authenticatedUser = await requireAuthenticatedWebUser();
final user = authenticatedUser.user;
Expand Down Expand Up @@ -545,12 +547,13 @@ class PublisherBackend {
Future<void> inviteConsentGranted(
String publisherId,
String userId, {
required String consentRequestFromUserId,
required String consentRequestFromAgent,
required bool consentRequestCreatedBySiteAdmin,
}) async {
checkPublisherIdParam(publisherId);
if (!consentRequestCreatedBySiteAdmin) {
await requirePublisherAdmin(publisherId, consentRequestFromUserId);
if (!consentRequestCreatedBySiteAdmin &&
consentRequestFromAgent != KnownAgents.pubSupport) {
await requirePublisherAdmin(publisherId, consentRequestFromAgent);
}
final user = await accountBackend.lookupUserById(userId);
await withRetryTransaction(_db, (tx) async {
Expand Down

0 comments on commit 5b44f9c

Please sign in to comment.