aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/guff.cr48
-rw-r--r--src/views/admin-page.ecr4
2 files changed, 44 insertions, 8 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,
diff --git a/src/views/admin-page.ecr b/src/views/admin-page.ecr
index 678b8c5..3394096 100644
--- a/src/views/admin-page.ecr
+++ b/src/views/admin-page.ecr
@@ -268,7 +268,7 @@
class='form-control'
title='Choose role of user.'
><%=
- # get_roles
+ role_options
%></select>
</div><!-- form-group -->
</div><!-- modal-body -->
@@ -362,7 +362,7 @@
class='form-control'
title='Choose role of user.'
><%=
- # get_roles
+ role_options
%></select>
</div><!-- form-group -->
</div><!-- modal-body -->