Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-77356

Add flag to sync image/avatar from communication plugins

    XMLWordPrintable

Details

    • MOODLE_402_STABLE
    • MOODLE_403_STABLE
    • MDL-77356-master
    • Hide

      Environment setup

      NOTE: You have options here.

      1. If you are using moodle-docker then you may find the Moodle-docker environment setup approach easier.
      2. If you are not, then try Andrew's environment setup

      Option #1: Moodle-docker environment setup

      This setup is a modified version of https://github.com/mattporritt/moodle-docker

      You can follow along in more detail using the link.

      You will require:

      • PHP 8 or greater
      • Docker
      • OpenSSL

      Docker

      We start by cloning our fork of the Moodle Docker repository:

      git clone git@github.com:mattporritt/moodle-docker.gitgit checkout omnibus

      Copy the sample config file to your Moodle root:

      cp moodle-docker/config.docker-template.php moodle_local/config.php

      Copy the sample environment file:

      cp moodle-docker/.env.example moodle-docker/.env

      Update the MOODLE_DOCKER_WWWROOT variable in the .env file to the location of your Moodle root folder.

      Host file

      Update your local hosts file (etc/hosts)to include the following:

      127.0.0.1 localhost synapse webserver keycloak element

      SSL Setup

      Make the self-signed certs so we can run Moodle and associated services over ssl/tls.

      Change to the directory of the script first:

      cd moodle-docker/moodle_dev/assets/certs

      Run the script and fill out the certificate details. Pay attention to the prompts. Fill in all data:

      ./createcerts.sh webserver

      The first time the script is run it will generate a root cert and key. After that it will re-use the root cert and just make the certs required for each service we want to run using SSL/TLS.

      Run it for each additional service we need

      ./createcerts.sh keycloak 
      ./createcerts.sh synapse 
      ./createcerts.sh element
      

      Next we add the root CA, this is to remove the browser self signed errors. To add the root CA to the Mac OS keychain. Run this on this host machine:

      sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" ca.pem

      Build and install

      Next we need to build our version of the moodle dev container:

      cd moodle-docker/moodle_dev
      docker build -t "stevando:moodle_dev" .

      Finally, actually start the services:

      cd moodle-docker/bin
      ./moodle-docker-compose up -d

      Synapse admin user

      We also need to create an initial Synapse admin user. This is the user you'll need before you can use the Matrix API. To create an initial admin user:

      docker exec -it CONTAINER_ID register_new_matrix_user \
      -u admin \
      -a \
      -c /data/homeserver.yaml \
      https://synapse:8008/

      Where CONTAINER_ID is the Docker ID of the running Synapse container.

      You will need to get the access token for this user. This can be done by accessing the following file with a database editor:

      cd moodle-docker/synapse_data/homeserver.db

      Look for the table access_tokens and the field token. You will need this token later on.

      Site URLs

      Once the following steps are complete the sites can be accessed at the following URLs:

      Option #2: Andrew's environment setup

      1. Clone Andrew's helper repository:

        git clone https://github.com/andrewnicols/moodle-synapse
        cd moodle-synapse
        

      2. Run the docker-compose up command:

        docker compose up -d
        

      3. Wait for about 10 seconds for the first run to complete
      4. Run the setup script:

        ./setup.sh
        

      5. Copy the command it outputs
      6. Change into your Moodle directory
      7. Paste in the command, for EXAMPLE:

        cd path/to/moodle
        sed -i '/^require_once.*lib.*setup.php.*$/i require_once("/Users/nicols/git/moodlehq/synapse/moodle-config.php");' config.php
        cd -
        

      8. If you have not done so already, edit your /etc/hosts file to add:

        127.0.0.1 element.container.docker.internal element
        127.0.0.1 synapse.container.docker.internal synapse
        127.0.0.1 keycloak.container.docker.internal keycloak
        

      9. Follow the instructions at https://github.com/andrewnicols/moodle-synapse#trusting to trust the root CA that is used for this.

      Moodle setup

      Now that you have your environment setup, you will have access to several important resources (element, synapse, keycloak, etc). Let's configure Moodle.

      1. Login to Moodle as admin
      2. Navigate to Site admin > Development > Experimental settings and enable 'Enable communication subsystem'
      3. Navigate to Site admin > Plugins > Communication > Manage communication providers and ensure 'Matrix' is enabled.
      4. Navigate to Site admin > Plugins > Communication > Matrix
      5. Add the home server url (e.g. https://synapse:8008).
      6. Add the access token (available from the environment setup)
      7. Add the refresh token if available, otherwise use the access token
      8. Add the element server url (e.g. https://element:8081)
      9. Save your changes
      10. Navigate to Site admin > HTTP Security
      11. Add 8008 and 8443 to the allowed ports

      Test scenario

      1. Navigate to the create a new course form
      2. Add all the required information to the form
      3. Add a course image
      4. Scroll down to the Communication section
      5. Set the Communication service to 'Matrix'
      6. Set Room name to 'Test room'
      7. Save changes.
      8. Run the queued adhoc tasks by running cron from the command line php admin/cli/cron.php
      9. Go to your newly created Matrix room using the link/icon in the bottom right corner.
      10. Log in using the user created during setup (if using Andrew's tooling that is the following):
        • username: `moodlebot`
        • password: `password`
      11. CONFIRM the avatar image for the room was set that same as the course image
      12. Navigate back to your course edit page.
      13. Change the course image to a different picture.
      14. Save changes.
      15. Run cron from the command line (see code snippet above).
      16. Go back to your Matrix room.
      17. CONFIRM that you see a new entry 'Admin changed the room avatar to ...'
      18. Go back to your course edit page.
      19. Click 'Save and display' (no changes made).
      20. Run cron from the command line (see code snippet above).
      21. Go back to your Matrix room.
      22. CONFIRM that there is no new entry about the room avatar being updated.
      23. Go back to your course edit page.
      24. Remove the course image.
      25. Save changes.
      26. Run cron from the command line (see code snippet above).
      27. Go back to your Matrix room.
      28. CONFIRM that you see a new entry 'Admin User removed the room avatar'

       

      Show
      Environment setup NOTE: You have options here. If you are using moodle-docker then you may find the Moodle-docker environment setup approach easier. If you are not, then try Andrew's environment setup Option #1: Moodle-docker environment setup This setup is a modified version of https://github.com/mattporritt/moodle-docker You can follow along in more detail using the link. You will require: PHP 8 or greater Docker OpenSSL Docker We start by cloning our fork of the Moodle Docker repository: git clone git@github.com:mattporritt/moodle-docker.gitgit checkout omnibus Copy the sample config file to your Moodle root: cp moodle-docker/config.docker-template.php moodle_local/config.php Copy the sample environment file: cp moodle-docker/.env.example moodle-docker/.env Update the MOODLE_DOCKER_WWWROOT variable in the .env file to the location of your Moodle root folder. Host file Update your local hosts file ( etc/hosts) to  include the following: 127.0.0.1 localhost synapse webserver keycloak element SSL Setup Make the self-signed certs so we can run Moodle and associated services over ssl/tls. Change to the directory of the script first: cd moodle-docker/moodle_dev/assets/certs Run the script and fill out the certificate details. Pay attention to the prompts. Fill in all data: ./createcerts.sh webserver The first time the script is run it will generate a root cert and key. After that it will re-use the root cert and just make the certs required for each service we want to run using SSL/TLS. Run it for each additional service we need ./createcerts.sh keycloak  ./createcerts.sh synapse  ./createcerts.sh element Next we add the root CA, this is to remove the browser self signed errors. To add the root CA to the Mac OS keychain. Run this on this host machine: sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" ca.pem Build and install Next we need to build our version of the moodle dev container: cd moodle-docker/moodle_dev docker build -t "stevando:moodle_dev" . Finally, actually start the services: cd moodle-docker/bin ./moodle-docker-compose up -d Synapse admin user We also need to create an initial Synapse admin user. This is the user you'll need before you can use the Matrix API. To create an initial admin user: docker exec -it CONTAINER_ID register_new_matrix_user \ -u admin \ -a \ -c /data/homeserver.yaml \ https://synapse:8008/ Where CONTAINER_ID is the Docker ID of the running Synapse container. You will need to get the access token for this user. This can be done by accessing the following file with a database editor: cd moodle-docker/synapse_data/homeserver.db Look for the table access_tokens and the field token.  You will need this token later on. Site URLs Once the following steps are complete the sites can be accessed at the following URLs: Moodle LMS:  https://webserver/ Keycloak:  https://keycloak:8443/ Element:  https://element:8081/ Synapse:  https://synapse:8008/ Option #2: Andrew's environment setup Clone Andrew's helper repository: git clone https://github.com/andrewnicols/moodle-synapse cd moodle-synapse Run the docker-compose up command: docker compose up -d Wait for about 10 seconds for the first run to complete Run the setup script: ./setup.sh Copy the command it outputs Change into your Moodle directory Paste in the command, for EXAMPLE : cd path/to/moodle sed -i '/^require_once.*lib.*setup.php.*$/i require_once("/Users/nicols/git/moodlehq/synapse/moodle-config.php");' config.php cd - If you have not done so already, edit your /etc/hosts file to add: 127.0.0.1 element.container.docker.internal element 127.0.0.1 synapse.container.docker.internal synapse 127.0.0.1 keycloak.container.docker.internal keycloak Follow the instructions at https://github.com/andrewnicols/moodle-synapse#trusting to trust the root CA that is used for this. Moodle setup Now that you have your environment setup, you will have access to several important resources (element, synapse, keycloak, etc). Let's configure Moodle. Login to Moodle as admin Navigate to  Site admin > Development > Experimental settings  and enable 'Enable communication subsystem' Navigate to  Site admin > Plugins > Communication > Manage communication providers  and ensure 'Matrix' is enabled. Navigate to  Site admin > Plugins > Communication > Matrix Add the home server url (e.g. https://synapse:8008 ). Add the access token (available from the environment setup) Add the refresh token if available, otherwise use the access token Add the element server url (e.g.  https://element:8081) Save your changes Navigate to  Site admin > HTTP Security Add 8008 and 8443 to the allowed ports Test scenario Navigate to the create a new course form Add all the required information to the form Add a course image Scroll down to the Communication section Set the Communication service to 'Matrix' Set Room name to 'Test room' Save changes. Run the queued adhoc tasks by running cron from the command line php admin/cli/cron.php Go to your newly created Matrix room using the link/icon in the bottom right corner. Log in using the user created during setup (if using Andrew's tooling that is the following): username: `moodlebot` password: `password` CONFIRM the avatar image for the room was set that same as the course image Navigate back to your course edit page. Change the course image to a different picture. Save changes. Run cron from the command line (see code snippet above). Go back to your Matrix room. CONFIRM that you see a new entry 'Admin changed the room avatar to ...' Go back to your course edit page. Click 'Save and display' (no changes made). Run cron from the command line (see code snippet above). Go back to your Matrix room. CONFIRM that there is no new entry about the room avatar being updated. Go back to your course edit page. Remove the course image. Save changes. Run cron from the command line (see code snippet above). Go back to your Matrix room. CONFIRM that you see a new entry 'Admin User removed the room avatar'  
    • 6
    • Team Hedgehog 2023 Sprint 1.3, Team Hedgehog 2023 Sprint 1.4, Team Hedgehog 2023 Sprint 2.0, Team Hedgehog 2023 Sprint 2.1, Team Hedgehog 2023 Sprint 2.2, Team Hedgehog 2023 Sprint 2.3
    • Small

    Description

      Matrix currently has an api to update the room avatar for a room. At the moment, there is no mechanism in Moodle or in matrix to compare the change in image when a new image is passed through the api to update the image. For example, if the same image is passed, it wont understand if thats a new image or the same image. Which is not good for efficiency and it also keeps sending information in the room that admin has updated the avatar.

      There are two possible ways to solve this:

      1. Compare the current course image with the incoming image and set a flag if the provider needs to be updated.
      2. Record the image hash of the avatar when it has been uploaded to the provider and compare that the next time the course image is changed.

      Some more information about setting room avatar is added below. This implementation is already present in MDL-76702. This tracker will add efficiency around that.

      Setting room avatar:

      This is a two part process. First the image to be used as the room avatar to Synapse. Next we need to set the avatar to the location of the image.

      curl 'https://synapse:8008/_matrix/media/r0/upload?filename=imagename.png' -X POST -H 'Content-Type: image/png' -H 'Authorization: Bearer syt_YWRtaW4_KXUwoITuowupgGEIGNuK_4MLu3S' -d @/location/of/image/imagename.png

      This will return the location of the saved image:

      {"content_uri":"mxc://synapse/ThJDXaRGnpFUdIjlUyiqVICQ"}

      Next we update the avatar:

      curl 'https://synapse:8008/_matrix/client/r0/rooms/!IWCtGkszxDkBUrIsGg%3Asynapse/state/m.room.avatar/' -X PUT -H 'Authorization: Bearer syt_YWRtaW4_KXUwoITuowupgGEIGNuK_4MLu3S' -d '{"url":"mxc://synapse/ThJDXaRGnpFUdIjlUyiqVICQ"}'

      All of these types of actions are known as events (https://spec.matrix.org/v1.5/client-server-api/#events ).

      They will return an event id.

      Attachments

        1. MDL-77356 1.png
          MDL-77356 1.png
          42 kB
        2. MDL-77356 2.png
          MDL-77356 2.png
          45 kB
        3. MDL-77356 3.png
          MDL-77356 3.png
          46 kB

        Issue Links

          Activity

            People

              david.woloszyn@moodle.com David Woloszyn
              safat.shahin@moodle.com Safat Shahin
              Safat Shahin Safat Shahin
              Andrew Lyons Andrew Lyons
              Simey Lameze Simey Lameze
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 week, 2 days, 35 minutes
                  1w 2d 35m

                  Clockify

                    Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.