2019-07-04 16:23:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Gestiona la relación entre sitios y usuaries
|
|
|
|
class SiteUsuariePolicy
|
|
|
|
attr_reader :usuarie, :site_usuarie
|
|
|
|
|
|
|
|
def initialize(usuarie, site_usuarie)
|
|
|
|
@usuarie = usuarie
|
|
|
|
@site_usuarie = site_usuarie
|
|
|
|
end
|
|
|
|
|
|
|
|
def index?
|
|
|
|
usuarie?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Les usuaries pueden remover a otres usuaries e invitades del sitio
|
|
|
|
def destroy?
|
|
|
|
usuarie?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Les usuaries pueden convertir a otres usuaries en invitades
|
|
|
|
def demote?
|
|
|
|
usuarie?
|
|
|
|
end
|
|
|
|
|
|
|
|
def promote?
|
|
|
|
usuarie?
|
|
|
|
end
|
|
|
|
|
2019-07-05 23:55:59 +00:00
|
|
|
def invite?
|
|
|
|
usuarie?
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_invitations?
|
|
|
|
usuarie?
|
|
|
|
end
|
|
|
|
|
2019-07-08 17:55:19 +00:00
|
|
|
def accept_invitation?
|
2024-03-25 15:42:26 +00:00
|
|
|
!!site_usuarie.usuarie.rol_for_site(site_usuarie.site)&.temporal
|
2019-07-08 17:55:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def reject_invitation?
|
|
|
|
accept_invitation?
|
|
|
|
end
|
|
|
|
|
2019-07-04 16:23:43 +00:00
|
|
|
private
|
|
|
|
|
2019-09-25 22:40:08 +00:00
|
|
|
def invitades?
|
|
|
|
site_usuarie.site.invitades?
|
|
|
|
end
|
|
|
|
|
2019-07-04 16:23:43 +00:00
|
|
|
def usuarie?
|
2019-09-25 22:40:08 +00:00
|
|
|
invitades? && site_usuarie.site.usuarie?(usuarie)
|
2019-07-04 16:23:43 +00:00
|
|
|
end
|
2019-07-08 17:55:19 +00:00
|
|
|
|
|
|
|
def invitade?
|
|
|
|
site_usuarie.site.invitade? usuarie
|
|
|
|
end
|
2019-07-04 16:23:43 +00:00
|
|
|
end
|