How to delete particular value from JSON in user preference of Alfresco - alfresco

When I use the following link
http://localhost:8080/alfresco/service/api/people/admin/preferences?pf=org.my
it returns a json structure like this
{"org":
{"ivory":
{"share":
{"site":
{"search":
{"dashlet":
{"component-1-1":
{"search-definition":
{"fromdate": "01\/02\/2015",
"author": "jhone",
"todate": "30\/04\/2015",
"term": "pensions"
}
}
}
}
}
}
}
}
}
How can I delete author section from this JSON?

The preferences REST API has a delete webscript. To delete an item from the preferences store, make sure the filter specified in the pf parameter identifies just the item you want to delete and then call it with a HTTP delete method.
E.g. a HTTP GET to this URL:
http://localhost:8080/alfresco/service/api/people/admin/preferences?pf=org.alfresco.share.sites.favourites.12345
will return true if that site is favourited. To remove it from the favourites, make a HTTP DELETE request for the same URL.

Related

Extract deep link from Firebase short dynamic link

I'm using Firebase REST APIs to create a short dynamic link on my backend. I'm writing tests (working in TypeScript) to check that functionality and I need to somehow programmatically extract the deep link nested inside the short dynamic link in order to check that I'm passing correct parameters to the mobile apps. Is it possible to do this?
Example request:
POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=api_key
Content-Type: application/json
{
"dynamicLinkInfo": {
"domainUriPrefix": "https://example.page.link",
"link": "https://www.example.com/data?param1=value1&param2=value2",
"androidInfo": {
"androidPackageName": "com.example.android"
},
"iosInfo": {
"iosBundleId": "com.example.ios"
}
}
}
Example response:
https://example.page.link/WXYZ
I'm gonna get the result https://example.page.link/WXYZ in my test and then I want to do some magic (request it in a special way and parse the response?) in order to get the deep link it wraps - https://www.example.com/data?param1=value1&param2=value2.

Using Request Headers in Query/Mutation

I am following Hasura basic tutorial on creating a todo app https://hasura.io/learn/graphql/hasura-advanced/introduction/ and want to extend it and have few additional operations, but don't seem to be able. Setup is as in the tutorial - you have Tasks table with title, description, authorId, isComplete, isPublic column. Table permissions are setup as in the tutorial, so a user can only select their own or public tasks. They can also update only their own tasks. Operations I want to add:
Query only public tasks that are NOT theirs (additionally, inverse also - only theirs without public ones).
Mutate public tasks to complete that are not theirs (update isComplete without having permissions to other columns).
I could create views for the first case, but it seems too much of an effort for such a simple logic. I think both cases could simply be done with access to Request Header (x-hasura-user-id) like so:
query PublicTasksOnly {
tasks(where: {isPublic: {_eq: true}, authorId: {_neq: x-hasura-user-id}}) {
description
isComplete
title
}
}
But it seems that this is not possible. Any ideas/suggestions how to achieve this?
To my knowledge I do not think it is possible to reference http headers in your graphql queries. Have you tried passing the userId as a variable to the query? Something like the following:
query PublicTasksOnly($userId: String!) {
tasks(where: {isPublic: {_eq: true}, authorId: {_neq: $userId}}) {
description
isComplete
title
}
}
I am not quite sure what you want to achieve but if your problem gets solved by adding this header x-hasura-user-id then I can help you out.
You can copy the graphql endpoint from hasura console and hit simple http request to that endpoint with query and it's variables in request body. Sharing sample code here using http library axios:
import axios from 'axios';
axios({
method: 'post',
url: 'https://your-hasura-project-url.hasura.app/v1/graphql',
headers: { 'x-hasura-user-id': '< Your user id >' },
data: {
query: `query PublicTasksOnly {
tasks(where: {isPublic: {_eq: true}}) {
description
isComplete
title
}
}`,
variables: { userId: 'abc-xyz' }
}
})
This should solve your issue.

Exist some way to pass custom parameter to short dynamic link on Firebase?

