我该怎么办,我希望每个人都可以读取firebase的数据,但是要由同一身份验证人员删除数据 [英] what can I do, I want the data of the firebase is read by everyone but data delete by same auth id person

查看:49
本文介绍了我该怎么办,我希望每个人都可以读取firebase的数据,但是要由同一身份验证人员删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Firebase实时数据库规则,假设这是两个设备用户A和B,A通过App将数据添加到Firebase RealTime数据库,因此B读取用户A添加的数据,相同B通过App添加数据,因此A读取了该数据,但用户A或B都只删除了他自己输入的数据,A只删除了自己的数据,而B只删除了自己的数据,但是两个用户互相读取了数据(表示该数据是由用户输入的).用户对世界可见).因此,此处适用哪条规则. 对于Facebook上的Ex-评论部分,该评论对所有人都是可见的,但是该评论已由管理员或发表该评论的人删除,所以我想要这样,这是我的数据库规则代码

This is my Firebase Realtime Database Rule, suppose that here is two device user A and B , A adds data through App to firebase realTime Database , So B reads that data which is added by user A, Same B adds data through app , So A reads That Data, but both the user A or B delete only own Data which he has entered , A deletes only own data and B deletes only own data, but both user read data each other(means the data is entered by the user is visible to the world).. So which rule is apply here. for Ex- a comment section on facebook , the comment is visible to everyone but that comment is delete by admin or the persom who make that comment , so I want like this ,here is my databae rule code

 {
      "rules": {
        "$uid": {
          ".write": "$uid === auth.uid",
          ".read": "auth != null"
       }
     }
}

这是设置firebase和firebaseUser的子项,它是onCreate中的数据

this is setup the firebase and firebaseUser and the child is data this is in onCreate

FirebaseUser mUser = mAuth.getCurrentUser ();
    String uid = mUser.getUid ();
    myRef = FirebaseDatabase.getInstance ().getReference ( "data" ).child ( uid );
    myRef.keepSynced ( true );//for syncronize the firebase data

数据发送到firebase是这样的,这是我的Java代码,用于显示从firebase到UI的数据,我的应用程序是Support Google和Facebook登录,

and the data is sent to firebase is like this,here is my java code for showing data from firebase to UI and my Application is Support Google and Facebook Signin,

  public void ShowData()
        {


            query1 = myRef.orderByChild ( "dateTime" ); 

            options = new FirebaseRecyclerOptions.Builder < modelClass > ().setQuery ( query1 , modelClass.class ).build ();


            adapter = new FirebaseRecyclerAdapter < modelClass, MyVIewHolder > ( options )
            {
                @Override
                public void onDataChanged() 
                {

                    super.onDataChanged ();
                }

                @Override
                protected void onBindViewHolder(@NonNull final MyVIewHolder holder , final int position , @NonNull modelClass model) 
               {

                        holder.setFoodPost ( model ); //for set all data to view

当用户长时间单击数据时此窗口打开,这里的删除窗口(alertDialog)打开并删除特定数据,但是当其他用户要删除其他人数据时我希望删除窗口不打开,表示该用户只能删除自己的数据(当用户要删除自己的数据时,将打开deleteDialog对话框),如果他要删除其他人的数据,则不会打开删除窗口,因此我在这里应该做些什么,并且 该代码也位于onBilndViewHolder

this is open when the user doing long clik on data, here the delete window(alertDialog) open and delete the particulr data, but I want the delete window not open when other user want to delete other person data , means the user can delete only own data(delete alertDialog open when the user wants delete own data), if he wants delete other person data the delete window will not open so what should I do here ,and this code is also in onBilndViewHolder

     //for longPress on particular view

                    holder.itemView.setOnLongClickListener ( new View.OnLongClickListener () {
                        @Override
                        public boolean onLongClick(View view) {

                            post_key = getRef ( position ).getKey ();

                                openDeleteWindow ();

                                 return true;
                            }

                        }
                    } );



                @NonNull
                @Override
                public MyVIewHolder onCreateViewHolder(@NonNull ViewGroup parent , int viewType) 
{
                    View v = LayoutInflater.from ( parent.getContext () ).inflate ( 
                   R.layout.recycler_view_item_layout , parent , false );
                    Log.d ( "firee","orCreate" );
                    return new MyVIewHolder ( v );



                }
            };
            adapter.startListening (); //if you use FirebaseRecyclerAdapter then this is nessasry

            recyclerView.setAdapter ( adapter ); //set adapter into recyclerView

这是我的火力发源地

 datamyapp-cbfba

    |-- data
        |-WNOAsWDaVlQXq2DssE9AsUCw1jB3    <- Device A (googleSignInKey)
        | |-M1UGU8pMJiNGd5zsG_r
        |   |-college:"ABES"
        |   |-contact:"956379797"
        |   |-dateTime:"03-03-2020 12:52:05"
        |   |-food: "Burger"
        |   |-name:"Vishal"
        |
        |-XiFNOWYYFHhjRdHx7AGOtchjN4x2   <- Device B (googleSignInKey)
          |-M1UGqWNjWVIlbtluD6D
           |-college:"TMU"
           |-contact:"9578379797"
           |-dateTime:"03-03-2020 12:50:05"
           |-food: "Pizza"
           |-name:"Ankit"

推荐答案

请看以下内容:

这里保存了两个用户的数据("keshtynejat"和"mohammadmoeingolchin").如您所见,数据保存完全分开.您如何读取一个用户的数据?您可以用相同的方式读取所有用户的数据.

Here data of two users are saved ('keshtynejat' & 'mohammadmoeingolchin'). As you see data are saved completely separated. How do you read data of one user?! You can read data of all the users the same way.

这篇关于我该怎么办,我希望每个人都可以读取firebase的数据,但是要由同一身份验证人员删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