Skip to content

About

The sources for HelsinkiUni Help

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UniHelp

This is a project for University of Helsinki's UniHelp service. It is based on wunderio/drupal-project. It is designed for deploying to code automatically to Silta environment(s).

Production environment

Environment variables for silta_finland context

The following secret variables are defined in the silta/silta-prod.secrets file for the silta_finland context:

  • AZURE_OPENAI_APIKEY - API key for Azure OpenAI
  • AZURE_OPENAI_EMBEDDINGS_ENDPOINT - Embeddings endpoint for Azure OpenAI
  • AZURE_OPENAI_COMPLETIONS_ENDPOINT - Completions endpoint for Azure OpenAI
  • EFECTE_API_KEY - API key for Efecte webform integration
  • EFECTE_API_KEY_TEST - API key for Efecte endpoint environment webform integration
  • FLAMMA_USERNAME - Username for Flamma content crawler
  • FLAMMA_PASSWORD - Password for Flamma content crawler
  • FLAMMA_BASE_URL - Base URL for Flamma content crawler
  • HCAPTCHA_SECRET_KEY - Secret key for hCaptcha
  • X_API_KEY_STUDIES_HELSINKI_ARTICLES_PIPELINE - API key for studies.helsinki.fi pipeline
  • X_API_KEY_WWW_HELSINKI_PIPELINE - API key for helsinki.fi main site pipeline

Other environment variables:

  • UNIHELP_SEARCH_API_BASE_URL - Base URL for the Search API
  • USERCENTRICS_SETTINGS_ID optional - ID for Usercentrics Cookie management, overrides the default Settings ID

Main environment

The Drush alias for the current Silta feature branch deployment is drush @current st.

Environment variables for silta_dev context

The following secret variables are defined in the silta/silta.secrets file for the silta_dev context:

The following secret variables are defined in the silta/silta-prod.secrets file for the silta_finland context:

  • AZURE_OPENAI_APIKEY - API key for Azure OpenAI
  • AZURE_OPENAI_EMBEDDINGS_ENDPOINT - Embeddings endpoint for Azure OpenAI
  • AZURE_OPENAI_COMPLETIONS_ENDPOINT - Completions endpoint for Azure OpenAI
  • EFECTE_API_KEY - API key for Efecte webform integration
  • EFECTE_API_KEY_TEST - API key for Efecte endpoint environment webform integration
  • FLAMMA_USERNAME - Username for Flamma content crawler
  • FLAMMA_PASSWORD - Password for Flamma content crawler
  • FLAMMA_BASE_URL - Base URL for Flamma content crawler
  • HCAPTCHA_SECRET_KEY - Secret key for hCaptcha
  • X_API_KEY_STUDIES_HELSINKI_ARTICLES_PIPELINE - API key for studies.helsinki.fi pipeline
  • X_API_KEY_WWW_HELSINKI_PIPELINE - API key for helsinki.fi main site pipeline

Other environment variables:

  • UNIHELP_SEARCH_API_BASE_URL - Base URL for the Search API
  • USERCENTRICS_SETTINGS_ID optional - ID for Usercentrics Cookie management, overrides the default Settings ID

Local development

This project supports two local development environments: DDEV (preferred) and Lando. Choose the one that best fits your workflow.

DDEV environment

DDEV provides a containerized development environment with all necessary services preconfigured.

DDEV setup instructions

  1. Install DDEV
  2. Ensure Docker is running on your system
  3. Copy the contents of the Wunder LastPass note named "UniHelp local ddev env file" into a local .env file at the project root to provide required environment variables.
  4. Start the environment and set up your project:
# Start the DDEV environment
ddev start

# Authenticate SSH for database syncing
ddev auth ssh

# Synchronize local database with a remote environment
# See `scripts/syncdb.sh` for options
ddev syncdb

# Apply configuration changes
ddev drush deploy

# Apply dataset configuration changes
ddev dcdi

# Get a one-time login link for admin access
ddev drush uli

Note: All commands in the DDEV section should be run within the DDEV environment using ddev prefix (e.g., ddev drush uli), or by using ddev ssh to access the container shell first.

DDEV services and access points

The project can be accessed at https://unihelp.ddev.site

For a complete list of all available services, URLs, and ports, use:

ddev describe

DDEV common commands

  • ddev - Display available commands
  • ddev adminer - Launch Adminer database management interface
  • ddev grumphp <commands> - Run code quality checks
  • ddev mailpit - Open Mailpit email testing interface
  • ddev npm <commands> - Execute npm commands
  • ddev phpunit <commands> - Run test suites
  • ddev varnishadm <commands> - Manage Varnish cache
  • ddev xdebug <mode> - Configure Xdebug debugging modes
  • ddev syncdb [environment] - Sync database from remote environment (requires VPN and ddev auth ssh, see scripts/syncdb.sh for details)
