我提前为长篇文章道歉,但这里有很多类似的问题 . 我相信我已经阅读了所有这些内容并且没有任何帮助,所以我将开始一个新的尝试尽可能明确 .

我的目标是为我的角度火力应用程序设置一个基于角色的基本访问控制系统 . 我正在使用Angular5,我将为我的所有代码和模块以及诸如此类的东西提供代码片段 .

不幸的是,我在设置最基本的规则时遇到了麻烦 . 为简单起见,我将数据库缩减为一个名为“events”的集合 . 我在该集合中有一些测试文档,它们唯一的属性是:

'title':string'active':布尔值

我试图做的是在用户文档上有一个事件id的列表(我已经删除了用户集合),该列表确定了该用户对该文档的CRUD权限 . 当我这样做时,我无法获得任何规则,所以我简化了它 .

我现在要做的就是测试事件文档的一些基本规则 . 一些工作,一些不工作,我只是想了解发生了什么 .

这是一个示例文档

以下是我的规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /events/{documentId} {
    // NONE OF THESE WORK
      // allow read: if documentId == "MCNgP57uK6fQTCWLBd6M";
      // allow read: if resource.__id__ == "MCNgP57uK6fQTCWLBd6M";
      // allow read: if resource.id == "MCNgP57uK6fQTCWLBd6M";
      // allow read: if documentId == MCNgP57uK6fQTCWLBd6M;
      // allow read: if resource.__id__ == MCNgP57uK6fQTCWLBd6M;
      // allow read: if resource.id == MCNgP57uK6fQTCWLBd6M;
      // allow read: if resource.id is string ||
      //   resource.__id__ is string || 
      //   documentId is string || 
      //   resource.id != null || 
      //   resource.__id__ != null || 
      //   resource.id != null

      // allow read: if resource.keys().hasAny(['id','__id__','name']) ||
      //     resource != null || 
      //   resource == null || 
      //   resource.keys().size() > 0 ||
      //   resource.keys() != null;

        // allow read: if resource
        // allow read: if false;

    // THESE WORK
        // allow read;
        // allow read: if true;
        // allow read: if resource.data.active == true;
            // allow read: if resource.data.keys().hasAny(['title','active']);

        // allow read: if resource.id is string ||
        // resource.__id__ is string || 
        // documentId is string || 
        // resource.id != null || 
        // resource.__id__ != null || 
        // resource.id != null || 
        // true;
      // allow read: if resource.keys().hasAny(['id','__id__','name']) ||
      //    resource != null || 
      //   resource == null || 
      //   resource.keys().size() > 0 ||
      //   resource.keys() != null ||
      //   true;
      allow update, create, delete;
    }
  }
}

我已经尝试了各种不同的查询方法 . 我确保我的身份验证设置正确,我可以检查request.auth变量,所以我不相信这是问题 . 我尝试过的两个问题是:

this.eventsCollection = afs.collection<any>('events', ref => ref.where('title', '==', 'event 2') );
this.events$ = this.eventsCollection.valueChanges();

// Basic collection query
this.eventsCollection = afs.collection<any>('events');
this.events$ = this.eventsCollection.valueChanges();

它有效的事实有时告诉我,我至少有一些东西设置正确 . 大多数失败都涉及尝试检查资源变量,我得到的是:the firestore documentation . 很难说哪些文档对应于实时数据库vs firestore,但我相信它适用于firestore .

我真正想做的就是了解失败的原因 . 此外,如果有人知道调试这些东西的好方法,我很乐意听到它 . 甚至只是一个日志文件或其他东西 .

理想情况下,如果有人可以告诉我如何获取resource.id(或类似的东西),那将是非常有帮助的 .

这是我的app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { CoreModule } from './core/core.module';
import { NgModule } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from '../environments/environment';
import { AppComponent } from './app.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppRoutingModule } from './app-routing.module';
import { ContentModule } from './content/content.module';
import { SharedModule } from './shared/shared.module';
import { PublicModule } from './public/public.module';

import { AuthGuard } from './core/auth.guard';
import { StoreModule } from '@ngrx/store';
import { reducers, metaReducers } from './reducers/reducers';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import {
  NgbDatepickerModule,
  NgbTimepickerModule
} from '@ng-bootstrap/ng-bootstrap';
import { CalendarModule } from 'angular-calendar';

import { } from '@fortawesome/fontawesome-svg-core'

@NgModule({
  declarations: [
    AppComponent,
    // ...APP_COMPONENTS,
  ],
  imports: [
    PublicModule,
    ContentModule,
    // AnimationsModule,
    SharedModule,
    BrowserAnimationsModule,
    FormsModule,
    BrowserModule,
    NgbModule.forRoot(),
    AngularFireModule.initializeApp(environment.firebase),
    StoreModule.forRoot(reducers, {metaReducers}),
    StoreDevtoolsModule.instrument({
      maxAge: 10
    }),
    AngularFireDatabaseModule,
    AngularFireAuthModule,
    CoreModule,
    AppRoutingModule, // this should always be the last router
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

的package.json

{
  "name": "umanity-ui",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.2",
    "@angular/animations": "^5.2.9",
    "@angular/cdk": "^5.2.4",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/material": "^5.2.4",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@fortawesome/fontawesome": "^1.1.5",
    "@fortawesome/fontawesome-svg-core": "^1.2.0-10",
    "@google/maps": "^0.4.6",
    "@ng-bootstrap/ng-bootstrap": "^1.1.0",
    "@ngrx/store": "^5.2.0",
    "angular-calendar": "^0.23.7",
    "angular-font-awesome": "^3.1.2",
    "angular-maps": "^0.8.2",
    "angular2-wizard": "^0.4.0",
    "angularfire2": "^5.0.0-rc.6",
    "bootstrap": "^4.0.0",
    "core-js": "^2.4.1",
    "firebase": "^4.12.1",
    "firebaseui": "^2.7.0",
    "font-awesome": "^4.7.0",
    "google": "^2.1.0",
    "ionic-native": "^2.9.0",
    "jquery": "^3.3.1",
    "ng2-charts": "^1.6.0",
    "ng2-charts-x": "^2.0.6",
    "ngx-bootstrap": "^2.0.3",
    "popper.js": "^1.14.2",
    "rxjs": "^5.5.8",
    "zone.js": "^0.8.25"
  },
  "devDependencies": {
    "@angular/cli": "~1.7.3",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@ngrx/store-devtools": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}

如果您需要我的源代码,请告诉我们 .