Skip to content

Instantly share code, notes, and snippets.

@mmuth
Created December 7, 2018 13:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmuth/8b9fed9c6610e6794b29b5f3a1cb619c to your computer and use it in GitHub Desktop.
Save mmuth/8b9fed9c6610e6794b29b5f3a1cb619c to your computer and use it in GitHub Desktop.
Postgres Trigger to apply a default theme to new Mattermost users
CREATE OR REPLACE FUNCTION apply_default_theme_for_new_user() RETURNS TRIGGER AS $defaultTheme$
BEGIN
IF (SELECT COUNT(*) FROM preferences WHERE userid=NEW.id AND category='theme') = 0 THEN
INSERT INTO preferences (userid, category, name, value)
VALUES (NEW.id, 'theme', '', '{"awayIndicator":"#b8b884","buttonBg":"#004818","buttonColor":"#ffffff","centerChannelBg":"#ffffff","centerChannelColor":"#444444","codeTheme":"monokai","linkColor":"#004818","mentionBg":"#7E9949","mentionColor":"#ffffff","mentionHighlightBg":"#cceecc","mentionHighlightLink":"#444444","newMessageSeparator":"#90ad58","onlineIndicator":"#99cb3f","sidebarBg":"#262626","sidebarHeaderBg":"#363636","sidebarHeaderTextColor":"#ffffff","sidebarText":"#ffffff","sidebarTextActiveBorder":"#7e9949","sidebarTextActiveColor":"#ffffff","sidebarTextHoverBg":"#525252","sidebarUnreadText":"#0aff44","type":"custom"}');
END IF;
RETURN NEW;
END;
$defaultTheme$ LANGUAGE 'plpgsql';
DROP TRIGGER IF EXISTS apply_default_theme_for_new_user ON users;
CREATE TRIGGER apply_default_theme_for_new_user AFTER INSERT ON users
FOR EACH ROW EXECUTE PROCEDURE apply_default_theme_for_new_user();
@melroy89
Copy link

I would like to see this feature coming back to the CE as well..!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment