Jump to content

FDP DataStore


pconkie

Recommended Posts

On 27/06/2018 at 17:28, adamw said:

@Chris Goluch @Graham Quince


Sorry it's taken me so long to see this, I've been busy beavering away at the shiny new things. I think what @Chris Goluch may find useful is the datastore in our FDP endpoints. We've not really mentioned these before because they are still in a state of flux, but they should go some way towards the things you mentioned.

FDP/2/datastore - which has the following methods available: (get, create, createMany, update, updateMany, delete) - I'll see if I can dig out some documentation for you to use. Basically, it allows you to store some data against a uuid / user and then use that data as you see fit. Now, because of how this is currently being used, it was more aimed at storing preferences, though you can store large data structures. The upshot of this, is that you should not put any confidential information into here, as others may be able to get to it.

The rules around who can see what goes as follows. If you use a widget uuid, then only people who have contribute rights the site the widget is on can create data-store entries for that widget. To get data-store entries for a widet uuid that is on a site, you only need view rights to that site.

When it comes to editing data-store entries, you can always edit ones that you own (created) but to edit other peoples you need the correct roles enabled. (Unless the permissions you have on the site have changed to deny you access)

So, what does this all mean? It means you can store data, but at the moment it's insecure. I do have a plan to introduce a 'private' flag, which will allow you to lock down data on a per-user basis, but we haven't needed that yet, so it's not been added.

Using the datastore I think it should be possible to create a message system or a voting system, along with other things. In future, if the private flag is added, then it would expand the possibilities.

Hope this helps.

 


/**
     * @api {get} /datastore/get Get Datastore entries
     * @apiVersion 2.0.0
     * @apiName get
     * @apiGroup datastore
     *
     * @apiDescription Allows you to get datastore entries saved against users / target uuids. If the target_uuid is a widget on a site, then only people who have view rights or higher can get datastore entries.
     *
     * @apiParam {String} target_uuid the uuid against which you wish to get  data (e.g. for a widget this.options.content_uuid)
     * @apiParam {String} data the data you are looking for
     * @apiParam {String} user_uuid the uuid of the user that this data is associated with (defaults to current user if this param is not passed)
     * @apiParam {String} alias the alias for this data, e.g. student.locker_number
     *
     * @apiSuccessExample Success-Response:
     *
     *    {
     *      "status": "ok",
     *      "response": {
     *      "uuid": "3AAA219B200C62F048936FD4E58368084607079CA9DD69C1",
     *      "target_uuid": "36712DA5200286BDD0DECF4D1ABEE602B1A4C0ACF0987992",
     *      "user_uuid": "332B044A2000570E940A2FEB71F4F0011971AB7CA10B3032",
     *      "alias": "student.locker_number",
     *      "data": "A4578B",
     *      "created_by": "332B044A2000570E940A2FEB71F4F0011971AB7CA10B3032",
     *      "created_on": 1512127146,
     *      "updated_on": null,
     *      "updated_by": null
     *   }
     *
     */

