Add migration to enable sharing for legacy service owners

This commit is contained in:
Andreas Nedbal 2023-02-05 18:00:48 +01:00 committed by Andreas Nedbal
parent 482ffe7d0b
commit a2e45c85bf
3 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,48 @@
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static targets = ['twitter', 'tumblr', 'custom'];
declare readonly twitterTarget: HTMLAnchorElement;
declare readonly tumblrTarget: HTMLAnchorElement;
declare readonly customTarget: HTMLAnchorElement;
declare readonly hasCustomTarget: boolean;
static values = {
config: Object,
autoClose: Boolean
};
declare readonly configValue: Record<string, string>;
declare readonly autoCloseValue: boolean;
connect() {
if (this.autoCloseValue) {
this.twitterTarget.addEventListener('click', () => this.close());
this.tumblrTarget.addEventListener('click', () => this.close());
if (this.hasCustomTarget) {
this.customTarget.addEventListener('click', () => this.close());
}
}
}
configValueChanged(value): void {
if (Object.keys(value).length === 0) {
return;
}
this.element.classList.remove('d-none');
this.twitterTarget.href = this.configValue['twitter'];
this.tumblrTarget.href = this.configValue['tumblr'];
if (this.hasCustomTarget) {
this.customTarget.href = `${this.customTarget.href}${this.configValue['custom']}`;
}
}
close(): void {
(this.element.closest(".inbox-entry")).remove();
}
}

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
module User::SharingMethods
def display_sharing_custom_url
URI(sharing_custom_url).host
end
end

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class EnableSharingForServiceOwners < ActiveRecord::Migration[6.1]
def up
execute <<~SQUIRREL
UPDATE users
SET sharing_enabled = true
WHERE id IN (SELECT user_id FROM services);
SQUIRREL
end
def down; end
end