diff --git a/Dockerfile b/Dockerfile index 853c0c2f..6e122582 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.17 AS alpine +FROM alpine:3 AS alpine ARG RAILS_ROOT=/usr/src/app ENV RAILS_ROOT=${RAILS_ROOT} diff --git a/Gemfile b/Gemfile index 0be1a76f..eb25097a 100644 --- a/Gemfile +++ b/Gemfile @@ -47,7 +47,7 @@ gem 'repost', '~> 0.3.8' gem 'lodash-rails' gem 'react-rails', '>= 3.0.0' -gem 'rails_lti2_provider', git: 'https://github.com/blindsidenetworks/rails_lti2_provider.git', tag: '0.1.4' +gem 'rails_lti2_provider', git: 'https://github.com/blindsidenetworks/rails_lti2_provider.git', tag: '0.1.5' gem 'ims-lti', git: 'https://github.com/blindsidenetworks/ims-lti.git', tag: 'v2.3.2.1' diff --git a/Gemfile.lock b/Gemfile.lock index dba82756..45ca429a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,10 +14,10 @@ GIT GIT remote: https://github.com/blindsidenetworks/rails_lti2_provider.git - revision: bdc2f0c6db9d88609356ff359a2e76d8f4628f61 - tag: 0.1.4 + revision: 5ca1cc0427c04187bbeb81848f0e7bfee72f9534 + tag: 0.1.5 specs: - rails_lti2_provider (0.1.4) + rails_lti2_provider (0.1.5) ims-lti (~> 2.3.2.1) GIT diff --git a/app/controllers/api/v1/tenants_controller.rb b/app/controllers/api/v1/tenants_controller.rb new file mode 100644 index 00000000..7f11ead5 --- /dev/null +++ b/app/controllers/api/v1/tenants_controller.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. + +# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below). + +# This program is free software; you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free Software +# Foundation; either version 3.0 of the License, or (at your option) any later +# version. + +# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public License along +# with BigBlueButton; if not, see . + +class Api::V1::TenantsController < Api::V1::BaseController + before_action :doorkeeper_authorize! + + before_action :set_tenant, only: [:show] + + # GET /api/v1/tenant/:uid + def show + render(json: @tenant, status: :ok) + end + + private + + def set_tenant + uid = params[:uid] + uid ||= '' + @tenant = RailsLti2Provider::Tenant.find_by(uid: uid) + rescue ApplicationRecord::RecordNotFound => e + render(json: { error: e.message }, status: :not_found) + end +end diff --git a/config/routes.rb b/config/routes.rb index b4d28ae5..8b756c90 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,7 @@ get 'users/:id', to: 'users#show', as: :users get 'user', to: 'users#show', as: :user get 'sessions/:token', to: 'sessions#validate_launch', as: :sessions + get 'tenants/(:uid)', to: 'tenants#show', param: :uid end end diff --git a/db/schema.rb b/db/schema.rb index 3cd67d59..f1e8538b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_02_24_170133) do +ActiveRecord::Schema.define(version: 2023_03_09_132533) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -82,6 +82,7 @@ t.string "uid" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.jsonb "settings", default: {}, null: false t.index ["uid"], name: "index_tenant_uid", unique: true end diff --git a/lib/tasks/db_tenant_settings.rake b/lib/tasks/db_tenant_settings.rake new file mode 100644 index 00000000..4148e335 --- /dev/null +++ b/lib/tasks/db_tenant_settings.rake @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'bbb_lti_broker/helpers' + +namespace :db do + namespace :tenants do + namespace :settings do + desc 'Show all settings for a tenant. If no id is specified, settings for all tenants will be shown' + task :showall, [:uid] => :environment do |_t, args| + tenant_id = args[:uid] || '' + + if tenant_id.present? + tenant = RailsLti2Provider::Tenant.find_by(uid: tenant_id) + if tenant.nil? + puts("Tenant '#{tenant_id}' does not exist.") + exit(1) + end + + puts("Settings for tenant #{tenant_id}: \n #{tenant.settings}") + else + tenants = RailsLti2Provider::Tenant.all + tenants_list = tenants.map do |t| + { + tenant: t.uid, + settings: t.settings, + } + end + puts(tenants_list) + end + end + + desc 'Add a new tenant setting' + task :upsert, [:uid, :key, :value] => :environment do |_t, args| + tenant_id = args[:uid] || '' + key = args[:key] + value = args[:value] + + unless key.present? && value.present? + puts('Error: key and value are required to create a tenant setting') + exit(1) + end + + tenant = RailsLti2Provider::Tenant.find_by(uid: tenant_id) + if tenant.nil? + puts("Tenant '#{tenant_id}' does not exist.") + exit(1) + end + + # Add the setting + tenant.settings[key] = value + tenant.save! + + puts("Added setting #{key}=#{value} to tenant #{tenant_id}") + rescue StandardError => e + puts(e.backtrace) + exit(1) + end + + desc 'Delete a setting' + task :delete, [:uid, :key] => :environment do |_t, args| + tenant_id = args[:uid] || '' + key = args[:key] + + if key.blank? + puts('Error: The setting key is required to delete a tenant setting') + exit(1) + end + + tenant = RailsLti2Provider::Tenant.find_by(uid: tenant_id) + if tenant.nil? + puts("Tenant '#{tenant_id}' does not exist.") + exit(1) + end + + puts("Key '#{key}' not found for tenant #{tenant}") unless tenant.settings[key] + + tenant.settings.delete(key) + tenant.save! + + puts("Setting #{key} for tenant '#{tenant_id}' has been deleted") + rescue StandardError => e + puts(e.backtrace) + exit(1) + end + end + end +end