Skip to content
Commits on Source (3)
......@@ -15,7 +15,8 @@ import { BlockListService } from '../../services/block-list.service';
import { ActivityService } from '../../../common/services/activity.service';
import { FeaturesService } from '../../../services/features.service';
import { ShareModalComponent } from '../../../modules/modals/share/share';
import { PermissionsService } from '../../services/permissions.service';
import { PermissionsService } from '../../services/permissions/permissions.service';
import { Flags } from '../../services/permissions/flags';
type Option =
| 'edit'
......@@ -372,7 +373,7 @@ export class PostMenuComponent {
checkEditPermissions() {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(this.entity, 'edit_post');
return this.permissionsService.canInteract(this.entity, Flags.EDIT_POST);
}
return (
......@@ -383,7 +384,10 @@ export class PostMenuComponent {
checkDeletePermissions() {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(this.entity, 'delete_post');
return this.permissionsService.canInteract(
this.entity,
Flags.DELETE_POST
);
}
return (
......
export enum Flags {
APPOINT_ADMIN = 'appoint_admin',
APPOINT_MODERATOR = 'appoint_moderator',
APPROVE_SUBSCRIBER = 'approve_subscriber',
CREATE_CHANNEL = 'create_channel',
CREATE_COMMENT = 'create_comment',
CREATE_GROUP = 'create_group',
CREATE_POST = 'create_post',
DELETE_CHANNEL = 'delete_channel',
DELETE_COMMENT = 'delete_comment',
DELETE_GROUP = 'delete_group',
DELETE_POST = 'delete_post',
EDIT_CHANNEL = 'edit_channel',
EDIT_COMMENT = 'edit_comment',
EDIT_GROUP = 'edit_group',
EDIT_POST = 'edit_post',
INVITE = 'invite',
JOIN = 'join',
JOIN_GATHERING = 'gathering',
MESSAGE = 'message',
SUBSCRIBE = 'subscribe',
TAG = 'tag',
REMIND = 'remind',
VIEW = 'wire',
VOTE = 'vote',
}
import { Flags } from './flags';
export type Permissions = {
name: string;
permissions: string[];
};
export class PermissionsService {
canInteract(entity: any, permission: string) {
canInteract(entity: any, permission: Flags) {
let permissions: Permissions = entity.permissions;
if (!permissions) {
return false;
}
return (
permissions &&
permissions.permissions.findIndex(item => item === permission) !== -1
);
}
......
......@@ -17,7 +17,7 @@ import { Observable } from 'rxjs';
import { DialogService } from '../../common/services/confirm-leave-dialog.service';
import { BlockListService } from '../../common/services/block-list.service';
import { ChannelSortedComponent } from './sorted/sorted.component';
import { PermissionsService } from '../../common/services/permissions.service';
import { PermissionsService } from '../../common/services/permissions/permissions.service';
import { ClientMetaService } from '../../common/services/client-meta.service';
@Component({
......
......@@ -32,7 +32,8 @@ import { FeaturesService } from '../../../services/features.service';
import { MindsVideoComponent } from '../../media/components/video/video.component';
import { MediaModalComponent } from '../../media/modal/modal.component';
import isMobile from '../../../helpers/is-mobile';
import { PermissionsService } from '../../../common/services/permissions.service';
import { PermissionsService } from '../../../common/services/permissions/permissions.service';
import { Flags } from '../../../common/services/permissions/flags';
@Component({
selector: 'm-comment',
......@@ -385,7 +386,10 @@ export class CommentComponentV2
checkEditPermissions() {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(this.comment, 'edit_comment');
return this.permissionsService.canInteract(
this.comment,
Flags.EDIT_COMMENT
);
}
return (
......@@ -399,7 +403,7 @@ export class CommentComponentV2
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(
this.comment,
'delete_comment'
Flags.DELETE_COMMENT
);
}
......
......@@ -24,7 +24,8 @@ import { ActivityService } from '../../../common/services/activity.service';
import { Subscription } from 'rxjs';
import { TouchSequence } from 'selenium-webdriver';
import { FeaturesService } from '../../../services/features.service';
import { PermissionsService } from '../../../common/services/permissions.service';
import { PermissionsService } from '../../../common/services/permissions/permissions.service';
import { Flags } from '../../../common/services/permissions/flags';
@Component({
selector: 'm-comments__thread',
......@@ -94,7 +95,7 @@ export class CommentsThreadComponent implements OnInit {
// TODO: maybe there should be a "view comment" flag?
this.canPost = await this.permissionsService.canInteract(
this.entity,
'create_comment'
Flags.CREATE_COMMENT
);
}
}
......
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
RouterStateSnapshot,
} from '@angular/router';
import { FeaturesService } from '../../../services/features.service';
import { PermissionsService } from '../../../common/services/permissions/permissions.service';
import { Session } from '../../../services/session';
import { Flags } from '../../../common/services/permissions/flags';
@Injectable()
export class CanCreateGroupGuardService implements CanActivate {
constructor(
private router: Router,
private featuresService: FeaturesService,
private permissionsService: PermissionsService,
private session: Session
) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (!this.session.getLoggedInUser()) {
this.router.navigate(['/login']);
return false;
}
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(
this.session.getLoggedInUser(),
Flags.CREATE_GROUP
);
}
return true;
}
}
......@@ -38,6 +38,7 @@ import { NewsfeedModule } from '../newsfeed/newsfeed.module';
import { GroupsProfileReviewComponent } from './profile/review/review.component';
import { GroupsKickModalComponent } from './kick-modal/kick-modal.component';
import { TextInputAutocompleteModule } from '../../common/components/autocomplete';
import { CanCreateGroupGuardService } from './create/can-create-group-guard.service';
const routes: Routes = [
{
......@@ -54,7 +55,11 @@ const routes: Routes = [
{ path: 'requests', component: GroupsProfileRequests },
],
},
{ path: 'groups/create', component: GroupsCreator },
{
path: 'groups/create',
component: GroupsCreator,
canActivate: [CanCreateGroupGuardService],
},
{ path: 'groups/:filter', component: GroupsListComponent },
{ path: 'groups', redirectTo: '/groups/top', pathMatch: 'full' },
];
......@@ -117,6 +122,6 @@ const routes: Routes = [
GroupsSidebarMarkersComponent,
],
entryComponents: [GroupsCard, GroupsSidebarMarkersComponent],
providers: [CanDeactivateGroupService],
providers: [CanCreateGroupGuardService, CanDeactivateGroupService],
})
export class GroupsModule {}
......@@ -7,7 +7,8 @@ import { OverlayModalService } from '../../../services/ux/overlay-modal';
import { Client } from '../../../services/api/client';
import { Session } from '../../../services/session';
import { FeaturesService } from '../../../services/features.service';
import { PermissionsService } from '../../../common/services/permissions.service';
import { PermissionsService } from '../../../common/services/permissions/permissions.service';
import { Flags } from '../../../common/services/permissions/flags';
@Component({
selector: 'minds-groups-settings-button',
......@@ -311,7 +312,10 @@ export class GroupsSettingsButton {
checkDeletePermissions() {
if (this.featuresService.has('permissions')) {
return this.permissionsService.canInteract(this.group, 'delete_group');
return this.permissionsService.canInteract(
this.group,
Flags.DELETE_GROUP
);
}
return true;
......
......@@ -3,8 +3,9 @@ import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
import { Session } from '../../../../services/session';
import { Client } from '../../../../services/api';
import { SignupModalService } from '../../../../modules/modals/signup/service';
import { PermissionsService } from '../../../../common/services/permissions.service';
import { PermissionsService } from '../../../../common/services/permissions/permissions.service';
import { FeaturesService } from '../../../../services/features.service';
import { Flags } from '../../../../common/services/permissions/flags';
// had forwardRef(() => RemindComposerModal)
@Component({
......@@ -55,7 +56,10 @@ export class RemindButton {
private checkPermissions() {
if (this.featuresService.has('permissions')) {
this.enabled = this.permissionsService.canInteract(this.object, 'remind');
this.enabled = this.permissionsService.canInteract(
this.object,
Flags.REMIND
);
} else {
this.enabled = true;
}
......
......@@ -46,7 +46,7 @@ import { AuthService } from './auth.service';
import { SiteService } from '../common/services/site.service';
import { SessionsStorageService } from './session-storage.service';
import { DiagnosticsService } from './diagnostics.service';
import { PermissionsService } from '../common/services/permissions.service';
import { PermissionsService } from '../common/services/permissions/permissions.service';
export const MINDS_PROVIDERS: any[] = [
SiteService,
......