feat: restrict access to inactive user profiles and update deactivation error messages
This commit is contained in:
@@ -130,6 +130,7 @@ export class AgentsService {
|
|||||||
id: true,
|
id: true,
|
||||||
email: true,
|
email: true,
|
||||||
avatar: true,
|
avatar: true,
|
||||||
|
status: true,
|
||||||
privacyPreferences: true,
|
privacyPreferences: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -141,6 +142,11 @@ export class AgentsService {
|
|||||||
throw new NotFoundException('Agent profile not found');
|
throw new NotFoundException('Agent profile not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Block access to inactive user profiles (unless viewing own profile)
|
||||||
|
if (profile.user.status !== 'ACTIVE' && profile.userId !== requestingUserId) {
|
||||||
|
throw new NotFoundException('Agent profile not found');
|
||||||
|
}
|
||||||
|
|
||||||
const visibility = this.getProfileVisibility(profile.user.privacyPreferences);
|
const visibility = this.getProfileVisibility(profile.user.privacyPreferences);
|
||||||
|
|
||||||
// Own profile — always visible
|
// Own profile — always visible
|
||||||
@@ -299,9 +305,10 @@ export class AgentsService {
|
|||||||
|
|
||||||
const skip = (page - 1) * limit;
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
// Build where clause — only show admin-approved profiles in search
|
// Build where clause — only show active, admin-approved profiles in search
|
||||||
const where: Prisma.AgentProfileWhereInput = {
|
const where: Prisma.AgentProfileWhereInput = {
|
||||||
verificationStatus: 'APPROVED',
|
verificationStatus: 'APPROVED',
|
||||||
|
user: { status: 'ACTIVE' },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.status !== UserStatus.ACTIVE) {
|
if (user.status !== UserStatus.ACTIVE) {
|
||||||
throw new UnauthorizedException('Account is not active');
|
throw new UnauthorizedException('Your account has been deactivated. Please contact support.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if email is verified
|
// Check if email is verified
|
||||||
@@ -334,7 +334,7 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.status !== UserStatus.ACTIVE) {
|
if (user.status !== UserStatus.ACTIVE) {
|
||||||
throw new UnauthorizedException('Account is not active');
|
throw new UnauthorizedException('Your account has been deactivated. Please contact support.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate tokens
|
// Generate tokens
|
||||||
|
|||||||
Reference in New Issue
Block a user