From 3f52cec25c971ece0082a39d75e1c81c8733302b Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 21 Nov 2024 19:17:30 +0200 Subject: [PATCH] Relocate Element Web features & element_call configuration to Element role, instead of ugly patching from the Element Call role --- group_vars/matrix_servers | 8 +++ .../matrix-client-element/defaults/main.yml | 61 +++++++++++++++++++ .../templates/config.json.j2 | 4 +- .../matrix-element-call/defaults/main.yml | 14 ++--- .../matrix-element-call/tasks/install.yml | 5 -- .../tasks/update_element_web_config.yml | 40 ------------ .../templates/well_known_element.json.j2 | 4 +- .../custom/matrix-element-call/vars/main.yml | 4 +- 8 files changed, 80 insertions(+), 60 deletions(-) delete mode 100644 roles/custom/matrix-element-call/tasks/update_element_web_config.yml diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index dad4e29d4..614ccea80 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -4498,6 +4498,14 @@ matrix_client_element_enable_presence_by_hs_url: |- matrix_client_element_jitsi_preferred_domain: "{{ matrix_server_fqn_jitsi if jitsi_enabled else '' }}" +matrix_client_element_features_feature_video_rooms: "{{ matrix_element_call_enabled }}" +matrix_client_element_features_feature_group_calls: "{{ matrix_element_call_enabled }}" +matrix_client_element_features_feature_element_call_video_rooms: "{{ matrix_element_call_enabled }}" +matrix_client_element_features_feature_oidc_native_flow: "{{ matrix_authentication_service_enabled }}" + +matrix_client_element_element_call_enabled: "{{ matrix_element_call_enabled }}" +matrix_client_element_element_call_url: "{{ matrix_element_call_public_url if matrix_element_call_enabled else '' }}" + ###################################################################### # # /matrix-client-element diff --git a/roles/custom/matrix-client-element/defaults/main.yml b/roles/custom/matrix-client-element/defaults/main.yml index 4cea592b2..50f62fb22 100644 --- a/roles/custom/matrix-client-element/defaults/main.yml +++ b/roles/custom/matrix-client-element/defaults/main.yml @@ -180,6 +180,67 @@ matrix_client_element_branding_auth_header_logo_url: "{{ matrix_client_element_w # URL to Wallpaper, shown in background of welcome page matrix_client_element_branding_welcome_background_url: ~ # noqa var-naming +# Controls the `features` section of the Element Web configuration. +matrix_client_element_features: "{{ matrix_client_element_features_default | combine(matrix_client_element_features_auto, recursive=True) | combine(matrix_client_element_features_custom, recursive=True) }}" +matrix_client_element_features_default: |- + {{ + {} + + | combine( + {'feature_video_rooms': true} if matrix_client_element_features_feature_video_rooms else {} + ) + | combine( + {'feature_group_calls': true} if matrix_client_element_features_feature_group_calls else {} + ) + | combine( + {'feature_element_call_video_rooms': true} if matrix_client_element_features_feature_element_call_video_rooms else {} + ) + | combine( + {'feature_oidc_native_flow': true} if matrix_client_element_features_feature_oidc_native_flow else {} + ) + }} + +matrix_client_element_features_auto: {} +matrix_client_element_features_custom: {} + +matrix_client_element_features_feature_video_rooms: false +matrix_client_element_features_feature_group_calls: false +matrix_client_element_features_feature_element_call_video_rooms: false +matrix_client_element_features_feature_oidc_native_flow: false + +matrix_client_element_element_call_enabled: false +matrix_client_element_element_call: "{{ matrix_client_element_element_call_default | combine(matrix_client_element_element_call_auto, recursive=True) | combine(matrix_client_element_element_call_custom, recursive=True) }}" +matrix_client_element_element_call_default: |- + {{ + {} + | combine( + {'url': matrix_client_element_element_call_url} if matrix_client_element_element_call_url else {} + ) + | combine( + {'participant_limit': matrix_client_element_element_call_participant_limit} if matrix_client_element_element_call_participant_limit else {} + ) + | combine( + {'brand': matrix_client_element_element_call_brand} if matrix_client_element_element_call_brand else {} + ) + | combine( + {'use_exclusively': matrix_client_element_element_call_use_exclusively} if matrix_client_element_element_call_use_exclusively else {} + ) + }} +matrix_client_element_element_call_auto: {} +matrix_client_element_element_call_custom: {} + +# Controls the `element_call.url` setting in the Element Web configuration. +matrix_client_element_element_call_url: '' + +# Controls the `element_call.participant_limit` setting in the Element Web configuration. +matrix_client_element_element_call_participant_limit: 8 + +# Controls the `element_call.brand` setting in the Element Web configuration. +matrix_client_element_element_call_brand: "Element Call" + +# Controls the `element_call.use_exclusively` setting in the Element Web configuration. +matrix_client_element_element_call_use_exclusively: true + matrix_client_element_page_template_welcome_path: "{{ role_path }}/templates/welcome.html.j2" # By default, there's no Element Web homepage (when logged in). If you wish to have one, diff --git a/roles/custom/matrix-client-element/templates/config.json.j2 b/roles/custom/matrix-client-element/templates/config.json.j2 index e45e68065..8dba3e2df 100644 --- a/roles/custom/matrix-client-element/templates/config.json.j2 +++ b/roles/custom/matrix-client-element/templates/config.json.j2 @@ -44,5 +44,7 @@ "auth_footer_links": {{ matrix_client_element_branding_auth_footer_links | to_json }}, "auth_header_logo_url": {{ matrix_client_element_branding_auth_header_logo_url | to_json }}, "welcome_background_url": {{ matrix_client_element_branding_welcome_background_url | to_json }} - } + }, + "features": {{ matrix_client_element_features | to_json }}, + "element_call": {{ (matrix_client_element_element_call if matrix_client_element_element_call_enabled else {}) | to_json }} } diff --git a/roles/custom/matrix-element-call/defaults/main.yml b/roles/custom/matrix-element-call/defaults/main.yml index 567553179..c65c6d078 100644 --- a/roles/custom/matrix-element-call/defaults/main.yml +++ b/roles/custom/matrix-element-call/defaults/main.yml @@ -2,10 +2,12 @@ # Enable or disable matrix-element-call deployment matrix_element_call_enabled: false +matrix_element_call_scheme: https +matrix_element_call_hostname: "call.{{ matrix_domain }}" + # Base path configuration matrix_element_call_base_path: "{{ matrix_base_data_path }}/element-call" matrix_homeserver_config_path: "{{ matrix_base_data_path }}/synapse/config/homeserver.yaml" -element_web_config_path: "{{ matrix_base_data_path }}/client-element/config.json" # Docker network configuration matrix_element_call_container_network: '' @@ -18,16 +20,10 @@ matrix_element_call_image: "ghcr.io/element-hq/element-call:latest" # Ports matrix_element_call_port: "8093" -# Well-known paths and domains (derived from matrix_domain) -matrix_element_call_domain: "call.{{ matrix_domain }}" -matrix_element_call_well_known_client_path: "{{ matrix_base_data_path }}/static-files/public/.well-known/matrix/client" -matrix_element_call_well_known_element_path: "{{ matrix_base_data_path }}/static-files/public/.well-known/element/element.json" -matrix_element_call_base_url: "https://{{ matrix_element_call_domain }}" - # Traefik Configuration for Element Call matrix_element_call_container_labels_traefik_enabled: true matrix_element_call_container_labels_traefik_docker_network: "{{ matrix_element_call_container_network }}" -matrix_element_call_container_labels_traefik_hostname: "{{ matrix_element_call_domain }}" +matrix_element_call_container_labels_traefik_hostname: "{{ matrix_element_call_hostname }}" # The path prefix must either be `/` or not end with a slash (e.g. `/element`). matrix_element_call_container_labels_traefik_path_prefix: "{{ matrix_element_call_path_prefix }}" matrix_element_call_container_labels_traefik_rule: "Host(`{{ matrix_element_call_container_labels_traefik_hostname }}`){% if matrix_element_call_container_labels_traefik_path_prefix != '/' %} && PathPrefix(`{{ matrix_element_call_container_labels_traefik_path_prefix }}`){% endif %}" @@ -122,4 +118,4 @@ matrix_element_call_hsts_preload_enabled: false # Enable or disable metrics collection matrix_element_call_metrics_enabled: false -matrix_element_call_metrics_port: 2112 \ No newline at end of file +matrix_element_call_metrics_port: 2112 diff --git a/roles/custom/matrix-element-call/tasks/install.yml b/roles/custom/matrix-element-call/tasks/install.yml index f11d002e3..f35f2a670 100644 --- a/roles/custom/matrix-element-call/tasks/install.yml +++ b/roles/custom/matrix-element-call/tasks/install.yml @@ -86,8 +86,3 @@ mode: '0644' owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - -# Update Element Web config.json with Element Call settings -- name: Update Element Web config.json - ansible.builtin.include_tasks: "tasks/update_element_web_config.yml" - when: matrix_element_call_enabled | bool diff --git a/roles/custom/matrix-element-call/tasks/update_element_web_config.yml b/roles/custom/matrix-element-call/tasks/update_element_web_config.yml deleted file mode 100644 index 2dead411e..000000000 --- a/roles/custom/matrix-element-call/tasks/update_element_web_config.yml +++ /dev/null @@ -1,40 +0,0 @@ -- name: Read Element Web config.json - ansible.builtin.slurp: - src: "{{ element_web_config_path }}" - register: element_web_config_content - -- name: Load JSON data from config.json - ansible.builtin.set_fact: - element_web_config: "{{ element_web_config_content['content'] | b64decode | from_json }}" - -- name: Update Element Call configuration in config.json - ansible.builtin.set_fact: - updated_element_call_config: > - {{ - { - "element_call": { - "url": "https://{{ matrix_element_call_domain }}", - "participant_limit": 8, - "brand": "Element Call", - "use_exclusively": true - }, - "features": { - "feature_video_rooms": true, - "feature_new_room_decoration_ui": true, - "feature_group_calls": true, - "feature_element_call_video_rooms": true - } - } - }} - -- name: Merge updated Element Call configuration with existing config.json - ansible.builtin.set_fact: - element_web_config: "{{ element_web_config | combine(updated_element_call_config, recursive=True) }}" - -- name: Write updated Element Web config.json - ansible.builtin.copy: - content: "{{ element_web_config | to_nice_json }}" - dest: "{{ element_web_config_path }}" - mode: '0644' - owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_groupname }}" diff --git a/roles/custom/matrix-element-call/templates/well_known_element.json.j2 b/roles/custom/matrix-element-call/templates/well_known_element.json.j2 index 01146e656..f7a7838b2 100644 --- a/roles/custom/matrix-element-call/templates/well_known_element.json.j2 +++ b/roles/custom/matrix-element-call/templates/well_known_element.json.j2 @@ -1,5 +1,5 @@ { "call": { - "widget_url": "https://{{ matrix_element_call_domain }}" + "widget_url": "https://{{ matrix_element_call_hostname }}" } -} \ No newline at end of file +} diff --git a/roles/custom/matrix-element-call/vars/main.yml b/roles/custom/matrix-element-call/vars/main.yml index 1f224472a..cb65e277c 100644 --- a/roles/custom/matrix-element-call/vars/main.yml +++ b/roles/custom/matrix-element-call/vars/main.yml @@ -1,5 +1,3 @@ --- -# roles/custom/matrix-element-call/vars/main.yml -# Variables specific to matrix-element-call, like service configurations, can go here. -# Any environment-specific values can be overridden here. \ No newline at end of file +matrix_element_call_public_url: "{{ matrix_element_call_scheme }}://{{ matrix_element_call_hostname }}"