/**
     * @api {post} /datastore/create Create Datastore entries
     * @apiVersion 2.0.0
     * @apiName create
     * @apiGroup datastore
     *
     * @apiDescription Allows you to create datastore entries saved against users / target uuids If the target_uuid is a widget on a site, then only people who have contribute rights or higher can create datastore entries.
     *
     * @apiParam {String} target_uuid the uuid against which you wish to associate the data (e.g. for a widget this.options.content_uuid)
     * @apiParam {String} data the data you want to store
     * @apiParam {String} user_uuid the uuid of the user that this data is associated with (defaults to current user if this param is not passed)
     * @apiParam {String} alias the alias for this data, this can be anything you want, and is to help you differentiate the data. For example: 'student.locker_number, student.random_data' max (255 chars)
     *
     * @apiSuccessExample Success-Response:
     *
     *    {
     *      "status": "ok",
     *      "response": {
     *      "uuid": "3AAA219B200C62F048936FD4E58368084607079CA9DD69C1",
     *      "target_uuid": "36712DA5200286BDD0DECF4D1ABEE602B1A4C0ACF0987992",
     *      "user_uuid": "332B044A2000570E940A2FEB71F4F0011971AB7CA10B3032",
     *      "alias": "student.locker_number",
     *      "data": "A4578B",
     *      "created_by": "332B044A2000570E940A2FEB71F4F0011971AB7CA10B3032",
     *      "created_on": 1512127146,
     *      "updated_on": null,
     *      "updated_by": null
     *   }
     *
     */

 /**
     * @api {post} /datastore/update Update Datastore entries
     * @apiVersion 2.0.0
     * @apiName update
     * @apiGroup datastore
     *
     * @apiDescription Allows you to update datastore entries saved against users / target uuids. If the target_uuid is a widget on a site, then only people who have contribute rights or higher can update datastore entries.
     *
     * @apiParam {string} The uuid of the entry you wish to update <strong>(Required)</strong>
     * @apiParam {String} target_uuid the uuid against which you wish to associate the data (e.g. for a widget this.options.content_uuid)
     * @apiParam {String} data the data you want to store
     * @apiParam {String} user_uuid the uuid of the user that this data is associated with (defaults to current user if this param is not passed)
     * @apiParam {String} alias the alias for this data, this can be anything you want, and is to help you differentiate the data. For example: 'student.locker_number, student.random_data' max (255 chars)
     *
     * @apiSuccessExample Success-Response:
     *
     *    {
     *      "status": "ok",
     *      "response": {
     *      "uuid": "3AAA219B200C62F048936FD4E58368084607079CA9DD69C1",
     *      "target_uuid": "36712DA5200286BDD0DECF4D1ABEE602B1A4C0ACF0987992",
     *      "user_uuid": "332B044A2000570E940A2FEB71F4F0011971AB7CA10B3032",
     *      "alias": "student.locker_number",
     *      "data": "A4578B",
     *      "created_by": "332B044A2000570E940A2FEB71F4F0011971AB7CA10B3032",
     *      "created_on": 1512127146,
     *      "updated_on": null,
     *      "updated_by": null
     *   }
     *
     */


    /**
     * @api {post} /datastore/delete delete Datastore entries
     * @apiVersion 2.0.0
     * @apiName delete
     * @apiGroup datastore
     *
     * @apiDescription Allows you to delete datastore entries. Data store entries are found based on the params you send, and delete if you have the correct permissions.
     *
     * @apiParam {string} The uuid of the entry you wish to delete
     * @apiParam {String} target_uuid <strong>optional</strong> the uuid against which you wish to associate the data (e.g. for a widget this.options.content_uuid)
     * @apiParam {String} data the data you want to delete <strong>optional</strong>
     * @apiParam {String} user_uuid the uuid of the user that this data is associated with (defaults to current user if this param is not passed) <strong>optional</strong>
     * @apiParam {String} alias the alias for this data <strong>optional</strong>
     *
     * @apiSuccessExample Success-Response:
     *
     *    {
     *      "status": "ok",
     *      "response": {
     *          true
     *   }
     *
     */

 

 

Link to comment
Share on other sites

Hi @adamw

So how would you recommend this api is integrate into a FrogCode widget?

Let's say I was going to store data against the widgets uuid.....

Do i need to do a datastore.get to check if a datastore exists and create one if it doesn't? Should I do this in the init section of the widget code?

Or will a datastore.create get ignored if the datastore already exists?

Thanks

Paul

Link to comment
Share on other sites

Any ideas?

Capture.PNG.bc0ed0ba7c0e2100495c9a469d7b2394.PNG

 

FrogOS.fdp({
  url: 'datastore/create',
  path: '/api/fdp/2/',
  type: 'POST',
  target_uuid: 'abcdef',
  data: '12345',
  alias: 'test'
}).done(function(response) {
  // Do things
  console.log("done");
  console.log(response);
}).fail(function(e) {
  // Report Error
  console.log("failed");
});

 

Link to comment
Share on other sites

On 18/07/2018 at 12:06, pconkie said:

Hi @adamw

So how would you recommend this api is integrate into a FrogCode widget?

Let's say I was going to store data against the widgets uuid.....

Do i need to do a datastore.get to check if a datastore exists and create one if it doesn't? Should I do this in the init section of the widget code?

Or will a datastore.create get ignored if the datastore already exists?

Thanks

Paul

Hi @pconkie

Sorry for the delay: In your case, you could do a datastore,get call with the params you want to check, to see if you get any data back. If not, you could create a new data-store entry. I think at the moment, if you send another create with the same params, it'll just add another data-store row. Depending on how you want to use this, then that may be fine.

 

Link to comment
Share on other sites

On 19/07/2018 at 14:31, pconkie said:

Any ideas?

Capture.PNG.bc0ed0ba7c0e2100495c9a469d7b2394.PNG


FrogOS.fdp({
  url: 'datastore/create',
  path: '/api/fdp/2/',
  type: 'POST',
  target_uuid: 'abcdef',
  data: '12345',
  alias: 'test'
}).done(function(response) {
  // Do things
  console.log("done");
  console.log(response);
}).fail(function(e) {
  // Report Error
  console.log("failed");
});

