I have 2 classes in Parse, a User class and a Group class. The idea is simple. A logged-in user will be able to create a new Group object, and an array relationship will form between that user and that newly created group. That user can now invite other users to that group via a push notification invitation. A second user will also form a relationship with that group object once he accepts the invite.
So far this is simple and working fine. However, I want the creator of that group object to have full control of the group he created.
1- Creator can invite other users, members cannot.
2- Creator can kick a member out
3- Creator can destroy/delete the group object.
I'm not sure what is the correct way of implementing this using ParseRole. Any suggestions?
You can enforce requirement 1 and requirement 3 with row-level ACL permitting write/delete to the Group table only by the creating user. (to enforce this for invitations, check the group's ACL in the invite logic to see if the inviting user equals the creating user).
Requirement 3 is trickier and, I think, not achievable given how you describe the data. A user who accepts an invitation can add to their own array of groups, but no other user (including a group creator) will be able update that user's row.
Your alternatives are either (a) represent group membership with an array on the group object, or (b) create a another object, one for each user, where the member-of-groups array is kept. Think of this object as a user's persona, and keep a pointer relationship between it and its user.
You can add column 'author' to group class with a User pointer.
When you receive a request, you check if the request author equal to author group.
You must add the user token in your request and compare Parse.User.current() with Group author.
Related
We are working at a mobile application and there we have a group entity with two fields - name and users:
Group name
----------
User A
User B
User C
As we see in our interface the name of the group is above the list of users.
Now, we need to build a step constructor to build such a group. We thought at the first step to give a field for group name, and the the second step we allow a user to create the list of group users.
However, the team that develops interface for our application say that we are not right. They say, that in such cases it is a commonly accepted interface pattern that firstly users must be selected (the first step) and only after that the name of the group must be entered (the second step). They say, this way it is done in Telegram and other messengers. So, even if we display the name of the group above group users, firstly we create user list and only after that we enter the name of the group.
My question - are they right? Is this really a commonly accepted interface pattern?
I have two different types of users Teachers and Students . I use Firebase Auth with Email and password to Authenticate them and store them in the Firebase Real time database . My question is is there a way to create custom accesor methods such as getCurrentUser().getEmail, getDisplayname etc . I need to display different UI for different user type (Teacher/Student) from the current user-type
You got 2 type of users. So first of all, you can make only one firebase structure for both user and just add a boolean variable TEACHER that indicates if a user is a teacher or a student.
But what I usually do is to seperate the users in two different firebase structures meaning that you should create a firebase path teacher/user_id and an another student/user_id which will give you flexibility with retreiving data and display the data in different UI.
A newbie Firebase/Android user here, and I am attempting to create an application where users can be added to a group in my Firebase database.
I have defined my User and Group objects as per this post -
Group of users in firebase
My user and group object looks as in the above post and I understand from the documents on Firebase that in order to add a user to a group I need to also add a group reference to a user object but I do not know how I would code this.
I am just unsure of how best to add a User to a Group with Android programatically ,how would I best achieve this?
i think if you familiar with lists you will use it very well as it is very basic one that you have object of group and object of user
and all you want is to access the user and add the group object
like this
user.getGroups().add(group)
I am developing a social network app that uses Parse.com as a back-end
I gave users the ability to change their name , email and profile picture (which is a parseFile)
And when users are logged in i gave them the ability to add posts
I add the posts by getting the user email and name by
ParseUser.getCurrentUser()
and saving the returned content to my ParseObject
but now the question is what if the user updated his data which is the profile picture or name or email how to update the post data dynamcly
You're going to have to write some cloud code. https://parse.com/docs/js/guide
I would create an beforeSave trigger for your users, check to see if the relevant fields are 'dirty' (have been changed), and, if they have been, create a new object of a customer class that just has a pointer to that user.
Save a pointer to the user on each post.
Create a background job that runs each day/hour/however often you want to do these updates that goes through all of your custom objects that contains a user, use Query.each() to go through each of those objects, and then do a query for all posts where the user key is equal to the user of the custom object. Then set the name/email fields as appropriate.
Make sure that when you're done, you delete all of the custom objects so that you don't continuously perform this job on more and more objects each time.
Alternatively, you could just add the user pointer to the post, and when you fetch your posts, include the user key, so that gets fetched as well. Then you can read the name/email directly from the user, which will always be dynamic. You have to make sure that your ACLs are set up so that users can't edit all of another user's info or something, though.
I'm new to Parse.com and was having trouble designing the structure of my database, and how to retrieve the desired data.
In the database, each user (primary identifier as email) has a list of friends and a status boolean. The friend list contains the email of other users in the database. I need to get the status boolean for each of the friends in a particular users list, and preferably in a single query to the server.
What would be a good way to design our structure and retrieve this data. Currently, I made two data classes (tables), one containing each user with their boolean status, and another containing each user and their list of friends. Firstly I was not sure if this structure is the correct way to go. Secondly, I don't know how to retrieve the status boolean for each user in a single users friend list.
Edit I actually discovered the relation column type just yesterday, but I was unable to figure out how to use it. 1) How do I link a Persona to a User in code? I understand I need to use ObjectID here, but how?
2) How do I add other Personae (friends) to a relation of a single Persona (the user). I was unable to populate this relation column. I understand query can be used on the relation column, but I couldn't reach that far ahead without populating the relation column.
3) In my query to the server, am I pulling the entire table? Lets say a user has 2 friends. Is there a way for me to fetch only the current user, and the two friends, or am I pulling the entire table, and then doing my filtering on it. I am concerned with the network being burdened if my table of users grows big.
Edit Well I couldn't figure out relational queries perfectly just yet, however, I found a good solution to my problem. Since the list of friends changes very rarely, I'll be maintaining this list offline, resulting in a single query to the server of pulling in the status of my friends. Along with this list, I may or may not also decide to pull in my own data and get an updated friend list. Thank you for your help though.
The way to model many-to-many relations in parse is with the relation column type. This is the best choice to describe how a user has many friends who are users. If this is a social-network-like app, another good bit of advice is to create a class -- distinct from the parse User -- that describes users' public personae.
This is so you can have the parse User class remain as the private, customer relationship between your app and a real person (there are built in security constraints here). This other table, say we call it Persona, can have a pointer-typed column to its user, keep such things as nickname, profile image, etc. and also keep your boolean status.
_User class - default stuff that comes standard with parse, plus anything pertaining to the customer relationship with your app.
Persona - pointer to _User table, boolean status, other public info, relation called "friends" relating this to other Persona.
So, given a logged in user and his/her currently selected persona (your choice whether users may have more than one personae), you can get friends' personae as follows (in pseudo code):
friendsRelation <- myPersona.friends
friendsQuery <- friendsRelation.query // query is a method on relation
run friendsQuery asynch, then the result will be allFriendsPersonae
for each persona in allFriendsPersonae
status <- persona.status
If you choose not to take the persona class advice, the "code" above is the same, just replace persona with user.
Edit - in response to question edit:
1) Link a persona the user by setting the persona's user column (pointer type) to the user object. To get that persona later, when you only have a user, query the persona table where "user" column equals user.
2) Relation implements an add() method. If you have a personaA, and want to add personaB as a friend, you getRelation("friends") on personaA, and send it add(personaB).
3) The query you get from a relation is a query only for members of that relation. So if personaA has two friends personaB and personaC, you'll get only B and C when you run personaA's friends query.