Class: ConnectorsSdk::ConfluenceCloud::Extractor

Inherits:
ConnectorsSdk::Confluence::Extractor show all
Defined in:
lib/connectors_sdk/confluence_cloud/extractor.rb

Constant Summary

Constants inherited from ConnectorsSdk::Confluence::Extractor

ConnectorsSdk::Confluence::Extractor::CONTENT_MODIFIED_SINCE_CURSOR_KEY, ConnectorsSdk::Confluence::Extractor::CONTENT_MODIFIED_SINCE_NEXT_CURSOR_KEY, ConnectorsSdk::Confluence::Extractor::CONTENT_NEXT_CURSOR_KEY, ConnectorsSdk::Confluence::Extractor::CONTENT_OFFSET_CURSOR_KEY

Constants inherited from Base::Extractor

Base::Extractor::DEFAULT_CURSOR_KEY, Base::Extractor::MAX_CONNECTION_ATTEMPTS, Base::Extractor::TRANSIENT_SERVER_ERROR_CLASSES

Instance Attribute Summary

Attributes inherited from Base::Extractor

#client_proc, #completed, #config, #content_source_id, #features, #monitor, #original_cursors, #service_type

Instance Method Summary collapse

Methods inherited from ConnectorsSdk::Confluence::Extractor

#yield_deleted_ids, #yield_document_changes

Methods inherited from Base::Extractor

#authorization_data, #authorization_data!, #client, #client!, #convert_transient_server_errors, #cursors_modified_since_start?, #deleted_ids, #document_changes, #download_args_and_proc, #evictable?, #identifying_error_message, #initialize, #permissions, #retrieve_latest_cursors, #transient_error?, #with_auth_tokens_and_retry, #yield_deleted_ids, #yield_document_changes, #yield_single_document_change

Constructor Details

This class inherits a constructor from ConnectorsSdk::Base::Extractor

Instance Method Details

#download(item) ⇒ Object



52
53
54
55
56
57
# File 'lib/connectors_sdk/confluence_cloud/extractor.rb', line 52

def download(item)
  content = item[:content]
  parent_id = content.dig('container', 'id')
  base_url = client.base_url.end_with?('/wiki') ? client.base_url : "#{client.base_url}/wiki"
  client.download("#{base_url}/rest/api/content/#{parent_id}/child/attachment/#{content['id']}/download").body
end

#yield_permissions(source_user_id) {|user_permissions.flatten.uniq.sort| ... } ⇒ Object

Yields:

  • (user_permissions.flatten.uniq.sort)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/connectors_sdk/confluence_cloud/extractor.rb', line 15

def yield_permissions(source_user_id)
  # yield empty permissions if the user is suspended or deleted
  user = client.user(source_user_id, :expand => 'operations')
  if user.nil? || user.operations.blank?
    yield [] and return
  end

  # refresh space permissions if not initialized
  if @space_permissions_cache.nil?
    @space_permissions_cache = {}
    yield_spaces do |space|
      if config.index_permissions
        get_space_permissions(space)
      end
    end
  end

  direct_spaces = get_user_spaces(source_user_id)
  indirect_spaces = []

  group_permissions = []
  client.user_groups(source_user_id).each do |group|
    group_name = group.name
    group_spaces = get_group_spaces(group_name)
    indirect_spaces << group_spaces
    group_permissions << "group:#{group_name}"
  end

  total_user_spaces = indirect_spaces.flatten.concat(direct_spaces).uniq
  user_permissions = ["user:#{source_user_id}"]
    .concat(group_permissions)
    .product(total_user_spaces)
    .collect { |permission, space| "#{space}/#{permission}" }

  yield user_permissions.flatten.uniq.sort
end