diff options
author | Mario de la Ossa <mariodelaossa@gmail.com> | 2017-12-19 07:55:51 +0300 |
---|---|---|
committer | Mario de la Ossa <mariodelaossa@gmail.com> | 2017-12-19 08:04:35 +0300 |
commit | b03789395c59ce94c8bdb4e0f4806c8cd7705f46 (patch) | |
tree | 037483d09991b6c70fdc84bafabe5576740976b4 /app/models | |
parent | 130b03c264b7a11a035a8dc2acd3c66279455704 (diff) |
Do not generate links for private NPM modules in blob view
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blob_viewer/dependency_manager.rb | 13 | ||||
-rw-r--r-- | app/models/blob_viewer/package_json.rb | 12 |
2 files changed, 22 insertions, 3 deletions
diff --git a/app/models/blob_viewer/dependency_manager.rb b/app/models/blob_viewer/dependency_manager.rb index a8d9be945dc..cc4950240af 100644 --- a/app/models/blob_viewer/dependency_manager.rb +++ b/app/models/blob_viewer/dependency_manager.rb @@ -27,10 +27,17 @@ module BlobViewer private - def package_name_from_json(key) - prepare! + def json_data + @json_data ||= begin + prepare! + JSON.parse(blob.data) + rescue + {} + end + end - JSON.parse(blob.data)[key] rescue nil + def package_name_from_json(key) + json_data[key] end def package_name_from_method_call(name) diff --git a/app/models/blob_viewer/package_json.rb b/app/models/blob_viewer/package_json.rb index 09221efb56c..6ce61e30d3d 100644 --- a/app/models/blob_viewer/package_json.rb +++ b/app/models/blob_viewer/package_json.rb @@ -16,8 +16,20 @@ module BlobViewer @package_name ||= package_name_from_json('name') end + def package_type + private? ? 'private package' : super + end + def package_url + return nil if private? + "https://www.npmjs.com/package/#{package_name}" end + + private + + def private? + !!json_data['private'] + end end end |