How do I programmatically set class level permissions in Parse? - javascript

According to the Parse Schema Javascript docs, there does not seem to be a way to set classLevelPermission using the JS api. It seems to be possible via the REST api, however. Is there a way to do it with the JS api?

try this in javascript.This is for your reference i did this in angular 6 -
setCLP() {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'X-Parse-Application-Id': enter application id ,
'X-Parse-Master-Key': enter master key
})
};
{
"url": 'your schema url' + 'enter your classname ',
"reqparam":{
"className" : abc,
"classLevelPermissions" :
{
"find": {
'*' : true
},
'*' : true
},
"create": { '*': true },
"update": { '*': false },
"delete": { '*' : true },
}
}
}, httpOptions).toPromise();
console.log(result);
return result;
}

There is no API for setting CLP with the JavaScript SDK, hopefully this is a feature we will see added in the future.
See this issue for a possible workaround.

This is now available in the Parse JS SDK.
setCLP(clp) → {Parse.Schema}
Sets Class Level Permissions when creating / updating a Schema.

Related

How to use getByDataFilter Sheets API v4 to get specific row data

I need to get specific data row of this table:
Google Sheet Data Base
, for that I am using the following filter parameter:
var filter = {
"dataFilters": [
{
"developerMetadataLookup": {
"metadataValue": "julian#domain3.com"
}
}
]
};
but the current result is as follows:
response: {
"spreadsheetId": "1chGysP"
}
The result I need is something like the following:
response: {
"range": "'Hoja 1'!A4:D4",
"majorDimension": "ROWS",
"values": [
[
"3",
"domain4",
"julian#domain3.com",
"Active"
]
]
}
I found a similar question to mine, and it seems to work but I think I wouldn't be taking advantage of using the api directly like checking quotas, reporting dashboard and so on.
How can I use the Google Sheets (v4) API getByDataFilter to return a specific row of data?
My complete code is as follows:
//function for bot that runs asynchronously from Google Apps Script
function consultData(){
var url = 'https://sheets.googleapis.com/v4/spreadsheets/1chGysP/values:batchGetByDataFilter?key=KAIzaSy'
var service = getOAuthService();
service.reset()
var filter = {
"dataFilters": [
{
"developerMetadataLookup": {
"metadataValue": "julian#domain3.com"
}
}
]
};
var params = {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
},
method: 'get',
contentType: 'application/json',
payload: JSON.stringify(filter),
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch(url, params).getContentText();
Logger.log('response: ' + response);
return response;
}
API reference:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/getByDataFilter
The most practical and scalable solution in my case for having increasing information is not to use sheets as a database, firstly because it has a limit on records https://support.google.com/drive/answer/37603?hl=es
and limit in metadata that is needed for getDataFilter for condition by values
https://developers.google.com/sheets/api/guides/metadata
My quick and effective solution was to have my information repository in Firebase, and with this library it is extremely easy to make the connection, queries, overwrites, creations:
https://github.com/grahamearley/FirestoreGoogleAppsScript

How to combine two `hello.init` into one?

I am trying to use hello.js init API to sign in Microsoft Graph later. The code below is how I am doing now and it works.
repo
However, is there a way to combine these two hello.init into one? Thanks
hello.init({
msft: {
oauth: {
version: 2,
auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
},
scope_delim: ' ',
form: false
}
});
hello.init({
msft: myAppId
}, {
redirect_uri: window.location.href
});
I got the answer from the creator of hello.js Andrew Dodson on GitHub.
hello.init ({msft:appid}) is short for hello.init ({msft:{id:appid}})
so you just need to define an id prop on your definition and it'll all
work. Fyi this is undocumented and may change in the future.
So in my case, the solution is
hello.init({
msft: {
id: myAppId,
oauth: {
version: 2,
auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
},
scope_delim: ' ',
form: false
},
},
{ redirect_uri: window.location.href }
);

Duplicate keys in a REST connector query in loopback

I would like to ask if you know how could I duplicate parameters in a loopback REST connector query.
I have the following code:
details: {
'template': {
'method': 'GET',
'debug': true,
'url': 'https://www.example.com/data',
'timeout': 10000,
'headers': {
'Authorization': 'Bearer {token}'
},
'query': {
q: 'PHOTOS'
q: 'DETAILS',
id: '{id}'
},
'options': {
'useQuerystring': true
},
'responsePath': '$'
},
'functions': {
'searchData': [
'token',
'id'
]
}
}
The problem for that it is that it seems that loopback override the value of the parameter q by the last one, because I get only information for the last parameter.
Any idea how to solve it?
Thank you in avance.
You just have to pass them as an array:
'query': {
q: ['PHOTOS', 'DETAILS'],
id: '{id}'
},
Note that the options key, is passed to request and here's the documentation for useQuerystring:
useQuerystring - If true, use querystring to stringify and parse querystrings, otherwise use qs (default: false). Set this option
to true if you need arrays to be serialized as foo=bar&foo=baz
instead of the default foo[0]=bar&foo[1]=baz.
So if you remove it you'll end with something like ?q[0]=PHOTOS&q[1]=DETAILS.
You can also another option there:
qsStringifyOptions - object containing options to pass to the qs.stringify method.
Alternatively pass options to the
querystring.stringify
method using this format {sep:';', eq:':', options:{}}. For example,
to change the way arrays are converted to query strings using the qs
module pass the arrayFormat option with one of
indices|brackets|repeat
So you can actually end up with the same thing adding this:
"options": {
"qsStringifyOptions": {
"arrayFormat": "repeat"
}
}
And if you want to have just the brackets(something like this ?q[]=PHOTOS&q[]=DETAILS) you can specify brackets option:
"options": {
"qsStringifyOptions": {
"arrayFormat": "brackets"
}
}