I know how to pass a custom parameter from a DynamicLink created in FireBase and get it on my app but the problem is that I can only make this work with the large link version, like this:
https://example.page.link/?link=https://example.com.br/?PARAMETER=VALUE&apn=com.example.br
The problem is that the link is too large, how can I send CUSTOM parameter with the short version from DynamicLink on Firebase?
You can probably get it to work if you send a request body instead of URL parameters. The REST docs explain how to:
{
"dynamicLinkInfo": {
"domainUriPrefix": string,
"link": string,
},
"suffix": {
"option": "SHORT" or "UNGUESSABLE"
}
}

Simple GetItem with ctx.identity.username returns null

I'm using AppSync with IAM auth with a DynamoDB resolver and Cognito. I'm trying to do the following.
{
"version": "2017-02-28",
"operation": "GetItem",
"key": {
"userId": $util.dynamodb.toDynamoDBJson($ctx.identity.username)
}
}
$ctx.identity.username is supposed to contain userId generated by Cognito and I'm trying to use it to fetch current user data.
Client side, I'm using AWS Amplify that tells me I'm currently logged:
this.amplifyService.authStateChange$.subscribe(authState => {
if (authState.state === 'signedIn') {
this.getUserLogged().toPromise();
this._isAuthenticated.next(true);
}
});
getUserLogged is the Apollo query that is supposed to returns user data.
What I've tried:
If I leave it like this, getUserLogged returns null.
If I replace in the resolver $util.dynamodb.toDynamoDBJson($ctx.identity.username) with a known userId like this $util.dynamodb.toDynamoDBJson("b1ad0902-2b70-4abd-9acf-e85b62d06fa8"): It works! I get this user data.
I tried to use the test tool in the resolver page but it only gives fake data so I can't rely on this.
Did I make a mistake? To me everything looks good but I guess I'm missing something?
Can I clearly see what $ctx.identity contains?
You'll want to use $ctx.identity.cognitoIdentityId to identify Cognito IAM users:
https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html#aws-appsync-resolver-context-reference-identity
You could see the contents of $ctx.identity by creating a Lambda resolver and logging the event or by creating a local resolver and returning the input that the mapping template receives:
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-local-resolvers.html
My cognitoIdentityId looks like this: eu-west-1:27ca1e79-a238-4085-9099-9f1570cd5fcf

Firestore Update a document field Using Rest API

Im trying to perform PATCH Opeartion in cloud firestore using REST API.
This is my Request body
`{
"fields": {
"name": {
"stringValue":"Dinesh"
}
}
}`
When i fire the request , All the existing fields inside the document are getting deleted and only the name field is getting updated. In the Documentation they have given the Document Mask. but i dont understand how it works , neither im able to find any samples for that. Somebody know how to update only one field inside the document without affecting other fields ?
Without a DocumentMask object, the patch method defaults to replacing the Firestore Document with the request body rather than updating the submitted fields and retaining omitted fields.
The DocumentMask is submitted as an updateMask parameter containing the fieldPaths to be patched. It took a while but thanks to this answer and a lot of attempts I figured out that each fieldPath property of the updateMask object needs to be individually included in the query string of the request url:
https://firestore.googleapis.com/v1beta1/projects/{projectId}/databases/{databaseId}/documents/{document_path}?updateMask.fieldPaths=status&updateMask.fieldPaths=title
Where status and title are two fields in the request body. Note that fields included in the request body are disregarded if they are omitted from the query string, remaining unchanged.
Here is another example giving this json structure from firestore
"fields": {
"eth0": {
"mapValue": {
"fields": {
"address": {
"stringValue": "172.0.0.1"
},
"port": {
"stringValue": "8080"
},
"endpoint": {
"stringValue": "10.0.5.24"
}
}
}
}
}
Then to update the endpoint field only
curl -sSLX PATCH \
-H "Authorization: Bearer {TOKEN}" \
-H "Content-type: application/json" \
-d "{
\"fields\": {
\"eth0\": {
\"mapValue\": {
\"fields\": {
\"endpoint\": {
\"stringValue\": \"10.10.2.24\"
}
}
}
}
}
}" \
"https://firestore.googleapis.com/v1/projects/{project-id}/databases/(default)/documents/{collection}/{document}?updateMask.fieldPaths=eth0.endpoint")
Your request body is ok. But you need to use the update mask.
From reading the documents I found that the DocumentMask is used to restrict a get or update operation on a document to a subset of its fields. So by adding 'name' to your field paths on the mask, it will only allow you to update that specific field and the others won't get deleted.
You can read more about it here.

Resources