diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-05-23 05:20:14 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-05-23 05:20:14 -0400 |
commit | 8f3fd44986e2433b222e976f11d049d4a407dcbd (patch) | |
tree | 4c043e98681acf57e235c2f0c2e2798bf7038187 /src/guff.cr | |
parent | 8c0f5e1e76e811bbebf173d29f936b61236094e6 (diff) | |
download | guff-8f3fd44986e2433b222e976f11d049d4a407dcbd.tar.bz2 guff-8f3fd44986e2433b222e976f11d049d4a407dcbd.zip |
add role options
Diffstat (limited to 'src/guff.cr')
-rw-r--r-- | src/guff.cr | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/src/guff.cr b/src/guff.cr index 61330a1..b0f57d4 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -970,6 +970,29 @@ module Guff r ? r.to_i64 : nil end end + + class RoleModel < Model + SQL = { + get_roles: " + SELECT role, + name + + FROM roles + + ORDER BY sort + ", + } + + def get_roles : Array(Hash(String, String)) + r = [] of Hash(String, String) + + @context.dbs.ro.all(SQL[:get_roles]) do |row| + r << { "role": row["role"] as String, "name": row["name"] as String } + end + + r + end + end end class ModelSet @@ -985,6 +1008,7 @@ module Guff project: Models::ProjectModel, blog: Models::BlogModel, site: Models::SiteModel, + role: Models::RoleModel, }) end @@ -1356,6 +1380,16 @@ module Guff super(TABS) end + OPTION = "<option value='%s'>%s</option>" + + def role_options + @role_options ||= String.build do |io| + @context.models.role.get_roles.each do |row| + io << OPTION % %w{role name}.map { |key| h(row[key]) } + end + end + end + ECR.def_to_s("src/views/admin-page.ecr") end @@ -1993,14 +2027,16 @@ module Guff ), -- user-visible role name - role_name TEXT UNIQUE NOT NULL - CHECK (LENGTH(role_name) > 0) + name TEXT UNIQUE NOT NULL + CHECK (LENGTH(name) > 0), + + sort INTEGER UNIQUE NOT NULL ) }, %{ - INSERT INTO roles(role_id, role, role_name) VALUES - (1, 'viewer', 'Viewer'), - (2, 'editor', 'Editor'), - (3, 'admin', 'Admin') + INSERT INTO roles(role_id, role, name, sort) VALUES + (1, 'viewer', 'Viewer', 1), + (2, 'editor', 'Editor', 2), + (3, 'admin', 'Admin', 3) }, %{ CREATE TABLE users ( user_id INTEGER PRIMARY KEY, |