Skip to content
Commits on Source (3)
......@@ -371,7 +371,7 @@ export class PostMenuComponent {
this.selectOption('share');
}
checkEditPermissions() {
checkEditPermissions(): boolean {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(this.entity, Flags.EDIT_POST);
}
......@@ -382,7 +382,7 @@ export class PostMenuComponent {
);
}
checkDeletePermissions() {
checkDeletePermissions(): boolean {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(
this.entity,
......
......@@ -6,8 +6,8 @@ export type Permissions = {
};
export class PermissionsService {
canInteract(entity: any, permission: Flags) {
let permissions: Permissions = entity.permissions;
canInteract(entity: any, permission: Flags): boolean {
const permissions: Permissions = entity.permissions;
if (!permissions) {
return false;
......
......@@ -30,6 +30,10 @@ import { AnalyticsService } from '../../../services/analytics';
import { analyticsServiceMock } from '../../../../tests/analytics-service-mock.spec';
import { ActivityService } from '../../../common/services/activity.service';
import { activityServiceMock } from '../../../../tests/activity-service-mock.spec';
import { FeaturesService } from '../../../services/features.service';
import { featuresServiceMock } from '../../../../tests/features-service-mock.spec';
import { PermissionsService } from '../../../common/services/permissions/permissions.service';
import { MockService } from '../../../utils/mock';
describe('Blog view component', () => {
let comp: BlogView;
......@@ -55,6 +59,11 @@ describe('Blog view component', () => {
{ provide: MindsTitle, useValue: mindsTitleMock },
{ provide: ScrollService, useValue: scrollServiceMock },
{ provide: Session, useValue: sessionMock },
{ provide: FeaturesService, useValue: featuresServiceMock },
{
provide: PermissionsService,
useValue: MockService(PermissionsService),
},
],
schemas: [NO_ERRORS_SCHEMA],
})
......@@ -64,6 +73,7 @@ describe('Blog view component', () => {
// synchronous beforeEach
beforeEach(() => {
featuresServiceMock.mock('permissions', false);
fixture = TestBed.createComponent(BlogView);
comp = fixture.componentInstance;
comp.blog = blog;
......
......@@ -23,8 +23,11 @@ import { ContextService } from '../../../services/context.service';
import { optimizedResize } from '../../../utils/optimized-resize';
import { OverlayModalService } from '../../../services/ux/overlay-modal';
import { ActivityService } from '../../../common/services/activity.service';
import { ShareModalComponent } from '../../../modules/modals/share/share';
import { ShareModalComponent } from '../../modals/share/share';
import { ClientMetaService } from '../../../common/services/client-meta.service';
import { Flags } from '../../../common/services/permissions/flags';
import { FeaturesService } from '../../../services/features.service';
import { PermissionsService } from '../../../common/services/permissions/permissions.service';
@Component({
moduleId: module.id,
......@@ -103,6 +106,8 @@ export class BlogView implements OnInit, OnDestroy {
private cd: ChangeDetectorRef,
private overlayModal: OverlayModalService,
private clientMetaService: ClientMetaService,
private featuresService: FeaturesService,
private permissionsService: PermissionsService,
@SkipSelf() injector: Injector
) {
this.clientMetaService
......@@ -154,6 +159,13 @@ export class BlogView implements OnInit, OnDestroy {
}
delete() {
if (
this.featuresService.has('permissions') &&
!this.permissionsService.canInteract(this.blog, Flags.EDIT_POST)
) {
return;
}
this.client
.delete('api/v1/blog/' + this.blog.guid)
.then((response: any) => {
......@@ -170,6 +182,12 @@ export class BlogView implements OnInit, OnDestroy {
menuOptionSelected(option: string) {
switch (option) {
case 'edit':
if (
this.featuresService.has('permissions') &&
!this.permissionsService.canInteract(this.blog, Flags.EDIT_POST)
) {
return;
}
this.router.navigate(['/blog/edit', this.blog.guid]);
break;
case 'delete':
......
......@@ -384,7 +384,7 @@ export class CommentComponentV2
.present();
}
checkEditPermissions() {
checkEditPermissions(): boolean {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(
this.comment,
......@@ -399,7 +399,7 @@ export class CommentComponentV2
);
}
checkDeletePermissions() {
checkDeletePermissions(): boolean {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(
this.comment,
......
......@@ -310,7 +310,7 @@ export class GroupsSettingsButton {
this.overlayService.create(ReportCreatorComponent, this.group).present();
}
checkDeletePermissions() {
checkDeletePermissions(): boolean {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(
this.group,
......
import {
Component,
ChangeDetectionStrategy,
ChangeDetectorRef,
EventEmitter,
Component,
ElementRef,
EventEmitter,
Injector,
Input,
ViewChild,
OnInit,
SkipSelf,
Injector,
ViewChild,
} from '@angular/core';
import { Client } from '../../../../../services/api';
......@@ -30,6 +30,8 @@ import { AutocompleteSuggestionsService } from '../../../../suggestions/services
import { ActivityService } from '../../../../../common/services/activity.service';
import { FeaturesService } from '../../../../../services/features.service';
import isMobile from '../../../../../helpers/is-mobile';
import { PermissionsService } from '../../../../../common/services/permissions/permissions.service';
import { Flags } from '../../../../../common/services/permissions/flags';
@Component({
moduleId: module.id,
......@@ -174,6 +176,7 @@ export class Activity implements OnInit {
protected featuresService: FeaturesService,
public suggestions: AutocompleteSuggestionsService,
protected activityService: ActivityService,
protected permissionsService: PermissionsService,
@SkipSelf() injector: Injector,
elementRef: ElementRef
) {
......@@ -273,6 +276,12 @@ export class Activity implements OnInit {
}
delete($event: any = {}) {
if (
this.featuresService.has('permissions') &&
!this.permissionsService.canInteract(this.activity, Flags.DELETE_POST)
) {
return;
}
if ($event.inProgress) {
$event.inProgress.emit(true);
}
......@@ -408,6 +417,12 @@ export class Activity implements OnInit {
this.router.navigate(['/newsfeed', this.activity.guid]);
break;
case 'edit':
if (
this.featuresService.has('permissions') &&
!this.permissionsService.canInteract(this.activity, Flags.EDIT_POST)
) {
return;
}
this.editing = true;
break;
case 'delete':
......
......@@ -147,20 +147,20 @@
];
if (Minds\Core\Session::isLoggedIn()) {
$user = Minds\Core\Session::getLoggedinUser();
$minds['user'] = $user->export();
$minds['user']['rewards'] = !!Minds\Core\Session::getLoggedinUser()->getPhoneNumberHash();
$minds['wallet'] = array('balance' => Minds\Helpers\Counters::get(Minds\Core\Session::getLoggedinUser()->guid, 'points', false));
if(Minds\Core\Di\Di::_()->get('Features\Manager')->has('permissions')) {
/** @var Minds\Core\Permissions\Manager $permissionsManager */
$permissionsManager = Minds\Core\Di\Di::_()->get('Permissions\Manager');
$permissions = $permissionsManager->getList([
'user_guid' => $user,
'entities' => [$user],
]);
$minds['user']['permissions'] = $permissions->exportPermission($user->getGuid());
}
$user = Minds\Core\Session::getLoggedinUser();
$minds['user'] = $user->export();
$minds['user']['rewards'] = !!Minds\Core\Session::getLoggedinUser()->getPhoneNumberHash();
$minds['wallet'] = array('balance' => Minds\Helpers\Counters::get(Minds\Core\Session::getLoggedinUser()->guid, 'points', false));
if(Minds\Core\Di\Di::_()->get('Features\Manager')->has('permissions')) {
/** @var Minds\Core\Permissions\Manager $permissionsManager */
$permissionsManager = Minds\Core\Di\Di::_()->get('Permissions\Manager');
$permissions = $permissionsManager->getList([
'user_guid' => $user,
'entities' => [$user],
]);
$minds['user']['permissions'] = $permissions->exportPermission($user->getGuid());
}
}
if (__MINDS_CONTEXT__ === 'embed') {
......