Giter VIP home page Giter VIP logo

solid-comment's Introduction

Solid Comment

A simple Solid application meant to read and write comments into users’ pods. This application is only the gateway to Solid and still needs a storing mechanism in a parent application – meaning your application will import this library, which will allow the communication with Solid, but your application still needs to hold a reference where to find the actual comment.

Reminder

  • The app needs control access, there needs to be in the trust applications section with full access.

Usage

  1. Install Solid Comment
npm i solid-comment
  1. Import the library into your project
// const SolidComment = require("solid-comment")
import SolidComment from "solid-comment"
  1. Configuration
  • solidCommentId: is the unique identifier for the specific instance this module is loaded. This will always have to be unique, otherwise it will override/write to other existing directories.
  • eventVisibility: decides if the comments can be discovered without the direct link.
  • serverStorageEndpointUrl: is the endpoint where the application implementing this module will persist references to the comments that have been posted. This endpoint will receive a JSON object with a url key and its value the URL to the comment. No more information is needed nor should be stored.
const solidComment = new SolidComment({
    solidCommentId: "sc-development-private-event-1",
    eventVisibility: "private",
    serverStorageEndpointUrl: "https://server-where-comment-urls-are-persisted"
})
  1. Initialize application

This will render all the components as soon as the DOM is completely ready. This is important as the components need elements from the DOM to attach to. The application will also check for a session, this is needed for the authentication with a Solid identity provider.

solidComment.initApp()
  1. Pass comment URLs to application

If the comments cannot be retrieved immediately on page render, they can be asynchronously fetched and passed to the application. SolidComment expects a list of strings with the URL to a single comment.

// these should be ["url-to-comment-1", "url-to-comment-2", …]
solidComment.setComments(comments)

Indico

  1. Install solid-comment in Indico
npm i solid-comment
  1. Import library in the JavaScript files where it is needed
// indico/modules/events/client/js/display.js

import { SolidComment } from 'solid-comment'
  1. Make sure axiosIndico is bound to window.indicoAxios
import {indicoAxios} from 'indico/utils/axios';
// …
function bindIndicoAxiosToWindow() {
  window.indicoAxios = indicoAxios;
}
// …
bindIndicoAxiosToWindow()
  1. Add HTML and JavaScript to initialize solid-comment
<!-- indico/modules/events/templates/display/indico/meeting.html -->
<main class="solid-comment">
    <!-- paste content of src/index.html -->
</main>

<script>
  function pythonBooleanToJS(str) {
      return str === 'True'
  }

  window.onload = () => {
      const isEventProtected = pythonBooleanToJS('{{ event.is_protected }}');
      const eventVisibility = isEventProtected ? "private" : "public";
      const eventId = '{{ event.id }}'
      const solidCommentId = `sc-indico-meeting-${eventVisibility}-${eventId}`;
      const serverUrl = `http://127.0.0.1:8000/event/${eventId}/solid-comments`
      const solidComment = new SolidComment({
          solidCommentId: solidCommentId,
          eventVisibility: eventVisibility,
          serverStorageEndpointUrl: serverUrl,
          appUrl: window.location.href.split('?')[0]
      })

      async function main() {
          await solidComment.initApp()
          solidComment.setAppClient(window.indicoAxios)
          await fetch(serverUrl)
              .then(response => response.json())
              .then(data => solidComment.setComments(data))
      }
      main()
  }

Extra HTTP Client

If your application holding the references to the comments requires extra configuration to enable communication with the storage endpoint, the setAppClient method in the SolidComment class sets a passed in client, which will then be used to GET and POST to the provided storage endpoint.

// const solidComment = new SolidComment({ … })
solidComment.setAppClient(axios.create())
// Indico example:
// solidComment.setAppClient(window.indicoAxios)

Development

  1. Clone the repository
$ git clone [email protected]:janschill/solid-comment.git
$ cd solid-comment
  1. Install dependencies
$ npm ci
  1. Run webpack development server
$ npm start
  1. Copy index.html into dist/ directory
$ cp src/index.html dist/index.html
  1. Start the JSON server
$ npm run json-server # $ json-server db.json -p 3001

Design Choices

  • This library stores each comment in a single file. Also, will the parent application implementing this library hold the reference URL to each comment. This enables the easiest possibility to add a pagination feature and thus improve performance by only loading the necessary comments.
  • If a comment fails to be fetch from the by the server (Indico) persisted list of references to the comment, it will simply show a “Comment is unavailable.” notice in the interface.

solid-comment's People

Contributors

janschill avatar thiefmaster avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

thiefmaster

solid-comment's Issues

Integrate with Indico

For the integration with Indico one thing is still needed, which is the persistence layer within Indico to store the references to the pods.
As a temporary solution the EventSettingsProxy can be used.
The event_core_settings is probably a good candidate to be enriched.

Add missing reference to Indico if more comments exist?

Should this module (or rather Indico) check and synchronize the references that Indico holds to the comments? When a comment is saved to the pod, but there is a problem with the creation of the reference to it in Indico.

How to overwrite ACL

Currently when the agent logs in and posts a comment, without having given the application control access mode it does not overwrite the ACLs and therefore cannot set them to the correct access permissions and thus they cannot be pulled from the pod.

Load and render individual comments

This would mean the comments are not depended on each other and they can be all added asynchronously. This would make the performance of the module better as the different pod hosts will have different latencies.

Times on comment differ

When a new comment is created by submission the generated time differs to the received time when fetching the comment from the pod later on

20210325T100058487Z.ttl

becomes

20210325T100058000Z.ttl

Sorting breaks when comment unavailable

Extract time from comment file name and add to the comment object.
Careful, because then the comment object is not empty anymore and the rendering of the empty comment HTML needs to be caught differently.

Evaluate application

To-do

  • Write integration tests
    • Deletion of comments
    • From pod
    • From interface
    • From Indico?
  • Write unit tests
  • Perfomance
    • Caching?
  • Security
    • Confidentiality
    • Integrity
    • Availability
    • Think of how to make URL to comment for private event truly random and not guessable.

Questions

  • How do I mock a pod locally/in test?
  • How do I test performance? I can reason about it: a request per comment etc.

Deleting comment reference in Indico

It is not possible to delete the reference in Indico.
We do not do any authentication/authorization against Indico, therefore, it is not possible to delete the reference that is kept with Indico. If the DELETE does not require authentication, everyone can obviously just delete comments.

Solution: keep the reference in Indico and render (as already implemented) the “Comment is unavailable” message. We could even hide all deleted comments from the currently logged in author …

Change to container ACL describing the permissions for its resources

Currently, all resources get a dedicated ACL file, this can be changed to the following to enable the same functionality.

World read on container resources:

@prefix acl: <http://www.w3.org/ns/auth/acl#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix target: <./>.

:ReadDefault
    a acl:Authorization;
    acl:default target:;
    acl:agentClass foaf:Agent;
    acl:mode acl:Read.

:ReadWriteControl
    a acl:Authorization;
    acl:accessTo target:;
    acl:default target:;
    acl:agent </profile/card#me>;
    acl:mode acl:Read, acl:Write, acl:Control.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.