How do you now find the ParseRoles associated with the current ParseUser?

I want to fill in ListViewwith the help of Arrayor ArrayListother ParseRolecurrent one associated with it ParseUser. I suppose this requires some kind of query for the current user, however I'm just not sure how you return the roles and also return them to Arrayor ArrayListwith which I could fill in ListView, I know that you can use the current user:

ParseUser.getCurrentUser();

However, I cannot find from there how you install the roles that have been allocated by the User.

EDIT:

I also tried experimenting with this:

ParseQuery<ParseRole> query = ParseRole.getQuery();
query.whereEqualTo("users", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback<ParseRole>() {
   @Override
   public void done(List<ParseRole> objects, ParseException e) {
      if(e == null) {
         Toast.makeText(getApplicationContext(), objects.size() + "", Toast.LENGTH_SHORT).show();
      } else {
         Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT).show();
      }
   }                      
});

. , , , "" - 0.

!

:

, , Waldal Android, , . , - :

    ParseQuery<ParseRole> roleQuery = ParseRole.getQuery();
    List<ParseRole> allRoles = null;
    try {
        allRoles = roleQuery.find();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    userRoles = new ArrayList<ParseRole>();
    userRolesNames = new ArrayList<String>();
    for(ParseRole role : allRoles) {
        ParseQuery usersQuery = role.getRelation("users").getQuery();
        usersQuery.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
        try {
            if(usersQuery.count() > 0) {
                userRoles.add(role);
                userRolesNames.add(role.getName().toString());
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }               

    GroupAdapter adapter = new GroupAdapter(this, userRolesNames);
    workspaces.setAdapter(adapter);
+4
3

, , , , . , - Android, iOS, , iOS, , , Android. iOS , , :

PFQuery *rolesQuery = [PFRole query]; 
NSArray *allRoles = [rolesQuery findObjects];
NSMutableArray *userRoles = [NSMutableArray arrayWithCapacity:10];
for (PFRole *role in allRoles) {
    PFQuery *usersQuery = [role relationforKey:@"users"].query;
    [usersQuery whereKey:@"objectId" equalTo:[PFUser currentUser].objectId];
    if ([usersQuery countObjects]) {
        [userRoles addObject:role];
    }
}

, ...

+1

, - , :

Android

ParseQuery<ParseRole> query = ParseRole.getQuery();
query.whereEqualTo('users', ParseUser.getCurrentUser());
query.findInBackground(new FindCallback<ParseRole>() {
    public void done(List<ParseRole> roles, ParseException e) {
        // do your thing with the roles list
    }
});

, .

iOS Objective-C

PFQuery *query = [PFRole query];
[query whereKey:@"users" equalTo:[PFUser currentUser]];
[query findObjectsInBackgroundWithBlock:^(NSArray *roles, NSError *error) {
  if (!error) {
    // Do something with the found roles
  }
}];

iOS Swift

var query = PFRole.query();
query.whereKey('users', equalTo:PFUser.currentUser());
query.findObjectsInBackgroundWithBlock {
  (roles: [PFObject]!, error:NSError!) -> Void in
  if error == nil {
    // do your thing with the roles
  }
}

JavaScript

var query = new Parse.Query(Parse.Role);
query.equalTo('users', Parse.User.current());
query.find().then(function(roles) {
  // do your thing with the roles array
});
+1

ParseRole myroles= (ParseRole) new ParseQuery("Role").whereEqualTo("name", "AppName-"+currentuserid).getFirst();


Here  "name" -----------Column in Role Table

      "AppName" --------eg: "MyApp-23"   in your _User table



I think this helps...
0

Source: https://habr.com/ru/post/1525151/


All Articles