2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SnippetPresenter < Gitlab::View::Presenter::Delegated
|
|
|
|
presents :snippet
|
|
|
|
|
|
|
|
def raw_url
|
2020-10-24 23:57:45 +05:30
|
|
|
url_builder.build(snippet, raw: true)
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def ssh_url_to_repo
|
2020-05-24 23:13:21 +05:30
|
|
|
snippet.ssh_url_to_repo if snippet.repository_exists?
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def http_url_to_repo
|
2020-05-24 23:13:21 +05:30
|
|
|
snippet.http_url_to_repo if snippet.repository_exists?
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
def can_read_snippet?
|
|
|
|
can_access_resource?("read")
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_update_snippet?
|
|
|
|
can_access_resource?("update")
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_admin_snippet?
|
|
|
|
can_access_resource?("admin")
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_report_as_spam?
|
|
|
|
snippet.submittable_as_spam_by?(current_user)
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def blob
|
2021-01-03 14:25:43 +05:30
|
|
|
return snippet.blob if snippet.empty_repo?
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
blobs.first
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def can_access_resource?(ability_prefix)
|
|
|
|
can?(current_user, ability_name(ability_prefix), snippet)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ability_name(ability_prefix)
|
|
|
|
"#{ability_prefix}_#{snippet.to_ability_name}".to_sym
|
|
|
|
end
|
|
|
|
end
|