DDEV Elasticsearch configuration

DDEV Elasticsearch configuration

This project includes Elasticsearch service for robust full-text search capabilities. It's automatically set up during DDEV initialization.

DDEV Kibana instance

Kibana is also included in ddev for easier debugging and inspection of Elasticsearch index and settings in local environment.

Kibana instance could be accessed at: https://unihelp.ddev.site:5601

Plugins configuration
  • Pre-configured with analysis-icu for Unicode/multilingual text processing
  • Additional plugins can be defined in .ddev/docker-compose.elasticsearch8.yaml
services:
  elasticsearch:
    environment:
      - ELASTICSEARCH_PLUGINS=analysis-icu # Space-separated plugin list
Useful commands
# Check Elasticsearch status
ddev exec -s elasticsearch "curl -s localhost:9200"

# List installed plugins
ddev exec -s elasticsearch "bin/elasticsearch-plugin list"
Web interface

Elasticvue is included for visualization and management at http://unihelp.ddev.site:9005

Lando environment

Lando environment

Lando offers another containerized development option with a focus on simplicity and flexibility.

Lando services and access points

Service Description Access
Web server Primary web service https://unihelp.lndo.site
Adminer Database management via docker-adminer http://adminer.unihelp.lndo.site
Elasticsearch Search functionality via Elasticsearch (uncomment in .lando.yml to enable) http://localhost:9200 or http://elasticsearch.lndo.site
Kibana Elasticsearch visualization (uncomment in .lando.yml to enable) http://localhost:5601 or http://kibana.lndo.site
Mailpit Email testing via Mailpit http://mail.lndo.site
Varnish Caching via Varnish https://varnish.unihelp.lndo.site
Drush Drupal CLI tool lando drush @local st
SSH Container shell access lando ssh (-s <service>)
Node JavaScript tooling Included in web container
Chrome Browser testing via selenium/standalone-chrome Available in web container

Lando setup instructions

  1. Install Lando
  2. Start the environment:
lando start

Lando common commands

  • lando - Display available commands
  • lando drupal <arguments> - Run Drupal core scripts
  • lando grumphp <commands> - Run code quality checks
  • lando npm <commands> - Execute npm commands
  • lando phpunit <commands> - Run test suites
  • lando varnishadm <commands> - Manage Varnish cache
  • lando xdebug <mode> - Configure Xdebug debugging modes
  • lando syncdb [environment] - Sync database from remote environment (requires VPN, see scripts/syncdb.sh for details)

Development tips

Code quality tools

Code quality tools

This project includes several tools to maintain code quality and consistency across the codebase.

Markdown Linting

Markdown files can be checked and automatically fixed using the following npm scripts:

# Check markdown files for linting issues
ddev npm run lint:md

# Automatically fix markdown linting issues where possible
ddev npm run lint:md:fix

Markdown linting rules are configured in .markdownlint.json at the project root.

JavaScript and CSS Linting

The project also includes linting for JavaScript and CSS files:

# Check JavaScript files
ddev npm run lint:js

# Check CSS/SCSS files
ddev npm run lint:css

# Run all linting (JS, CSS, and Markdown)
ddev npm run lint
Cursor AI Code Editor

Cursor AI Code Editor

This project uses Cursor as the recommended AI-powered IDE. Cursor enhances development productivity through AI-assisted coding features while maintaining compatibility with VSCode extensions and settings.

Project-specific AI Rules

  • Rules are stored in @.cursor/rules/ directory
  • Main configuration file: @.cursor/rules/common.mdc
  • Rules provide AI with project-specific context about:
    • File organization and key project files
    • Development environment setup
    • Code standards and technology stack
    • Git workflow and commit message formatting
Drupal core updates

Drupal core updates

Varnish and Purge configuration

Varnish and Purge configuration

This section describes how to set up Varnish caching and Purge functionality in your local development environment.

Note: Drush commands in this section should be run with the appropriate environment prefix (ddev or lando).

Configuration Overview

The project includes ready-to-use Varnish configuration:

  1. Configuration Import (Recommended)

    • For existing projects, simply import the configuration from config/sync:

      drush cim -y
    • This applies all Purge and Varnish settings, including processors and purgers

  2. Manual Configuration (for new sites)

    • If config/sync is not available, follow these steps:

    a. Install required modules:

    drush en purge purge_drush purge_processor_lateruntime purge_queuer_coretags purge_tokens purge_ui varnish_purger varnish_purge_tags -y

    b. Configure Varnish Purger:

    • Set a value for Browser and proxy cache maximum age in admin/config/development/performance
    • Navigate to /admin/config/development/performance/purge
    • Click Add purger and select Varnish Purger:
      • Name: "Varnish Purger"
      • Type: "Tags"
      • Request method: "BAN" (important: use BAN instead of PURGE for compatibility with Silta)
      • Headers: Cache-Tags: [invalidation:expression]
      • Save the configuration

    c. Configure processors:

    • Go to /admin/config/development/performance/purge/processors
    • Ensure these processors are enabled:
      • drush_purge_invalidate (for manual invalidation via Drush)
      • lateruntime (for batching invalidations)
      • purge_ui_block_processor (for admin UI functionality)

    d. Export the configuration:

    drush cex -y

    e. Update settings.php:

    • Find the purger ID in varnish_purger.settings.<PURGER_ID>.yml

    • Update web/sites/default/settings.php with the correct purger ID:

      if (getenv('VARNISH_ADMIN_HOST')) {
        $config['varnish_purger.settings.<PURGER_ID>']['hostname'] = trim(getenv('VARNISH_ADMIN_HOST'));
        $config['varnish_purger.settings.<PURGER_ID>']['port'] = getenv('VARNISH_ADMIN_PORT') ? trim(getenv('VARNISH_ADMIN_PORT')) : '80';
      }

Environment-Specific Setup

DDEV (Recommended)
  1. Varnish Configuration: DDEV comes pre-configured with Varnish in .ddev folder.

  2. Testing Configuration:

    ddev drush cr
    ddev exec curl -X BAN -H "Cache-Tags: config:system.performance" http://varnish

    If working correctly, you should receive a "200 Ban added" response

  3. Viewing Varnish logs:

    ddev exec -s varnish varnishlog -i BAN -i Cache
Lando
  1. Enable Varnish:

    • Varnish configuration is already enabled in .lando.yml & .lando/varnish.vcl.
  2. Testing Configuration:

    lando drush cr
    lando ssh -c "curl -X BAN -H 'Cache-Tags: config:system.performance' http://varnish"

Important Notes

  • BAN vs PURGE Method: Always use the "BAN" method in the Varnish purger configuration instead of "PURGE". The Silta Varnish configuration is set up to handle BAN requests but may reject PURGE requests with "405 Method Not Allowed" errors.

  • Processors: The default Purge setup uses the purge_processor_lateruntime module, which empties the purge queue during page requests. This works well for most sites needing immediate cache clearing. Ensure all required processors are enabled.

  • Cache Tags: The Varnish configuration is set up to handle cache tag invalidation with the Cache-Tags header.

Running tests

Running tests

The PHPUnit test framework is predefined in this project. See phpunit.xml for details. A minified web/modules/custom/phpunit_example module from the examples module is included for learning purposes.

Testing examples

Note: Run these commands with the appropriate environment prefix (ddev phpunit or lando phpunit).

  • Run one test class: phpunit path/to/your/class/file.php
  • List groups: phpunit --list-groups
  • Run all tests in a particular group: phpunit --group Groupname

End-to-End and Accessibility Testing

This project uses Cypress for end-to-end (E2E) testing, including automated accessibility checks powered by axe-core via the cypress-axe plugin.

Running Cypress E2E Tests

You can run the E2E test suite in headless mode:

npm run test:e2e

Or open the interactive Cypress UI:

npm run test:e2e:open

Note: The site must be running locally (e.g., via DDEV or Lando) before running Cypress tests.

Accessibility Testing

Accessibility checks are integrated into the Cypress E2E tests using cypress-axe. These tests automatically scan pages and components for accessibility violations according to WCAG standards.

  • Accessibility violations are logged in the terminal with details and CSS selectors to help locate issues.
  • To view or debug violations, check the Cypress test output or browser console (when running interactively).

Test Locations

  • E2E test files are located in cypress/e2e/
  • Accessibility logging helpers are in cypress/support/axe-log.ts
  • Cypress configuration is in cypress.config.ts

Adding or Updating Tests

  • Add new E2E or accessibility tests in the cypress/e2e/ directory.
  • Use cy.injectAxe() after cy.visit() and before cy.checkA11y() in your tests to enable accessibility scanning.
  • For custom accessibility logging, use the terminalLog helper.

Example Accessibility Test

it('has no detectable accessibility violations on load', () => {
  cy.visit('/');
  cy.injectAxe();
  cy.checkA11y(undefined, undefined, terminalLog);
});

