-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#49124] Implement open links for storages, file links
- https://community.openproject.org/wp/49124 - added open_link method to project storages and storages - extracted open_link for file links to storage queries - polished code that shows elements with open link - storage menu items - file link list - added fallback icon matching for storages without an own icon
- Loading branch information
Showing
20 changed files
with
327 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...pp/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
module Storages | ||
module Peripherals | ||
module StorageInteraction | ||
module OneDrive | ||
module Internal | ||
class DriveItemQuery | ||
UTIL = ::Storages::Peripherals::StorageInteraction::OneDrive::Util | ||
|
||
def self.call(storage:, user:, drive_item_id:, fields: []) | ||
new(storage).call(user:, drive_item_id:, fields:) | ||
end | ||
|
||
def initialize(storage) | ||
@storage = storage | ||
@uri = storage.uri | ||
end | ||
|
||
def call(user:, drive_item_id:, fields: []) | ||
select_url_query = if fields.empty? | ||
'' | ||
else | ||
"?$select=#{fields.join(',')}" | ||
end | ||
|
||
UTIL.using_user_token(@storage, user) do |token| | ||
make_file_request(drive_item_id, token, select_url_query) | ||
end | ||
end | ||
|
||
private | ||
|
||
def make_file_request(drive_item_id, token, select_url_query) | ||
response_data = Net::HTTP.start(@uri.host, @uri.port, use_ssl: true) do |http| | ||
http.get(uri_path_for(drive_item_id) + select_url_query, { 'Authorization' => "Bearer #{token.access_token}" }) | ||
end | ||
|
||
handle_responses(response_data) | ||
end | ||
|
||
def handle_responses(response) | ||
json = MultiJson.load(response.body, symbolize_keys: true) | ||
|
||
case response | ||
when Net::HTTPSuccess | ||
ServiceResult.success(result: json) | ||
when Net::HTTPNotFound | ||
ServiceResult.failure(result: :not_found, | ||
errors: ::Storages::StorageError.new(code: :not_found, data: json)) | ||
when Net::HTTPForbidden | ||
ServiceResult.failure(result: :forbidden, | ||
errors: ::Storages::StorageError.new(code: :forbidden, data: json)) | ||
when Net::HTTPUnauthorized | ||
ServiceResult.failure(result: :unauthorized, | ||
errors: ::Storages::StorageError.new(code: :unauthorized, data: json)) | ||
else | ||
ServiceResult.failure(result: :error, | ||
errors: ::Storages::StorageError.new(code: :error, data: json)) | ||
end | ||
end | ||
|
||
def uri_path_for(file_id) | ||
"/v1.0/drives/#{@storage.drive_id}/items/#{file_id}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
95 changes: 95 additions & 0 deletions
95
...es/app/common/storages/peripherals/storage_interaction/one_drive/open_drive_link_query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# frozen_string_literal: true | ||
|
||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2023 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module Storages | ||
module Peripherals | ||
module StorageInteraction | ||
module OneDrive | ||
class OpenDriveLinkQuery | ||
def self.call(storage:, user:) | ||
new(storage).call(user:) | ||
end | ||
|
||
def initialize(storage) | ||
@storage = storage | ||
@uri = storage.uri | ||
end | ||
|
||
def call(user:) | ||
Util.using_user_token(@storage, user) do |token| | ||
make_request(token).map(&web_url) | ||
end | ||
end | ||
|
||
private | ||
|
||
def make_request(token) | ||
response_data = Net::HTTP.start(@uri.host, @uri.port, use_ssl: true) do |http| | ||
http.get(drive_uri_path, { 'Authorization' => "Bearer #{token.access_token}" }) | ||
end | ||
|
||
handle_responses(response_data) | ||
end | ||
|
||
def handle_responses(response) | ||
json = MultiJson.load(response.body, symbolize_keys: true) | ||
|
||
case response | ||
when Net::HTTPSuccess | ||
ServiceResult.success(result: json) | ||
when Net::HTTPNotFound | ||
ServiceResult.failure(result: :not_found, | ||
errors: ::Storages::StorageError.new(code: :not_found, data: json)) | ||
when Net::HTTPForbidden | ||
ServiceResult.failure(result: :forbidden, | ||
errors: ::Storages::StorageError.new(code: :forbidden, data: json)) | ||
when Net::HTTPUnauthorized | ||
ServiceResult.failure(result: :unauthorized, | ||
errors: ::Storages::StorageError.new(code: :unauthorized, data: json)) | ||
else | ||
ServiceResult.failure(result: :error, | ||
errors: ::Storages::StorageError.new(code: :error, data: json)) | ||
end | ||
end | ||
|
||
def drive_uri_path | ||
"/v1.0/drives/#{@storage.drive_id}?$select=webUrl" | ||
end | ||
|
||
def web_url | ||
->(json) do | ||
json[:webUrl] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.