Class: PowerBI::Admin

Inherits:
Object
  • Object
show all
Defined in:
lib/power-bi/admin.rb

Instance Method Summary collapse

Constructor Details

#initialize(tenant) ⇒ Admin

Returns a new instance of Admin.



4
5
6
# File 'lib/power-bi/admin.rb', line 4

def initialize(tenant)
  @tenant = tenant
end

Instance Method Details

#force_delete_workspace_by_workspace_id(user_email, workspace_id) ⇒ Object



63
64
65
66
# File 'lib/power-bi/admin.rb', line 63

def force_delete_workspace_by_workspace_id(user_email, workspace_id)
  add_user(user_email, workspace_id, access_right: "Admin")
  @tenant.workspace(workspace_id).delete
end

#force_delete_workspace_by_workspace_name(user_email, workspace_name) ⇒ Object



57
58
59
60
61
# File 'lib/power-bi/admin.rb', line 57

def force_delete_workspace_by_workspace_name(user_email, workspace_name)
  workspace = get_workspaces(filter: "name eq '#{workspace_name}' and state eq 'Active'").first
  add_user(user_email, workspace[:id], access_right: "Admin")
  @tenant.workspace(workspace[:id]).delete
end

#get_user_artifact_access(user_id, artifact_types: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/power-bi/admin.rb', line 8

def get_user_artifact_access(user_id, artifact_types: nil)
  if artifact_types
    params = {artifactTypes: artifact_types.join(',')}
  else
    params = {}
  end

  url = "/admin/users/#{user_id}/artifactAccess"

  resp = @tenant.get(url, params)
  data = resp[:ArtifactAccessEntities]

  continuation_token = resp[:continuationToken]

  while continuation_token
    params = {continuationToken: "'#{continuation_token}'"}
    resp = @tenant.get(url, params)
    data += resp[:ArtifactAccessEntities]
    continuation_token = resp[:continuationToken] ? URI::decode_uri_component(resp[:continuationToken]) : nil
  end

  data
end

#get_workspaces(filter: nil, expand: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/power-bi/admin.rb', line 32

def get_workspaces(filter: nil, expand: nil)
  params = {}
  params[:$filter] = filter if filter
  params[:$expand] = expand if expand

  url = '/admin/groups'

  nr_records = 5000
  count = 0

  data = []

  loop do
    params[:$top] = nr_records
    params[:$skip] = count
    resp = @tenant.get(url, params)
    data += resp[:value]
    batch_count = resp[:value].size
    count += batch_count
    break if batch_count < nr_records
  end

  data
end