Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Users
    • Groups
    1. Home
    2. venkAT
    3. Best
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 10
    • Best 2
    • Groups 0

    Best posts made by venkAT

    • Unable to edit the post privilages issues

      Unable to edit the post privilages error

      posted in General Discussion
      venkAT
      venkAT
    • Tags are not updated while editing the post (/api/v2/posts/:pid)

      Hello @julian @PitaJ

      My local Nodebb Version : v1.16.2

      I am trying to edit my own post and I want to update the content , title and tags

      Here is my payload

      curl --location --request PUT 'http://localhost:4567/api/v2/posts/17' \
      --header 'Authorization: Bearer 0257ecdd-ffd7-4a79-a2c4-2244aa490c2d' \
      --header 'Content-Type: application/json' \
      --header 'Cookie: express.sid=s%3AbIhfigykYJ3MKanc6ShQ2gGxoZ6xccjE.s02leB%2BLFWGPnXG1IBQQdaTb8gD%2BDobwa05UEYja1Ws' \
      --data-raw '{
          "pid": 17, 
          "content": "Edit my own post alsong with tags",
          "title": "Edit post",
          "tags": ["edit", "update", "tagCheck"]
      }'
      

      And I got response back

      {
          "code": "ok",
          "payload": {}
      }
      

      But the tags are not updated, check the screenshot
      6f76780c-001c-4e52-a6c2-0fd67320a455-image.png

      These are my findings
      STEP: 1 - Nodebb-WriteAPI
      in write api plugin for the api /api/v2/posts/:pid
      verify From line number 19 to 33
      https://github.com/NodeBB/nodebb-plugin-write-api/blob/master/routes/v2/posts.js#L19

      Here the tags are added into options object - #Line: 29

      in write api the final object looks like this

       {
        uid: 18,
        pid: '17',
        content: 'Edit my own post alsong with tags',
        options: { tags: [ 'edit', 'update', 'tagCheck' ] },
        title: 'Edit post'
      }
      

      STEP:2 - NodeBB (POSTS section)
      As par the above git link #lineNo: 31 we are calling parent funtion posts.edit so that will come to NodeBB src/posts/edit.js file.
      Verify Here:
      https://github.com/NodeBB/NodeBB/blob/master/src/posts/edit.js#L126

      You are access the tags from data object data.tags but Actually tags present in data.options.tags

      Referencs Data object in Nodebb

       {
        uid: 18,
        pid: '17',
        content: 'Edit my own post alsong with tags',
        options: { tags: [ 'edit', 'update', 'tagCheck' ] },
        title: 'Edit post'
      }
      

      And finally The updated data object looks like

      {
        tid: 17,
        cid: 2,
        uid: 18,
        title: 'Edit post',
        oldTitle: 'Edit post',
        slug: '17/edit-post',
        isMainPost: true,
        renamed: false,
        tags: []
      }
      

      Because off the tags access from wrong place, causing issue for updating the tags while editing the post

      my local practice

      1. in my local I changed the tags accessing in Nodebb(/src/posts/edit.js#LineNo: 126) from data.tags = data.tags || []; to data.tags = data.options.tags || [];

      After that the tags are updating for that post

      CC: @vinu

      posted in Bug Reports
      venkAT
      venkAT