eduardoboucas / staticman

💪 User-generated content for Git-powered websites
https://staticman.net
MIT License
2.41k stars 532 forks source link

It is possible to update a current file? #309

Open NoobTaco opened 5 years ago

NoobTaco commented 5 years ago

I am trying to update a post that I created with staticman for my jekyll site.

Here is my config.

editaddons:
  allowedFields:
    [
      'title',
      'body',
      'curselink',
      'wowilink',
      'websitelink',
      'gitlink',
      'image',
      'status',
      'categories',
      'editorsname',
      'editreason',
    ]
  branch: 'develop'
  commitMessage: 'Edit Addon'
  format: 'frontmatter'
  generatedFields:
    date:
      type: date
    slug:
      type: slugify
      options:
        field: title
    layout: addon
    draft: false
  filename: '{fields.slug}'
  moderation: true
  name: 'xxxxxxxxsic.com'
  path: '_addons'
  requiredFields: ['title', 'body', 'editorsname', 'editreason']
  transforms:
    email: md5
    body: 'frontmatterContent'

And the error I am getting when trying to overright the same file.

{  
   "success":false,
   "rawError":{  
      "message":"{\"message\":\"Invalid request.\\n\\n\\\"sha\\\" wasn't supplied.\",\"documentation_url\":\"https://developer.github.com/v3/repos/contents/#create-or-update-a-file\"}",
      "statusCode":422
   },
   "errorCode":"GITHUB_FILE_ALREADY_EXISTS"
}

Is it possible to oversight? I am starting to think the sha message could be a key, but I am unsure how to proceed.

Thank you for any help.

VincentTam commented 5 years ago

@NoobTaco That's the expected behavior of this Node.JS app. The filename for each POST request is set to {fields.slug}, which is a function of fields.title, which is a function of Jekyll's {{ page.title }} (or similar page variables in other static blog generators). Therefore, for the same {{ page.title}}, {fields.slug} is the same. When a blog entry receives the first comment, the file is named as _addons/{fields.slug}. When the second comment is sent, the filename is still _addons/{fields.slug}, so this gives the above error.

editaddons:
  allowedFields: [...]
  generatedFields:
    date:
      type: date
    slug:
      type: slugify
      options:
        field: title
  filename: '{fields.slug}'
  path: '_addons'

To avoid this error, a common way is to group comment data files into the same subfolder :file_folder:, and use the timestamp for filename. Here's a working example: https://github.com/daattali/beautiful-jekyll/blob/5dca8a44ff42c8e8069a01a5364666cd2c8089c9/staticman.yml

alexwaibel commented 4 years ago

Question seems to have been answered by @VincentTam. Resolved.

danieldreke commented 4 years ago

No, @NoobTaco is asking if it is possible to update an existing comment file and if so, how to do it, as github wants the sha code of the file to be updated. @VincentTam is talking about something different, grouping comments into subfolders respresenting the posts. Please reopen as it hasn't been answered and would be an awesome feature if comments could be edited/updated. Am not able to figure out where respectively if it is possible to add sha field somewhere in staticman codebase. Any help greatly appreciated. Thank you.

alexwaibel commented 4 years ago

@danieldreke you're right, this doesn't appear to have actually been resolved. I will open this back up for discussion.

While such a feature would be possible, I feel like it would be open to abuse. Essentially anyone could send your API a request and overwrite any comment on your website, which seems dangerous. This is less dangerous with moderation enabled, but even so I can't imagine a way in which you'd be able to verify on the front end that the user requesting an edit is the same user that made the comment.

Without enabling comments to be edited, you could still add a reply feature to your website using nested comments. This would allow a user to reply to their original comment with some further clarification.

danieldreke commented 4 years ago

Hi @alexwaibel and thanks for reopening. Hmm, good point. What about the user has to reenter the e-mail-address he has provided when doing his comment or a password, set by the user or a generated code, sent to his mail, so that he can edit the comment later? and the code is added to comment file as field. I thought about using staticman for something like dynamic content and users do not need an account to edit a website or parts of a website or like editable/appendable access to parts of a website.

VincentTam commented 4 years ago

Sorry for super-late reply.

@danieldreke I see your point. I think OP's problem described in the question context doesn't require the feature request, which would have been much better to be put in a separate issue because of the one-issue-one-problem principle. Given that we've already started the discussion about the FR, I'll add my comment to the pile.

With respect to the recently established GPDR, I see a motive to ask the collector of static comments, which are a form of data, for a modification. However, let's think about the target users:

  1. Dev'ers/Prog'ers: they have Git acct, so they can simply jump into the corresponding auto-gen'd Git issue and ask the site owner for changing. That would fail if the source code for the static site isn't public.
  2. Others who don't write code: examples incl writers, commentators, etc. I doubt if they would bother to take the steps above to have their comments changed.

It seems technically possible, but who practically needs that?