Skip to content

Commit

Permalink
fix: selected visibility filter
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 committed Dec 2, 2022
1 parent 510e152 commit 2745e69
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/interceptors/pagination.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ export class PaginationInterceptor implements Provider<Interceptor> {
return comment;
}

if (visibility === VisibilityType.SELECTED) {
const {selectedUserIds} = post;
const isSelected = selectedUserIds.find(e => e === currentUserId);
if (!isSelected) {
post.text = '[This is a post for selected user only]';
post.rawText = '[This is a post for selected user only]';
comment.text = '[This comment is for selected user only]';
comment.post = post;
comment.privacy = 'private';
}
}

// Post creator is not current user
// Check comment creator privacy when post visibility is public
const isPrivate = await this.userService.isAccountPrivate(userId);
Expand Down
5 changes: 5 additions & 0 deletions src/services/friend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,16 @@ export class FriendService {
friendStatus = 'respond';
}
break;

default:
friendStatus = 'blocked';
}

return {
id: friendId,
status: friendStatus,
requesteeId: friend.requesteeId,
requestorId: friend.requestor,
};
}

Expand Down
19 changes: 14 additions & 5 deletions src/services/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export class PostService {
if (!currentUserId) return;
if (currentUserId === creator) return;
if (visibility === VisibilityType.PRIVATE) {
throw new HttpErrors.Forbidden('Restricted post!');
throw new HttpErrors.Forbidden('PrivatePost');
} else {
promises[0] = this.friendRepository.findOne({
where: {
Expand Down Expand Up @@ -523,14 +523,14 @@ export class PostService {
accountPrivacy === AccountSettingType.PUBLIC &&
friend?.status === FriendStatusType.BLOCKED
) {
throw new HttpErrors.Forbidden('Restricted post!');
throw new HttpErrors.Forbidden('PrivatePost');
}

if (
accountPrivacy === AccountSettingType.PRIVATE &&
friend?.status !== FriendStatusType.APPROVED
) {
throw new HttpErrors.Forbidden('Restricted post!');
throw new HttpErrors.Forbidden('OnlyFriendPost');
}

return;
Expand All @@ -540,14 +540,23 @@ export class PostService {
const [friend] = await Promise.all(promises);

if (friend?.status !== FriendStatusType.APPROVED) {
throw new HttpErrors.Forbidden('Restricted post!');
throw new HttpErrors.Forbidden('OnlyFriendPost');
}

return;
}

case VisibilityType.SELECTED: {
const {selectedUserIds} = post;
const isSelected = selectedUserIds.find(e => e === currentUserId);
if (!isSelected) {
throw new HttpErrors.Forbidden('OnlySelectedUser');
}
return;
}

default:
throw new HttpErrors.Forbidden('Restricted post!');
throw new HttpErrors.Forbidden('RestrictedPost');
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/services/user-social-media.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,13 @@ export class UserSocialMediaService {
userSocialMedia: UserSocialMediaWithRelations,
people: People,
): Promise<UserSocialMedia> {
const currentUserId = this.currentUser[securityId];
const key = `social-media/${currentUserId}`;
const connected = userSocialMedia?.connected;
const promises = [this.metricService.countServerMetric()];
const promises = [
this.metricService.countServerMetric(),
this.identityRepository.delete(key),
];

if (!connected) {
promises.push(
Expand Down Expand Up @@ -236,7 +241,5 @@ export class UserSocialMediaService {
if (identity.hash !== hash) {
throw new HttpErrors.UnprocessableEntity('InvalidHashCode');
}

await this.identityRepository.delete(key);
}
}

0 comments on commit 2745e69

Please sign in to comment.