Troubleshooting

  • If you see errors about missing Cypress binaries, run npm run cypress:install.
  • If accessibility violations are reported, check the terminal output for selectors and descriptions to help you fix the issues.

For more details, see the Cypress documentation and cypress-axe documentation.

Secrets handling

Silta CLI is a command-line tool to manage secrets and configurations for Silta projects. Use the following commands:

  • Encrypt a file: silta secrets encrypt --file silta/silta.secrets --secret-key=<secret_key_env>
  • Decrypt a file: silta secrets decrypt --file silta/silta.secrets --secret-key=<secret_key_env>
  • Display help: silta secrets --help

See the corresponding secret_key_env values in the .circleci/config.yml file for the silta_dev and silta_finland contexts. Refer to the Getting Started section for details.

Contributing

This project is maintained by Wunder. Contributions from the community are welcome.

Commit message validation and ticketing system integration

Commit message validation and ticketing system integration

We follow the Conventional Commits specification for commit messages, with an additional requirement for ticket IDs. Each commit message must include a valid ticket ID (except for merge commits) and follow the conventional commits format:

[PROJECTKEY-123]: (feat) Add new feature description

- Detailed change description
- Another relevant detail

Refs: file1.ext, file2.ext

Types include (used within parentheses):

  • feat: New feature (correlates with MINOR in semantic versioning)
  • fix: Bug fix (correlates with PATCH in semantic versioning)
  • docs: Documentation changes
  • style: Changes not affecting code meaning
  • refactor: Code changes neither fixing bugs nor adding features
  • perf: Performance improvements
  • test: Adding or correcting tests
  • build: Build system or dependency changes
  • ci: CI configuration changes
  • chore: Other changes not modifying src or test files

Breaking changes must be indicated by appending a ! after the type/scope or including "BREAKING CHANGE:" in the footer.

Ticket ID formats:

  • JIRA: [PROJECTKEY-123]: (type) Description
  • GitHub: GH-123: (type) Description

We leverage autolinked references to automatically convert ticket IDs into clickable links for easy navigation. This enhances traceability and accessibility across platforms.

Validation rules are implemented via the GrumPHP git_commit_message component. See grumphp.yml for configuration details.

Git workflow

Refer to the WunderFlow repository for Git workflow details.

Deployments

Deployments are managed with CircleCI. Configurations are in .circleci/config.yml.

  • Feature branches require manual approval for deployment by default.
  • Other branches deploy automatically but can be configured for manual approval.

Manual approvals are managed through the approve-deployment job in the CircleCI UI by clicking the "approve-deployment" job label when marked as "Needs Approval."

Data Pipelines

See data-pipelines.md for details on data pipeline setup and usage.

Search Service and Language Detection

The project includes a standalone Node.js search service (search-service/) that handles search queries and AI-powered answer generation. The service features automatic language detection to improve user experience across multiple languages.

Language Detection Feature

The search service automatically detects the language of user queries using the franc library. When a user searches in a language that differs from the current page language, the system:

  1. Backend Detection (search-service/utils/languageDetection.js):

    • Detects query language using franc (trigram-based statistical analysis)
    • Supports Finnish (fi), Swedish (sv), and English (en)
    • Requires minimum 10 characters for reliable detection
    • Returns null if detection fails or language is unsupported
  2. Backend Response (search-service/server.js):

    • Compares detected language with page language parameter
    • Returns language mismatch response if languages differ
    • Response includes languageMismatch: true and detectedLanguage properties
  3. Frontend Handling (web/themes/custom/unihelp/src/js/search/Search.jsx):

    • Displays notification instead of AI summary when mismatch detected
    • Provides link to search in the correct language
    • Preserves query and role parameters in the redirect URL

Related Files:

  • search-service/utils/languageDetection.js - Language detection utility
  • search-service/server.js - API endpoint with detection logic
  • web/themes/custom/unihelp/src/js/search/Search.jsx - Frontend React component
  • web/themes/custom/unihelp/src/js/i18n/index.js - Translatable strings

Library: franc - Language detection library with support for 187+ languages

Search Analytics

The search service automatically logs search statistics to track how users interact with the search system. This data helps monitor search usage patterns, identify popular queries, and improve search quality.

Index: unihelp_search_statistics

The analytics data is stored in a dedicated Elasticsearch index (unihelp_search_statistics) that is automatically created on search-service startup if it doesn't exist.

Stored Fields

