Edit current stream (Post) - getstream-io

I have a query. How we can edit the current stream and how we can ,make sure that same user is editing the stream . for e.g. If I created a post and now I want to edit that post. Is it possible? and how to make sure that only I can edit this post

If you use Laravel and the stream-laravel integration this comes out of the box, the only thing you need to do is follow the instructions from the Readme.
In your case you probably want to have a Post model that uses the ActivityTrait trait. After that you only need to add the correct ACL for objects within Laravel (eg. only allow the author of a post to edit that post)

Related

Making a forum using Node Express EJS and MongoDB

I am making a forum using Node, Express, EJS and MongoDB. Currently, I render the forum page and pass data from the database using Node and EJS. I use GET and POST requests. As soon as I add a comment, the page stores in the database and then redirects back to the same route. I am then able to scroll down and see my comment. However I am not happy with this and I want the comments and replies to be handled by Ajax so that as soon as I comment, without refreshing, I create a post request and again without refreshing the page I can load the new comment. Any suggestion on how can I bring this to live?
The project is available to view on https://github.com/Ibrahim40021974/Forum . (Sorry for the untidy code. Am still working on version control). All suggestions are welcomed!
Thanks in Advance.
What you wanna achieve, is generally called a single page application where you won't see the page refresh but the small component of that page is actually got updated with new data.
I have done using Reactjs, Nodejs which is pretty easy to do in Reactjs. If you are interested , I can share the repo.
Had looked into your project and few things I noted.
If I am referring the right one (https://github.com/Ibrahim40021974/Forum/blob/master/views/forum.ejs#L69) then you need to stop default form submit using e.preventDefault(). Default form submit always refresh the page which you don't want. Same form operation you have to do with ajax call.For exm.
handleFormSubmit(e) {
e.preventDefault();
// <add your ajax call here>
}
See once you do this if things work without page refresh.
See if this helps you with how to make ajax call. https://www.thetopsites.net/article/53326172.shtml
As #Ajay kumar said the best way is to create a single page app : framework like react/angular/vue are pretty good when it's about refreshing only part of your page when new data are inserted.
Yet you could do this without using any of this framework but it will be tricky.
You can, in your ejs template add the javascript logic that will, when you submit your comment, do the following :
Send a post request to submit the new comment
Send a get request to get comment affiliated to this post as soon as post request ended
update the DOM(vanillaJs or Jquery) to display the list of comment.
The first choice will ask you to change your project architecture, but will be easier to manage, the second will give you the possibiliy to keep using ejs but is a bit more complicated.

Which RESTful route to use when updating an item involves creating and adding a new item to it?

New to coding and had a question about structure of routes rather than actual coding. I'll use the example of a libraries and books web app below to clarify my question.
I want to create a new library:
POST libraries route.
I want to update the library name:
PUT libraries/libraryId route.
I want to create a new book.
POST books
I want to update the book name.
PUT books/bookId
I am viewing a list of books in a library in my single page app. There is a form to add a new book to the library.
Which route should the form go to in line with RESTful routing or it doesn't matter?
Form posts to the new book route and then updates library:
POST /books/libraryId
or
The form PUTs to the update library route and creates a new book within that route:
PUT /library/libraryId/newbookname
EDIT: Some clarifications based on comments below..
So in my scenario, new books can be created outside of a library by users but they cannot allocate to a library. The librarian administrates the library so can create new books which would automatically be added to their library.
In my opinion, if the books are related to a library then you will have a route like that to create a book: POST /libraries/libraryId/books, and to update a book: PUT /libraries/libraryId/books/bookId.
Also make sure to respect these basic rules about HTTP methods: https://nordicapis.com/understanding-idempotency-and-safety-in-api-design/
POST are not always for create and PUT for updates.
The choice of target-uri primarily depends on which currently cached resource you want to automatically invalidate. See RFC 7234.
For instance, consider this protocol: you GET /libraries/123, and observe in the representation that a book is missing. So you then get the form to add the book to the library, and submit it. Where should that submission go?
Well, the currently cached representation of /libraries/123 doesn't have that book, so if we want the user to be able to verify that things changed, then they are going to need a new copy of /libraries/123 to look at, so we should invalidate the currently cached copy by submitting the post request to /libraries/123
Note that this is the same target-uri that we use when trying to update that library name. That's deliberate.
A good heuristic to consider is "how would you do this on the web?". When we are using HTML to navigate a domain application protocol, POST is the only unsafe method we have available. So adding a new book and changing the name would both be POST requests -- in other words, the POST handler may need to look at the body of the request to figure out what to do.

GETting a document within a Document Update Handler

Is it possible to query (GET) a document from within a document update handler in CouchDB?
I have written a simple document update handler in CouchDB 2.0 to accept a POST from a third party (CognitoForms). This works fine, and I take the ID from their JSON payload and use that as the doc _id.
You can then specify an 'update' URI in CognitoForms, so I could create a new update handler or use the same one. However, in CognitoForms:
The update does a POST rather than a PUT
There does not appear to be a way to send any query parameters
As the ID for the document which needs to be updated is within the body, I could use this to query the database for the document, get the _rev, and return the payload with the _id and _rev to perform the update. However, I simply don't know if I can do such a query within the update handler. I feel like I am either missing something obvious, or there is a very good reason that I wouldn't be allowed to do that.
Thanks very much
edit: I should add that I understand I could create a small application to parse the request before forwarding on to couchdb, but I was interested to see if I could implement this in couchdb only to understand how far I can get without another layer!
In your particular case, it's quite hard to do this. A document update handler is basically a pure function that gets the data it needs and returns a response, but it has no way to reach out into the database.
If you add a doc id to the url, the update function gets the doc from the database as a parameter. For details see the CouchDB docs for update functions.
The way to a possible solution is to use a rewrite in CouchDB in order to extract the id from the body. In CouchDB 2.0, a new way for rewrites as functions has been introduced.
For pushing the limits, using a rewrite function for this sounds like fun. But for a production use case, it's probably easier and more maintainable to create a small node.js app that parses the body.

How do i get all the weblinks from a website?

I want to get all the links(web posts) available in website . And also if any new post is added to website I should be able get the link. I will be having list of 10 websites and the link extraction process needs to be run periodically.
Can some one help me how to get only post links and new post link that is added.
I would suggest to write a php script (since you mentioned php) which is called by a cron-job periodically. Inside the script you can
Option 1: Define a curl commando which automatically fetches all the content of one url. (May be better if you have to deliver some information to the website with post-method.)
Option 2: Use file_get_contents function to get all contents
Than you can parse these result with a regular-expression to extract the parts you are interested in (for example search for something like <div class=".post">...</div>). After that you can add the information to your database or just check if the information is already there.

Posting Blog Entries to a Community

Our tool is submitting blog entries to the idation blog for a configured community by using the Connections API.
Therefore, I use the following workflow, given only a community ID:
1) query /blogs/api/blogs?commUuid=<ID_HERE>&blogType=ideationblog
2) retrieve the link to the communities ideation blog from the xml result of aboves query. the xPath for this is "/app:service/app:workspace/app:collection[a:category[#term='entries']][1]/#href"
3) post the created blog entry payload to this url.
This all worked fine in our environment. However, when I deployed this at a customer, it did not work anymore. The url from the first step returns an empty xml document, and the following steps thus cannot be executed. I tried to query different urls on the customers server like /blogs/{homepageHandle}/api/blogs?commUuid=&blogType=ideationblog which work fine, however the query to the api service document above is the only one which contains the collection element with the link I need.
Is there any other API call I can do, to get this url? Do you know of any reason, why the call is working just fine in our environment, but fails at the customer? Might this be an access rights problem?
I am aware, that I could probably just create a url like "blogs//api/entries" and post to it, however I would prefer the above way, since I only have the communityUuid configured, and also because it is exactly the way that the API Documentation describes:
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Creating_blog_posts_ic45&content=pdcontent
ServiceDoc -> Collection -> href
UPDATE:
This might be a problem with the SBT really. My assumption, that an empty xml document was returned was wrong, it is rather that calls via the SBT Endpoint classes are returning null.
Endpoint endpoint = EndpointFactory.getEndpoint("connections");
Object result = endpoint.xhrGet("/blogs/api"); // also tried for /blogs/<homepage>/api
When I again tried those URLs in the Browser, I got the complete results. Problem with all this is, that I can neither reproduce this in our own environment nor am I able to debug this at the customer. I tried to catch possible exceptions from this, but none are thrown. It's just that the result is null.
To clarify: The same requests work perfectly fine in our own (Connections 4.0) environment, and also from the browser at the customer. I am of course using the same user to authenticate as well in the browser as in the API calls.
endpoint.isAuthenticationValid();
also returns true, so seemingly no problem there...
I have long ago given up trying to follow the IBM documented REST API instructions (not least of all because it always ends in a myriard of REST requests just to get to the URL I need to send my request to).
I tried both your URLs (/blogs/api/blogs?commUuid=... and /blogs/<homepage>/api/blogs...) against all our Connections 4.5 systems, but although I do get an xml document back it doesn't contain a reference to the ideationblog anywhere (and yes, I made sure to quest against a Community that does contain an ideation blog).
This is a dirty workaround, which you mentioned you did not want to do, but which I do use because the documented way doesn't work:
To post blog entries, you need to POST against
/blogs/<bloghandle>/api/entries
To find out the handle (<snx:handle>) of the ideation blog in your community, you can do the following:
1.) Get the widgets-feed for the community: /communities/service/atom/community/widgets?communityUuid=...
2.) Navigate to the entry of the Ideation Blog widget: <snx:widgetDefId>IdeationBlog</snx:widgetDefId>.
Unless someone in your customer system has messed with the widgets-config.xml, the widgetDefId will be IdeationBlog.
3.) Take the <snx:widgetInstanceId> text of the Ideation Blog entry.
That is the handle of your ideation blog. (Yes, community ideation blogs are created with the widgetInstanceId of the Ideation Blog widget as handle. Normal blogs are created with some mashup of their title as handle). You can now construct the URL to post the entries to.

Resources