Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/discourse/manifests/admin.pp

Issue 9351210: Define Discourse admins and site settings in Puppet, separate private data from other settings (Closed)
Patch Set: Created Feb. 19, 2013, 3:08 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: modules/discourse/manifests/admin.pp
===================================================================
new file mode 100644
--- /dev/null
+++ b/modules/discourse/manifests/admin.pp
@@ -0,0 +1,28 @@
+define discourse::admin(
+ $email = $title,
+ $ensure = 'present'
+) {
+ # Attempt some escaping
+ $escaped_email = regsubst($email, '[\'\\]', '\\\1', 'G')
+
+ case $ensure {
+ default: {
+ err("unknown ensure value ${ensure}")
+ }
+ present: {
+ # Only confirmed accounts should be made admins
+ postgresql_psql {"UPDATE users SET admin = true WHERE email = '$escaped_email' AND EXISTS (SELECT * FROM email_tokens WHERE email_tokens.user_id = users.id AND email_tokens.email = users.email AND email_tokens.confirmed)":
+ db => 'discourse',
+ psql_user => 'discourse',
+ unless => 'SELECT false'
+ }
+ }
+ absent: {
+ postgresql_psql {"UPDATE users SET admin = false WHERE email = '$escaped_email'":
+ db => 'discourse',
+ psql_user => 'discourse',
+ unless => 'SELECT false'
+ }
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld