Class: Aven::WorkspaceUser

Inherits:
ApplicationRecord show all
Defined in:
app/models/aven/workspace_user.rb

Instance Method Summary collapse

Instance Method Details

#add_role(role_label) ⇒ Object



42
43
44
45
# File 'app/models/aven/workspace_user.rb', line 42

def add_role(role_label)
  role = workspace.workspace_roles.find_or_create_by!(label: role_label)
  workspace_user_roles.find_or_create_by!(workspace_role: role)
end

#has_role?(role_label) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/aven/workspace_user.rb', line 38

def has_role?(role_label)
  workspace_roles.exists?(label: role_label)
end

#remove_role(role_label) ⇒ Object



47
48
49
50
51
52
# File 'app/models/aven/workspace_user.rb', line 47

def remove_role(role_label)
  role = workspace.workspace_roles.find_by(label: role_label)
  return unless role

  workspace_user_roles.where(workspace_role: role).destroy_all
end

#rolesObject



34
35
36
# File 'app/models/aven/workspace_user.rb', line 34

def roles
  workspace_roles.pluck(:label)
end