Try:

 

  FrogOS.fdp({
    url: 'datastore/create',
    path: '/api/fdp/2/',
    type: 'POST',
    data: {
      target_uuid: 'abcdef',
      data: '12345',
      alias: 'test'
      }
  }).done(function(response) {
  // Do things
  console.log("done");
  console.log(response);
}).fail(function(e) {
  // Report Error
  console.log("failed");
});

 

Note: you'll get an error telling you that 'abcdef' is not a valid frog uuid.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Hi @adamw

I'm still not getting very far with this fdp datastore.....

Capture2.PNG.572be68894d14ed1eb42caa8d79a34f5.PNG

Code runs and outputs "failed".

Error message is as follows:

Capture.PNG.8a0d9ce6ea96c68f2d9fe061cad2f9d5.PNG

I've looked for the datastore permissions in groups & policies but can not find any - is it a permissions issue?

Thanks

Paul

 

 

 

Link to comment
Share on other sites

@pconkie - I'll have to have a look at the logs on your server and see why you're getting a 500 error - which usually indicates a code problem. If it was a permissions error then I'd expect the response to tell you as much. What is the target uuid? A user uuid?

I'm off work this week, but I'm back in on Monday, so can look at it then for you. Or if @Simon Law has a few moments I'm sure he'd have a look. (He likes to find all the bugs in my code.)

Adam

Link to comment
Share on other sites

@pconkie

Okay, so I replicated the call on my side, using your params, and it threw a missing argument exception, because it's expecting a user_uuid to associated this data against. The errors must be suppressed on live boxes and that's why you didn't see that - which is kinda annoying I imagine (I'll look into it).

In the meantime, the following code works:

            FrogOS.fdp({
                url: 'datastore/create',
                path: '/api/fdp/2/',
                type: 'POST',
                data: {
                    target_uuid: this.uuid,
                    data: '12345',
                    alias: 'test',
                    user_uuid: FrogOS.getUser().uuid
                }
            }).done(function(response) {
                // Do things
                console.log("done");
                console.log(response);
            }).fail(function(e) {
                // Report Error
                console.log("failed");
            });

Have a go with that, and let me know if you have any other issues. The data-store stuff was used for a very specific purpose in Frog - but I made it into an FDP endpoint so that people would be able to experiment with it. It's possible that there's some strange behaviour still lingering about in the code.

Thanks!

Link to comment
Share on other sites

Thanks @adamw

Got create, get and update working.....

Can you talk me through Com.Frog.Controller#showLoader ?

I assume there is a built in delay to .showLoader as most of the time it doesn't appear unless the network is slow or i comment out .hideLoader? Can this be overridden?

I think I have grasped the basic functionality (show/hide) -  but I can not seem to do useful things such as...

var widget = this;

////this works.....
widget.showLoader();
//white loader appears full screen
//do some things
//do more things
widget.hideLoader();


////this works....
widget.showLoader(
  widget.element.find(".wrapper"),
  'dark',
  'Please wait...'
);
//dark loader appears covering only widget area of screen
//do some things
//do more things
widget.hideLoader();



////this doesn't work....
widget.showLoader();
setTimeout(
  function() {
    widget.updateLoader("This is taking longer than anticipated");
  },
  3000
);


////this doesn't work....
////and is what I really want to beable to do...
function anyfunction() {
  
  widget.showLoader(
    widget.element.find(".wrapper"),
    'dark',
    'Please wait...'
  );
  
  anyAPI({
    any data
    
  }).done(function(response) {
    widget.hideLoader();
  }).fail(function(e) {
    widget.updateLoader("There has been an error")
  }).always(function(e) {
    widget.updateLoader("This is taking longer than anticipated")
  });
  
}

What is the best way to go when we actually want the user to wait until an ajax request has completed?

Thanks

Paul

 

Link to comment
Share on other sites

  • 2 weeks later...

Hey @adamw

I've built a nice widget using the datastore api.  I've put it on our website and it looks like because visitors do not log in (and they are therefore no authenticated) they can't access the datastore to pull the data for the widget to use. This makes the widget useless :( 

Is there a way around this?

Link to comment
Share on other sites

10 hours ago, pconkie said:

Hey @adamw

I've built a nice widget using the datastore api.  I've put it on our website and it looks like because visitors do not log in (and they are therefore no authenticated) they can't access the datastore to pull the data for the widget to use. This makes the widget useless :( 

Is there a way around this?

Do you have a link to the widget on the public site so I can have a look? What does the widget do?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...