Roles: Role table & relation to user model

master
E. Almqvist 3 years ago
parent 521dfe4b32
commit 1cc4f5fdbd
  1. 4
      src/db_init.rb
  2. 29
      src/db_models.rb
  3. 4
      src/sql/tables/User_Role_relation.sql
  4. 1
      src/views/stylesheets/style.sass
  5. 23
      src/views/user/profile.slim

@ -1,7 +1,9 @@
require_relative "db_models.rb"
LOAD_MODELS = [
User
User,
Role,
User_Role_relation
]
def db_init

@ -18,7 +18,19 @@ class User < EntityModel
end
def role
"INSERT ROLE HERE"
roles = self.roles
p "####"
p roles
if roles.length > 0 then
role = roles.max_by { |role| role.flags }
return role.name
else
return ""
end
end
def roles
User_Role_relation.get_user_roles @id
end
def rep_score
@ -115,13 +127,12 @@ end
class Role < EntityModel
attr_reader :name, :color, :perm_level
attr_reader :name, :color, :flags
def initialize(role_info)
super role_info
@name = role_info["name"]
@color = role_info["color"]
@perm_level = role_info["perm_level"]
# perm_level follow the UNIX perms system
@flags = role_info["flags"]
end
def self.find_by_id(id)
@ -134,3 +145,13 @@ class Role < EntityModel
data && Role.new(data)
end
end
class User_Role_relation < EntityModel
def self.get_user_roles(user_id)
roleids = self.get "role_id", "user_id = ?", user_id
roles = roleids.map do |ent|
Role.find_by_id(ent["role_id"].to_i)
end
end
end

@ -0,0 +1,4 @@
CREATE TABLE IF NOT EXISTS "User_Role_relation" (
"user_id" INTEGER NOT NULL,
"role_id" INTEGER NOT NULL
);

@ -249,6 +249,7 @@ ul.button-container
#userinfo
margin-bottom: 1.75rem
text-align: center
min-width: 250px
h2
margin: 1rem 0 0 0
padding: 0

@ -19,21 +19,14 @@
a.button href="/settings"
li Edit profile
#roles.card
h2 Roles
.card-container
ul.button-container
// insert roles here
li
label role
li
label role2
li
label role2
li
label role2
li
label role2
- if user.roles.length >= 1
#roles.card
h2 Roles
.card-container
ul.button-container
- user.roles.each do |role|
li
label = role.name
#reputation.card
h2 Reputation

Loading…
Cancel
Save