mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-15 13:45:25 +08:00
28 lines
650 B
Ruby
28 lines
650 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
class UserAssignmentSerializer < ActiveModel::Serializer
|
||
|
include Canaid::Helpers::PermissionsHelper
|
||
|
include Rails.application.routes.url_helpers
|
||
|
|
||
|
attributes :id, :assigned, :assignable_type, :user, :user_role, :last_owner
|
||
|
|
||
|
def user
|
||
|
{
|
||
|
id: object.user.id,
|
||
|
name: object.user.name,
|
||
|
avatar_url: avatar_path(object, :icon_small)
|
||
|
}
|
||
|
end
|
||
|
|
||
|
def user_role
|
||
|
{
|
||
|
id: object.user_role.id,
|
||
|
name: object.user_role.name
|
||
|
}
|
||
|
end
|
||
|
|
||
|
def last_owner
|
||
|
object.last_with_permission?("#{object.assignable.class.name}Permissions".constantize::USERS_MANAGE, assigned: :manually)
|
||
|
end
|
||
|
end
|