Each search event records the following information:

  • @timestamp: Date and time of the search (ISO 8601 format)
  • query: The search query string (text with keyword subfield query.raw for exact matching)
  • langcode: Language code of the search ("fi", "sv", or "en")
  • role: User's role/profile used for the search (empty string if not specified)
  • offset: Pagination offset (0 for initial searches, >0 for paging queries)
  • total_results: Total number of filtered results returned
Privacy & Security

The analytics system is designed with privacy in mind:

  • No PII stored: No IP addresses, User-Agent strings, emails, names, or authentication tokens are logged
  • Dynamic fields disabled: The index mapping uses dynamic: false to prevent accidental PII field creation
  • Fire-and-forget: Analytics failures never impact search functionality - if analytics logging fails, the search still works normally
Configuration

Search analytics can be controlled via environment variables:

  • SEARCH_ANALYTICS_ENABLED: Set to "false" to disable analytics logging (default: true)
  • SEARCH_ANALYTICS_INDEX: Customize the index name (default: "unihelp_search_statistics")

The index uses cluster defaults for shards and replicas configuration.

Index Creation

The analytics index is automatically created on search-service startup with the correct mappings. If index creation fails, the service will log a warning but continue to start normally (analytics won't work until the index is created manually).

Analytics Export Endpoint

The search service provides an authenticated API endpoint to export analytics data as CSV format for easy import into spreadsheets.

Endpoint: GET /api/analytics

Authentication: Requires API key via one of the following methods:

  • HTTP header: X-API-Key: <your-api-key>
  • Query parameter: ?api_key=<your-api-key>

Query Parameters:

  • from: Start date in ISO 8601 format (YYYY-MM-DD), optional. Defaults to 7 days ago.
  • to: End date in ISO 8601 format (YYYY-MM-DD), optional. Defaults to today.
  • api_key: API key for authentication (alternative to header).

Response Format: CSV file with the following columns:

  • timestamp: Date and time of the search
  • query: The search query string
  • langcode: Language code (fi, sv, or en)
  • role: User's role/profile (empty if not specified)
  • offset: Pagination offset
  • total_results: Total number of results

Default Behavior: If from or to parameters are not provided, the endpoint returns data from the last 7 days (from 7 days ago to today).

Results: All matching records are returned (no pagination limits). Results are sorted by timestamp in descending order (newest first).

Example Requests:

# Export last 7 days (default) using header authentication
curl -H "X-API-Key: your-api-key-here" \
  https://your-search-service.com/api/analytics \
  -o analytics.csv

# Export specific date range using query parameter authentication
curl "https://your-search-service.com/api/analytics?from=2026-01-01&to=2026-01-31&api_key=your-api-key-here" \
  -o analytics-january.csv

# Export last 30 days
curl -H "X-API-Key: your-api-key-here" \
  "https://your-search-service.com/api/analytics?from=2026-01-01&to=2026-01-31" \
  -o analytics-january.csv

Configuration:

  • ANALYTICS_API_KEY: Environment variable that must be set to enable the analytics export endpoint. This API key is required for all requests to /api/analytics.

Audience-aware boosting

The Elasticsearch indices expose an audience keyword field generated during indexing (see buildAudiencePainlessScript() in web/modules/custom/unihelp_data_pipelines/src/Drush/Commands/UnihelpDataPipelinesCommands.php). Documents may be tagged with any of the following audiences: employee, researcher, teacher, applicant, student, open university, or supervisor.

The search service combines explicit role parameters and intent detector hits to apply soft boosts:

  • search-service/utils/role.js#getAudienceEmphasis() maps the incoming role to matching audience values, merges intent detections, and emits a single boost config for the audience field. Legacy de-emphasis rules remain in the file but are guarded by a AUDIENCE_DE_EMPHASIS_ENABLED flag (currently false).
  • search-service/utils/intentDetector.js#detectAudienceIntents() generalizes the previous Open University detection and currently recognizes both open university and supervisor phrases across Finnish, Swedish, and English inputs.
  • search-service/utils/queryBuilder.js#addAudienceEmphasisClauses() injects the boost into lexical should clauses, while buildRescoreFunctions() mirrors the weighting in the ANN rescore phase used by both search-service/services/search.js and search-service/services/answer.js.

This setup keeps the configuration simple (audience values only) and makes it straightforward to introduce additional audiences later by extending the detector registry.

The same helper now re-enables a mild de-emphasis for applicant/student roles: whenever their selected audiences include only study-oriented profiles, any overlapping employee-style audiences (employee, supervisor, researcher, teacher) receive a small multiplier (0.85) via the existing rescore pipeline. This keeps search and answer behaviour aligned without reintroducing domain-based suppression.

About

The sources for HelsinkiUni Help

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages