You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cartodb/app/models/permission/presenter.rb

55 lines
1.5 KiB

require_relative 'permission_user_presenter'
require_relative 'permission_organization_presenter'
require_relative 'permission_group_presenter'
module CartoDB
class PermissionPresenter
def initialize(permission)
@permission = permission
@user_presenter = CartoDB::PermissionUserPresenter.new
@org_presenter = CartoDB::PermissionOrganizationPresenter.new
end
def to_poro
{
id: @permission.id,
owner: @user_presenter.decorate_user(@permission.owner),
entity: {
id: @permission.entity_id,
type: @permission.entity_type
},
7 years ago
acl: @permission.acl.map { |entry|
Solution to wrong ACL (deleted user) Here is the scenario we're trying to fix: - some user A creates a table - that user A grants permission to some other user B to that table - the user B is deleted Usually this is dealt with as part of the user deletion, but we found a situation in which ACL (permissions table) is wrong because they reference a deleted user. We don't know exactly how we arrived to that situation. It is most likely a race condition deleting a user or migrating a DB, but we don't have enough information to reconstruct the whole story. The trouble with that is that the web client is generating requests to change permissions based on the wrong (referencing the deleted user) ACL. Once you have the data inconsistent in the DB you have 3 possible approaches to get it fixed: - fix it directly in the database - filter the input of PUT /api/v1/perm, ignoring deleted entities - filter the output (viz endopoint, permissions presenter) Fixing directly in the database is OK as a one-time thing, but that may cause some maintenance burden. Returning an error if the input is wrong is OK. Filtering for wrong inputs could fix it but I don't think it's the right approach, as some other errors could be masked otherwise. I think filtering the output from DB is the rigth approach. This way the permissions can be set correctly by the user. They will get "automatically fixed" the next time the user tries to modify the permissions. And this is why the fix for it is in the presenter.
7 years ago
entity = entity_decoration(entry)
if entity.blank?
nil
else
{
type: entry[:type],
entity: entity,
access: entry[:access]
}
end
7 years ago
}.reject(&:nil?),
created_at: @permission.created_at,
updated_at: @permission.updated_at
}
end
private
def entity_decoration(entry)
case entry[:type]
when Carto::Permission::TYPE_USER
@user_presenter.decorate(entry[:id])
when Carto::Permission::TYPE_ORGANIZATION
@org_presenter.decorate(entry[:id])
when Carto::Permission::TYPE_GROUP
CartoDB::PermissionGroupPresenter.new.decorate(entry[:id])
else
raise "Unknown entity type for entry #{entry}"
end
end
end
end