Creating an envelope from a template returning "UNSPECIFIED_ERROR"

When I try to create an envelope from a template I get a response of:
{ errorCode: 'UNSPECIFIED_ERROR',
message: 'Non-static method requires a target.' }
Here's what I'm doing so far:
First I login, which returns
{ loginAccounts:
[ { name: '*****',
accountId: '*****',
baseUrl: 'https://demo.docusign.net/restapi/v2/accounts/******',
isDefault: 'true',
userName: '***** ********',
userId: '*******-*****-*****-*****-*********',
email: '********#*******.com',
siteDescription: '' } ] }
So then I take the baseUrl out of that response and I attempt to create the envelope. I'm using the hapi framework and async.waterfall of the async library, so for anyone unfamiliar with either of these my use of the async library uses the next callback to call the next function which in this case would be to get the url for the iframe, and with our usage of the hapi framework AppServer.Wreck is roughy equivalent to request:
function prepareEnvelope(baseUrl, next) {
var createEntitlementTemplateId = "99C44F50-2C97-4074-896B-2454969CAEF7";
var getEnvelopeUrl = baseUrl + "/envelopes";
var options = {
headers: {
"X-DocuSign-Authentication": JSON.stringify(authHeader),
"Content-Type": "application/json",
"Accept": "application/json",
"Content-Disposition": "form-data"
},
body : JSON.stringify({
status: "sent",
emailSubject: "Test email subject",
emailBlurb: "My email blurb",
templateId: createEntitlementTemplateId,
templateRoles: [
{
email: "anemailaddress#gmail.com",
name: "Recipient Name",
roleName: "Signer1",
clientUserId: "1099", // TODO: replace with the user's id
tabs : {
textTabs : [
{
tabLabel : "acct_nmbr",
value : "123456"
},
{
tabLabel : "hm_phn_nmbr",
value : "8005882300"
},
{
tabLabel : "nm",
value : "Mr Foo Bar"
}
]
}
}
]
})
};
console.log("--------> options: ", options); // REMOVE THIS ====
AppServer.Wreck.post(getEnvelopeUrl, options, function(err, res, body) {
console.log("Request Envelope Result: \r\n", JSON.parse(body));
next(null, body, baseUrl);
});
}
And what I get back is:
{ errorCode: 'UNSPECIFIED_ERROR',
message: 'Non-static method requires a target.' }
From a little googling it look like 'Non-static method requires a target.' is a C# error and doesn't really give me much indication of what part of my configuration object is wrong.
I've tried a simpler version of this call stripping out all of the tabs and clientUserId and I get the same response.
I created my template on the Docusign website and I haven't ruled out that something is set up incorrectly there. I created a template, confirmed that Docusign noticed the named form fields, and created a 'placeholder' templateRole.
Here's the templateRole placeholder:
Here's one of the named fields that I want to populate and corresponding data label:
As a side note, I was able to get the basic vanilla example working without named fields nor using a template using the docusign node package just fine but I didn't see any way to use tabs with named form fields with the library and decided that I'd rather have more fine-grained control over what I'm doing anyway and so I opted for just hitting the APIs.
Surprisingly when I search SO for the errorCode and message I'm getting I could only find one post without a resolution :/
Of course any help will be greatly appreciated. Please don't hesitate to let me know if you need any additional information.
Once I received feedback from Docusign that my api call had an empty body it didn't take but a couple minutes for me to realize that the issue was my options object containing a body property rather than a payload property, as is done in the hapi framework.

Name of Azure blob/filename when uploading

When I upload to azure container the filename that is saved is the uuid(guid) how can I change that?
I create the signatur by using the querystring "bloburi" added in the signature request.
$("#fine-uploader").fineUploaderAzure({
autoUpload : true,
debug: true,
validation: {
itemLimit: 10,
sizeLimit: 209715200 // 200 mb
},
resume: {
enabled: true,
id: 'ResumeUpload',
cookiesExpireIn: 7
},
extraButtons: {
folders: true
},
deleteFile: {
enabled: true
},
request: {
endpoint: 'https://xxx.blob.core.windows.net/'
},
cors: {
//all requests are expected to be cross-domain requests
expected: true,
//if you want cookies to be sent along with the request
sendCredentials: true
},
signature: {
endpoint: '/sig/'
},
uploadSuccess: {
endpoint: '/success'
}
});
The docs are wrong.
For version 4.4.0 the correct property to set is:blobProperties
// 'uuid', 'filename', or a function which may be promissory
blobProperties: {
name: "uuid"
},
I know this is an old question, but I ran into the same problem. You'll need to pass a Promise to get it to work:
name: function (id) {
return new Promise(function (resolve) {
resolve("The String You Want to Pass");
});
}
The default value for the name option is 'uuid' which will set the filename in Azure to the uuid. You can instead set it to 'filename' to have the object stored under the filename, or provide a function that will create some other name.
blobProperties: {
name: 'filename'
}
From my experience, the best method for generating filenames is to save the filename under a unique id subfolder. This guarantees that you save the original filename, and that there are no naming collisions.
blobProperties: {
name: function(id) {
var uuid = this.getUuid(id),
filename = this.getName(id);
return uuid + '/' + filename;
}
}

Categories

Resources