Created
December 7, 2018 13:33
-
-
Save mmuth/8b9fed9c6610e6794b29b5f3a1cb619c to your computer and use it in GitHub Desktop.
Postgres Trigger to apply a default theme to new Mattermost users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
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
nice!! this was very helpful. thank you, @mmuth!
and if you already have some existing users, here is a solution to set a theme for them:
note that you may have a few users in there you might not want to set a theme for.
in that case, first inspect the full user list:
locate some usernames you don't like.
and then instead of the above, use this modified code:
in this example, the users
admin
,foo
, andsurveybot
are excluded.