如何给读用户一些写访问权限

时间:2019-04-04 13:51:21

标签: java android firebase-realtime-database firebase-authentication firebase-security-rules

我正在尝试使读者具有编辑/写入某些子节点的能力:请参见下面的DB(状态和分配给)。我最近做的是添加以下规则:

第5行|| root.child('writeByAll')。hasChild(auth.uid))“

不幸的是,这为读取用户提供了所有写访问权限,如果删除了该行,则删除了用户的写访问权限,但我似乎无法获得正确的结果

我看了帖子Firebase Database Rules for groups,但无法将其放在上下文中。

任何帮助将不胜感激,这是针对学位论文项目的。 (此处的原始规则:How to grant read-read/write access to specific UIDs from Firebase Auth and Database

{
"rules": {

"stores": {
    ".read": "auth != null && (root.child('readUsers').hasChild(auth.uid) || root.child('readWriteUsers').hasChild(auth.uid))",
    ".write": "auth != null && (root.child('readWriteUsers').hasChild(auth.uid) || root.child('writeByAll').hasChild(auth.uid))",

"Status" : {
        ".read": "auth != null && root.child('writeByAll').hasChild(auth.uid)",
    ".write": "auth != null && root.child('writeByAll').hasChild(auth.uid)",
},
},


"readUsers": {
    ".read": "auth != null && root.child('readUsers').hasChild(auth.uid)",
    ".write": false   
 },


"writeByAll": {
    ".read": "auth != null && root.child('writeByAll').hasChild(auth.uid)",
    ".write": false   
 }

    }
   }

enter image description here

下面是我的编辑任务类-

database = FirebaseDatabase.getInstance().getReference("stores").child("Store 01").child("Task List"); // Reference Database


    spinnerType = findViewById(R.id.typeSpinner);
    status = findViewById(R.id.statusView);
    findViewById(R.id.saveTaskbtn).setOnClickListener(saveTask);

//        Retrieving data from background

    Intent intent = getIntent();

    String passedType = intent.getStringExtra("passType");
    String passedStatus = intent.getStringExtra("passStatus")

    spinnerType.setSelection(((ArrayAdapter<String>)spinnerType.getAdapter()).getPosition(passedType));
    spinnerStatus.getAdapter()).getPosition(passedStatus));
    status.setText(passedStatus);


}//OnCreate

View.OnClickListener saveTask = new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        Intent intent = getIntent();

        final String key = intent.getStringExtra("passKey");


                DatabaseReference typeRef = ref.child("Type");
                DatabaseReference statusRef = ref.child("Status")

                String type = spinnerType.getSelectedItem().toString();
                String statusName = status.getText().toString();

                assignedRef.setValue(assignee);
                typeRef.setValue(type);
                statusRef.setValue(statusName).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {

0 个答案:

没有答案