How to update another users collection data from front-end

Hi All

Short version: I’d like to find a way, for certain users (moderators) to have the ability to update / change certain fields data of a collection, that belong to other users/owners.

Long version:

I’ve created a site, where when members create an account, they also populate the content collection (database) with their details, and they effectively create themselves a profile.

I’ve also created a profile page, where members can view AND edit their details in the front end (using the “owner” filter on the dataset link). I’ve made these using dynamic pages. A user can log into their profile, hit the “Edit” button, and can update all the fields in their profile, which updates the content collection - good stuff.

My problem comes where, I need myself & my moderators, to be able to access another users profile, from the front end, and update/change their profile info (fields). I got as far as making it possible for us to access the other members profile, we can edit & save the new data, but unfortunately it just saves to the 1st person in my collection list - rather than the specific profile page we’re on. I’ve checked the dataset filter options, and you can set a filter to “Owner is Logged In” (so you update your OWN data), but I can’t find a way to change the filter, so that it saves the changes to the users profile we’re currently on. Seems the only two options are either saving to the “Logged in owner’s” profile OR the 1st person on the list.

Maybe there is a work around, but as I say, short version is I want us to be able to change the content data of ANY user, from the front end.

I hope this all makes sense, and hope someone is able to assist with this?

Thank you!
Tom

See image below of the filter I was referring to. Setting it to this, means the data submitted will save to whoever is logged in’s profile. But I need the data to save to the users profile page that we’re currently on instead.

Anyone got any ideas?

Typically, a user can’t change data that belongs to another user. However, as the site admin, you have super powers, and you can make whatever changes to the database that you want.

You will want to do all of this in the backend since you don’t want any sensitive information exposed in the frontend. You, or whoever else has the required site credentials (assigned by you, the admin), will have no problem performing a query of the Members collection in the backend if you use the suppressAuth option in your queries.

Forgot to mention, some collections (eg. Members) can’t be changed - they don’t have write access - not even for an admin. That means that whatever info you want to be editable, should be in another collection that you create specifically for that kind of information.

Thanks for the response Yisrael.

The data I’m looking to change, is indeed editable, as it’s custom fields I’ve created. I do realise that this data can be changed in the back-end as an admin, however I’m looking for a way to change this data from the FRONT end of the website. This is because I don’t want my moderators to have full access to back-end, and want an easy way for them to update 1 data field, for any user, on the front end.

Is there a way I can achieve this?

Thanks again

Hi :raised_hand_with_fingers_splayed:

You can store the (moderators) IDs in an array, and store it in a variable inside a backend function, and when the function is called a check is performed against the moderators IDs array, and if the IDs match, then grant the user the authorization to do whatever you want to do.

Example:

// backend code - backend/members.jsw;
import wixUsersBackend from 'wix-users-backend';
import wixData from 'wix-data';

let user = wixUsersBackend.currentUser;
const moderators = ["id1-asldkalsd", "id2-aslkdjuqw"];

export function getMembersData() {
    return checkPermissions().then(() => {
        // Run your code to do anything, for example, retrieving some data
        return wixData.query('Members').find({suppressAuth: true}).then((result) => {
            return Promise.resolve(result.items);
        }).catch(err => {
            return Promise.reject(err);
        })
    }).catch(err => {
        return Promise.reject(err);
    })
}

function checkPermissions() {
    if (moderators.indexOf(user.id) > -1) {
        return Promise.resolve("ok");
    } else {
        return Promise.reject("Not enough permissions!");
    }
}

Those functions are on a backend module called “members”.
To get the members data, a backend function needs to be called from the frontend to get the members, but only if the member has permissions to do that.

// Frontend page.
import { getMembersData } from 'backend/members.jsw';

$w.onReady(() => {
    $w('#getDetails').onClick(async () => {
        await getMembersData().then((items) => {
            // Display the data to the moderator
            $w('#membersRepeater').data = items;
        }).catch(err => {
            $w('#erorMessage').text = String(err);
        })
    })
})

Just make sure to configure the repeater with its onItemReady( ) function.

Hope this helps~!
Ahmad

Thank you for the advice Ahmad, I appreciate it

Unfortunately I am not that experienced with coding, so I wouldn’t know how to utilise that code, to create what I need.

Is there a way to customise a table, so that the fields on it are editable? If so, I could create a page, with a table, displaying my collection info - but enable it to be editable from the front end, that would be perfect to be honest.

Is this possible?

Thanks

Anyone know if that’s possible? A table, placed on a page on front-end, but the fields editable ?

@thomasbastock Yes it’s totally possible :ok_hand:

You can also use a Repeater with input fields. A repeater is much more flexible and offers many more options. See the Input Repeaters example.

Yeah I did setup a page with a repeater, but that seems to be read only. I’ll give it another go though

Yeah unfortunately I didn’t have any luck with the repeater. How would I go about adding input fields in a table that’s connected to my dataset Ahmad?

Thanks

Anyone else got any ideas, on how I can update content collection data, for a different user, from the front end? Or how to adjust my table, so that fields can be updated from the front end? Thank you!

Anyone who can help with this one? Thank you :slight_smile:

I think all that stuff is a way to far away for you. You should do more little steps.
You try to understand complexe coding-parts, which could let explode your brain, destroy your interest in coding, because you do not get any results.

My suggestion: Try to do step by step.

Yisrael gave you an example (i did not see it yet) but try to look at it, try to understand it. Work on it, till you get/got some results.

This is the way of learning and the best way of learning is by DOING it yourself.
Keep trying and when you still can’t get any coding improvements, go a step backwards and start again.

Try first to learn how to save data into a database and how to get it back (read-out) of course by CODE.

Then do the next step and learn how to work with Private-Members-Data.

Then learn how to use backend and so on.

EDIT : The only way i know to edit some data in a table is to create a form for it, which will open for example by a button-click. Then you load all the data you need from your database into this form, changes all its values you want and by pressing a “SAVE”-button you pull all the changed data back into your database.

@ahmadnasriya
You should give some more infos about it. Let’s say i am interessted, too.:grin:
Editable table, how does it look like? There is a way how to use directly a table to input values?

@russian-dima It’s possible, but not as a table as you imagine, but rather as an interface with multiple and different layouts, I know how to achieve it with workarounds, but the solution was way long and complex, and out of my free time to demonstrate it here, never mention that it’s beyond the knowledge scope of most people, I like helping people how to code, not giving them full (already written) solutions.

@thomasbastock You can create two interfaces for each item in the repeater, one to display the data, and the other to edit them, this way you can save each item individually.

@ahmadnasriya No problem, i understand you very well.

@russian-dima Hi Russian. Interestingly, everything you’ve suggested I go to learn first, I already have, and successfully.

I have indeed created my members database (collection).
I have indeed setup my member private (and public) profiles, which can be edited in the front end, by users, by using forms which are linked by datasets to my collections.
I also know how to customise all my users data in the backend, and customise my collection database.
I’ve even successfully imported all my member data, from my old Joomla website through CSV files, and successfully set them up in my Wix database.

All of this I did, though learning and teaching myself, as you say.

I’m passed all of that now, but now I need to find a way for users to edit OTHER users info, from the front end (not the back end). I have indeed tried to do this through creating forms linked to my collection, however so far it hasn’t seemed possible to “write” to other users collection data, through a form or any front end element that I’ve discovered so far. Owners can write over their own data no problem, but writing to others, I can’t find the solution.

This is why I came here, to find out, how I can achieve this.

Hey guys, I’m still stuck with this one. I’ve created a form for submitting data to the collection, but not sure how to configure it so you can choose which users data, you’re looking to edit.