I am using Collection2 for form insert and validation. It works great.
My only issue using the context to access the keys for presenting errors back to the user on the client.
I have the following code:
Common.coffee
Schemas = {}
Schemas.Journal = new SimpleSchema
goal:
type: String
label: "Related Goal"
max: 200
description:
type: String
label: "Comment"
max: 200
likes:
type: Number
label: "Likes"
min: 0
createdBy:
type: String
max: 50
createdAt:
type: Date
label: "Created At"
Journal.attachSchema(Schemas.Journal)
journalContext = Schemas.Journal.namedContext("insertForm")
On Client:
Template.journalForm.events
'submit #newEntryForm': (event) ->
text = event.target.text.value
Meteor.call("newJournalEntry", Session.get("activeGoal"), text)
On Server as a Method:
'newJournalEntry': (goalId, text) ->
Journal.insert
goal: goalId
description: text
createdAt: new Date()
createdBy: Meteor.userId()
likes: 0
{validationContext: "insertForm"}, (error, result) ->
if error
console.log error.invalidKeys
else
console.log "#{result} added to Journal collection."
The validation works correctly on the server and when insert is denied I see the correct messages via terminal, but calling the validation context ON THE CLIENT always gives back an empty array. []
Either of the following work on the server, but if I try these on the client they are empty:
Schemas.Journal.namedContext("insertForm").invalidKeys()
or
error.invalidKeys
UPDATE:
I tried a few more tries at the syntax ON THE CLIENT. Same empty array result. Here are the attempts:
Schemas.Journal.namedContext().invalidKeys()
journalContext.invalidKeys()
Schemas.Journal.namedContext("insertForm").invalidKeys()
Related
How do I set the note field?
When I try to add a new Client with the following data (taken from logged request):
method: 'post',
data: '{"name":"Inger Lise Suprice AS","note":"10017"}',
I get the following response:
data: {
id: '***',
name: 'Inger Lise Suprice AS',
workspaceId: '***',
archived: false,
address: null,
note: null <-----
}
Notice the 'note' field is null, even though I set the field in the request.
I followed the example in the documentation. Assuming this is a bug.
Error: Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The value for the field 'Date.$' must be a valid JSONPath at /States/Insert Data Dynamodb/Parameters' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition;
below is the corresponding serverless.yaml code.
I tried wrapping the two parameters into encoded json string and passed it as single payload field and it resulted in the same error but when there is only one plain field in the payload this code deployed successfully
Any suggestions on how to pass two parameters?
service: service-name
frameworkVersion: '2'
provider:
name: aws
runtime: go1.x
lambdaHashingVersion: 20201221
stage: ${opt:stage, self:custom.defaultStage}
region: us-east-1
tags: ${self:custom.tagsObject}
logRetentionInDays: 1
timeout: 10
deploymentBucket: lambda-repository
memorySize: 128
tracing:
lambda: true
plugins:
- serverless-step-functions
configValidationMode: error
stepFunctions:
stateMachines:
sortData:
name: datasorting-dev
type: STANDARD
role: ${self:custom.datasorting.${self:provider.stage}.iam}
definition:
Comment: "Data Sort"
StartAt: Query Data
States:
Query Data:
Type: Task
Resource: arn:aws:states:::athena:startQueryExecution.sync
Parameters:
QueryString: >-
select * from table.data
WorkGroup: primary
ResultConfiguration:
OutputLocation: s3://output/location
Next: Insert Data Dynamodb
Insert Data Dynamodb:
Type: Task
Resource: arn:aws:states:::lambda:invoke
Parameters:
FunctionName: arn:aws:lambda:us-east-1:${account-id}:function:name
Payload:
OutputLocation.$: $.QueryExecution.ResultConfiguration.OutputLocation
Date.$: ${self:custom.dates.year}${self:custom.dates.month}${self:custom.dates.day}
End: true
Your Date.$ property has value of ${self:custom.dates.year}${self:custom.dates.month}${self:custom.dates.day}. Let's assume that:
const dates = {
"year": "2000",
"month": "01",
"day": "20"
}
The result will be Date.$: "20000120" which is not a valid JSON Path.
JSON Path needs to start with a $ sign and each level is divided by ..
Do you want to achieve something like this? $.2000.01.20?
As you see, the issue is not with passing 2 parameters but with wrong string JSON Path created by string interpolation for Date.$.
Some useful links:
https://github.com/json-path/JsonPath
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-paths.html
I'm having this issue while I'm trying to perform a crud update function. To put into context, this is an Ionic app with Firebase. This is an app in which the user will be able to create events and update them at a later stage if they want. However, I'm not being able to perform the update with the following error:
ERROR FirebaseError: Function DocumentReference.update() called with invalid data. Nested arrays are not supported (found in document Events/XWtRgH04iEG9IUIqMrgX)
Below are highlighted the function that will save an event after being updated and the service that contains the update function. Any help is greatly appreciated!
saveEvent(event) {
let id = event.id;
let evtSave = {
id: id,
createdAt: event['createdAt'],
createdBy: event['createdBy'],
updatedAt: Date.now(),
part: event['part'] || ['No participants'],
comments: event['comments'] || ['No comments'],
type: event['type'],
title: event['title'],
date: event['date'],
time: event['time'],
map: event['map'],
players: event['players'],
location: event['location'],
description: event['description'],
image: event['image']
};
console.log('saveEvent: ', evtSave);
this.eventServ.updateEvents(id, evtSave)
.then(res => {
this.searchEvents();
console.log('Event: ', res);
this.myAlert('Event successfully updated');
this.mode = 'listMode';
});
Below is the code contained in the service:
updateEvents(eventID, event){
return this.firestore.collection('Events').doc(eventID).update(({
id: event.id,
createdAt: event.date,
createdBy: event.createdBy,
updatedAt: Date.now(),
part: [event.part],
comments: [],
type: event.type,
title: event.title,
date: event.dateMilis,
time: event.time,
map: event.map,
players: event.players,
location: event.location,
description: event.description || 'No description...',
image: event.image || 'No image...',
})).catch((error)=>{
console.log('Error: ', error);
})
and finally a screenshot of how an event looks like in firebase:
At one place in your code you have part: event['part'] || ['No participants'], which will set part to an array of stringy, containing exactly one participant.
Later, when you save, you do: part: [event.part], which I assume can lead to the case where you will get part: [['No participants']].
This is a nested array and as firebase tells you in the error message, this is not supported in firestore.
In order to validate the installation of WordPress instances, we are writing Python unit tests. One of the test should perform the following action: upload an image to WordPress.
In order to do that, I am using the Requests library.
When I inspect the form within /wp-admin/media-new.php page through Firebug (form information, I get the following information):
Form
Id: file-form
Name
Method: post
Action: http://localhost:8000/wp-admin/media-new.php
Elements
id: plupload-browse-button
type: button
value: Select Files
id:async-upload
name: async-upload
type: file
label: Upload
id:html-upload
name: html-upload
type: submit
value: Upload
id: post_id
name: post_id
type: hidden
value: 0
id: _wpnonce
name: _wpnonce
type: hidden
value: c0fc3b80bb
id: file-form
name: _wp_http_referer
type: hidden
value: /wp-admin/media-new.php
I believe that the _wpnonce is a unique value generated for each session. Therefore, before trying to upload the file, I get the media-new.php page and grab the _wpnonce in the form (hence the variable in my code).
My code is the following:
with open('1.jpg', 'rb') as f:
upload_data = {'post_id': '0',
'_wp_http_referer': '/wp-admin/media-new.php',
'_wpnonce': wp_nonce,
'action': 'upload_attachement',
'name': '1.jpg',
'async-upload': f,
'html-upload': 'Upload'}
upload_result = session.post('http://localhost:8000/wp-admin/media-new.php', upload_data)
The code runs fine and the upload_result.status_code equals 200.
However, the image never shows up in the media gallery of WordPress.
I believe this a simple error, but I can't figure out what I'm missing.
Thanks in advance for the help.
If you want to post files you should use the files parameter. Also the '_wpnonce' value is not enough to get authenticated, you need to have cookies.
url = 'http://localhost:8000/wp-admin/media-new.php'
data = {
'post_id': '0',
'_wp_http_referer': '/wp-admin/media-new.php',
'_wpnonce': wp_nonce,
'action': 'upload_attachement',
'html-upload': 'Upload'
}
files = {'async-upload':('1.jpg', open('1.jpg', 'rb'))}
headers = {'Cookie': my_cookies}
upload_result = session.post(url, data=data, files=files, headers=headers)
I'm assuming that you have acquired valid cookies from your browser. If you want to get authenticated with requests check my answer to this post: login-wordpress-with-requests
I want to publish only a limited amount of data to the client.
I've tried to do it like this:
# server
Meteor.publish('users', ->
Meteor.users.find({},
fields:
services: 0
)
)
But the client still receives the whole object.
# client
Meteor.startup( ->
Meteor.subscribe('users')
)
# ...
# in another function
Meteor.users.find().observe( ->
changed: (updated) ->
console.log updated
)
What am I doing wrong?
Meteor.publish '', ->
Posts.find({}, { fields: { title: 1, content: true, secret: false } });
what about add those {}
The code below works for me (coffeescript). The pwd field isn't published.
Server
Meteor.publish "users", (userId) ->
user = Users.find userId,
fields:
pwd: false
return user
Client
Meteor.autosubscribe ->
userId = Session.get SESSION_USER
Meteor.subscribe 'users', userId
The only differences I see are
0 vs false... (should be a matter of taste, only)
Your collection is accessed via Meteor
In the client my subscription is placed inside a autosubscribe callback while you're using the observe method.
Do the fields exists in the result of Meteor.users.find().fetch() in the browsers console, too?