Closed gicelte closed 7 years ago
perhaps it'll be helpful to check the admin docs hiding under hoodie-account-client? i think it might already cover
Logged in users create/edit/delete additional "user" data which should also be editable by admins in the backend. (2nd data sharing case)
but idk about the other ask, and it's been a while since i've updated my hoodie stuffs ...
... perhaps this could be retitled, because i jumped at the title of this, thinking that
data shared among users.
might happen...
The admins create/edit/delete "public" data in the backend that users access "read-only" in the frontend. (1st data sharing case)
If I understand you correctly, you need a content management system (CMS) for publicly readable data, but only editable by admins. It is a common requirement. There are two answers to do this:
What you can do with Hoodie today
In your app, create a /hoodie/server/index.js
file in which you have to export a hapi plugin. You won’t need to define new routes, what you want is to create a new database with our Store Server API, which is exposed at server.plugins.store.api
. You have to great read access, only admins will have write-access: server.plugins.store.api.create('public-content', {access: 'read'}). The method returns a promise. If it rejects with with
error.statusbeing
409then you are all good, it means the database already exists. The database will now be accessible at the URL path
/hoodie/store/api/public-content`.
We don’t yet have a client API for custom databases, but we are planning on something like hoodie.open(dbName, options)
; options
allowing you to define the sync you want (pull only in your case) or if you want the database to be deleted on sign out (not in your case). If you like we can work on this API together.
Until we have hoodie.open
, we can probably create workaround for your app. Create /hoodie/client/index.js
which should export a function looking like this: module.exports = function (hoodie) { return hoodie.ready.then(function () { /* your custom logic here */ }) }
. You can use @hoodie/store-client
within your plugin, it could look something like this
module.exports = myAppPlugin
var StoreClient = require('@hoodie/store-client')
function myAppPlugin (hoodie) {
return hoodie.ready.then(function () {
var MyStoreClient = StoreClient.defaults({
remoteBaseUrl: location.origin + '/hoodie/store/api/'
})
hoodie.open = function (name) {
return new Store(name)
}
})
}
For editing the data by Admins, we unfortunately don’t yet have a simple way to do that. It is something we want to add to our admin dashboard. This will also cover your second requirement
Logged in users create/edit/delete additional "user" data which should also be editable by admins in the backend. (2nd data sharing case)
If the data does not change a lot (yet), I would suggest you add the data to your app and bootstrap it within /hoodie/server/index.js
after you made sure the database exists, you can write data to it. You could use the server.plugins.store.api.open('public-content').add([])
to which you would pass an array of the documents you want. Make sure they have an .id
property so they only get created, but not updated. You can also do a .removeAll()
before the .add()
if you want to delete and re-create the data each time so updates apply.
Would that work for now? If yes, I would suggest you create a public GitHub repository for a Hoodie App that covers the basic functionality you need, and we can discuss details there and collaborate on it?
What you will be able to do in future
First some context: We have 3 big milestones before considering Hoodie ready for mainstream. We worked most of 2015 and early 2016 on the first milestone, which we called the "Camp Release". We consider Hoodie being a great project in terms of contributor-friendliness, and we have a great and ever growing foundation of active contributors and maintainers now. We are heading towards the 2nd milestone now, which we call the "Village Release". Our main focus now is the Hoodie Ecosystem. If you are a developer with good understanding of JavaScript / Node.js, it will be ready for you. We want people to build apps with Hoodie, share their experiences, create plugins, write tutorials, etc. We will also focus on integrating with other communities, particularly front-end frameworks and libraries like React, Ember, Vue and others.
Hoodie plugins are npm modules that can currently extend the client and server (like mentioned above with the /hoodie/server/index.js
and /hoodie/client/index.js
file. This will land very soon. But other than that, we also want plugins to extend the admin dashboard. So for your case, you should be able to create a simple UI to manage your public-content
database. The same way we have a hoodie.*
client API today, we will have a hoodieAdmin.*
client API. Today’s version it only lets you manage accounts, but we will add an API to manage user data and custom stores soon.
You will also be able to load the admin client outside of the admin dashboard, and create an entirely custom admin UI specifically for your application, the same way you build a custom UI for your app itself.
Let me know if that all makes sense. I’d be happy to get your app ready and help polyfill the features that Hoodie lacks today, and will help you migrate your app to new Hoodie versions as the new features come in.
And please note: things will only move as fast as people help us moving it forward. We are an independent project without any corporate backing :) So things might move slower, but we are here to stay and only accountable towards ourselves and our users
Thank you very much @gr2m! Your explanations are comprehensive and detailed, I just have to tell you it's going to take me a bit of time and testing before I can understand them fully. I am planning to start my tests very soon and hope I'll be able to contribute!
Hey @gicelte did anything come out of your work? Hoodie had some great progress and things should be simpler to implement now.
I’m closing this due to inactivity but let me know if you still have any questions
In a (typical?) web app we have 3 roles: admins, guests users and logged in users.
A backend for admins and a frontend for guests and/or logged in users.
The admins create/edit/delete "public" data in the backend that users access "read-only" in the frontend. (1st data sharing case)
Logged in users create/edit/delete additional "user" data which should also be editable by admins in the backend. (2nd data sharing case)
For now, no need to have data shared among user roles.
How is it possible to implement this with Hoodie?