Skip to content

Commit 3b7627a

Browse files
authored
Merge branch 'master' into hyperlinks
Signed-off-by: Ayush Ukhalkar <[email protected]>
2 parents 2f8f0ee + 73aaef9 commit 3b7627a

10 files changed

+365
-179
lines changed
Lines changed: 113 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,116 @@
1-
{{ $data := "" }} {{ $p := "static/data/csv/keys.csv" }} {{ $excludedColumns :=
2-
slice 0 10 11 12 13 14 15 16 17 18 }} {{ if os.FileExists $p }} {{ $opts := dict
3-
"delimiter" "," }} {{ $data = (os.ReadFile $p | transform.Unmarshal $opts) }} {{
4-
else }} {{ errorf "Unable to get resource %q" $p }} {{ end }} {{ if $data }} {{
5-
$uniqueCategories := slice }} {{ $stopAddingCategories := false }} {{ range $i,
6-
$header := index $data 1 }} {{ if gt $i 3 }} {{if eq $header "Keychain ID"}} {{
7-
$stopAddingCategories = true }} {{end}} {{ if not $stopAddingCategories }} {{ if
8-
and (ne (trim $header "") "") (not (in $uniqueCategories $header)) }} {{
9-
$uniqueCategories = $uniqueCategories | append $header }} {{ end }} {{ end }} {{
10-
end }} {{end}} {{ range $index, $category := $uniqueCategories }}
11-
<div class="csvtable-div">
12-
<h2 id="{{ $category | urlquery }}">{{ $category }} Role </h2>
13-
<table class="csvtable td-initial">
14-
<thead>
15-
<tr>
16-
{{ range $i, $col := index $data 1 }} {{ if and (not (in
17-
$excludedColumns $i)) (or (eq $i 0) (ne $i 1) (ne $i 2)) }} {{ if and
18-
(eq $i 1) }}
19-
<th>Permission</th>
20-
{{ else }} {{ if and (eq $i 2) }}
21-
<th>Description</th>
22-
{{ end }}{{ end }} {{ end }} {{ end }}
23-
</tr>
24-
</thead>
25-
<tbody>
26-
{{ range $i, $row := $data }} {{ if gt $i 0 }} {{/* Skip the header row */}}
27-
{{ $hasAccess := false }} {{/* Flag to track if the row has access for the category */}}
28-
{{ $functionValue := "" }} {{/* Variable to hold the Function value */}}
29-
{{ $featureValue := "" }} {{/* Variable to hold the Feature value */}}
30-
31-
{{/* Find the column indices for Category, Function, and Feature */}}
32-
{{ $categoryIndex := -1 }}
33-
{{ $functionIndex := -1 }}
34-
{{ $featureIndex := -1 }}
35-
{{ range $j, $header := index $data 1 }} {{/* Assuming the first row contains headers */}}
36-
{{ if eq $header $category }} {{/* Check if the header matches the current category */}}
37-
{{ $categoryIndex = $j }}
38-
{{ end }}
39-
{{ if eq $header "Function" }}
40-
{{ $functionIndex = $j }}
41-
{{ end }}
42-
{{ if eq $header "Feature" }}
43-
{{ $featureIndex = $j }}
44-
{{ end }}
45-
{{ end }}
46-
{{/* Check if the row has access for the category */}}
47-
{{ if and (ge $categoryIndex 0) (or (eq (index $row $categoryIndex) "X") (eq (index $row $categoryIndex) "X*")) }}
48-
{{ $hasAccess = true }}
49-
{{ end }}
50-
{{/* Get the Function and Feature values if the row has access */}}
51-
{{ if $hasAccess }}
52-
{{ $functionValue = index $row $functionIndex }}
53-
{{ $featureValue = index $row $featureIndex }}
54-
{{ end }}
55-
{{/* Print the row if it has access */}}
56-
{{ if $hasAccess }}
1+
{{ $data := "" }}
2+
{{ $p := "static/data/csv/keys.csv" }}
3+
{{ $excludedColumns := slice 0 10 11 12 13 14 15 16 17 18 }}
4+
5+
{{ if os.FileExists $p }}
6+
{{ $opts := dict "delimiter" "," }}
7+
{{ $data = (os.ReadFile $p | transform.Unmarshal $opts) }}
8+
{{ else }}
9+
{{ errorf "Unable to get resource %q" $p }}
10+
{{ end }}
11+
12+
{{ if $data }}
13+
{{ $uniqueCategories := slice }}
14+
{{ $stopAddingCategories := false }}
15+
16+
{{ range $i, $header := index $data 1 }}
17+
{{ if gt $i 3 }}
18+
{{ if eq $header "Keychain ID" }}
19+
{{ $stopAddingCategories = true }}
20+
{{ end }}
21+
22+
{{ if not $stopAddingCategories }}
23+
{{ if and (ne (trim $header "") "") (not (in $uniqueCategories $header)) }}
24+
{{ $uniqueCategories = $uniqueCategories | append $header }}
25+
{{ end }}
26+
{{ end }}
27+
{{ end }}
28+
{{ end }}
29+
30+
{{ range $index, $category := $uniqueCategories }}
31+
<div class="csvtable-div">
32+
{{ $sectionName := $category | lower }}
33+
{{ $urlPath := "roles" }}
34+
{{ if hasPrefix $sectionName "workspace" }}
35+
{{ $urlPath = "roles/workspace-roles" }}
36+
{{ else if hasPrefix $sectionName "team" }}
37+
{{ $urlPath = "roles/team-roles" }}
38+
{{ else if hasPrefix $sectionName "org" }}
39+
{{ $urlPath = "roles/organization-roles" }}
40+
{{ else if hasPrefix $sectionName "provider" }}
41+
{{ $urlPath = "roles/#provider-admin-role" }}
42+
{{ else }}
43+
{{ $urlPath = print "roles/" $sectionName | urlize }}
44+
{{ end }}
45+
<h2><a href="/cloud/security/{{ $urlPath }}">{{ $category }} Role</a></h2>
46+
<table class="csvtable td-initial">
47+
<thead>
5748
<tr>
58-
<td>{{ $functionValue }} </td>
59-
<td>{{ $featureValue }}</td>
49+
{{ range $i, $col := index $data 1 }}
50+
{{ if and (not (in $excludedColumns $i)) (or (eq $i 0) (ne $i 1) (ne $i 2)) }}
51+
{{ if and (eq $i 1) }}
52+
<th>Permission</th>
53+
{{ else }}
54+
{{ if and (eq $i 2) }}
55+
<th>Description</th>
56+
{{ end }}
57+
{{ end }}
58+
{{ end }}
59+
{{ end }}
6060
</tr>
61-
{{end}}
62-
{{ end }} {{ end }}
63-
</tbody>
64-
</table>
65-
</div>
66-
{{ end }} {{ else }}
61+
</thead>
62+
<tbody>
63+
{{ range $i, $row := $data }}
64+
{{ if gt $i 0 }}
65+
{{/* Skip the header row */}}
66+
{{ $hasAccess := false }}
67+
{{/* Flag to track if the row has access for the category */}}
68+
{{ $functionValue := "" }}
69+
{{/* Variable to hold the Function value */}}
70+
{{ $featureValue := "" }}
71+
{{/* Variable to hold the Feature value */}}
72+
73+
{{/* Find the column indices for Category, Function, and Feature */}}
74+
{{ $categoryIndex := -1 }}
75+
{{ $functionIndex := -1 }}
76+
{{ $featureIndex := -1 }}
77+
{{ range $j, $header := index $data 1 }}
78+
{{/* Assuming the first row contains headers */}}
79+
{{ if eq $header $category }}
80+
{{/* Check if the header matches the current category */}}
81+
{{ $categoryIndex = $j }}
82+
{{ end }}
83+
{{ if eq $header "Function" }}
84+
{{ $functionIndex = $j }}
85+
{{ end }}
86+
{{ if eq $header "Feature" }}
87+
{{ $featureIndex = $j }}
88+
{{ end }}
89+
{{ end }}
90+
91+
{{/* Check if the row has access for the category */}}
92+
{{ if and (ge $categoryIndex 0) (or (eq (index $row $categoryIndex) "X") (eq (index $row $categoryIndex) "X*")) }}
93+
{{ $hasAccess = true }}
94+
{{ end }}
95+
{{/* Get the Function and Feature values if the row has access */}}
96+
{{ if $hasAccess }}
97+
{{ $functionValue = index $row $functionIndex }}
98+
{{ $featureValue = index $row $featureIndex }}
99+
{{ end }}
100+
101+
{{/* Print the row if it has access */}}
102+
{{ if $hasAccess }}
103+
<tr>
104+
<td>{{ $functionValue }} </td>
105+
<td>{{ $featureValue }}</td>
106+
</tr>
107+
{{ end }}
108+
{{ end }}
109+
{{ end }}
110+
</tbody>
111+
</table>
112+
</div>
113+
{{ end }}
114+
{{ else }}
67115
<p>No data available.</p>
68-
{{ end }}
69-
70-
116+
{{ end }}

layouts/shortcodes/csvtable.html

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{ $data := "" }}
22

33
{{ $p := "static/data/csv/keys.csv" }}
4-
{{ $excludedColumns := slice 0 10 11 12 13 14 15 16 17 18 }}
4+
{{ $excludedColumns := slice "Category" "Keychain ID" "Key ID" "Inserted" "Local Provider" }} <!-- Add the names of the columns to exclude -->
55

66
{{ if os.FileExists $p }}
77
{{ $opts := dict "delimiter" "," }}
@@ -10,9 +10,14 @@
1010
{{ errorf "Unable to get resource %q" $p }}
1111
{{ end }}
1212

13-
1413
{{ if $data }}
1514
{{ $uniqueCategories := slice }}
15+
{{ $header := index $data 1 }}
16+
{{ $headerMap := dict }}
17+
18+
{{ range $i, $col := $header }}
19+
{{ $headerMap = merge $headerMap (dict $col $i) }}
20+
{{ end }}
1621

1722
{{ range $i, $row := $data }}
1823
{{ if gt $i 1 }}
@@ -28,28 +33,43 @@ <h2>{{ $category }} Permissions</h2>
2833
<table class="csvtable td-initial">
2934
<thead>
3035
<tr>
31-
{{ range $i, $col := index $data 1 }}
32-
{{ if and (not (in $excludedColumns $i)) (or (eq $i 0) (ne $i 1) (ne $i 2)) }}
33-
{{ if and (eq $i 1) }}
34-
<th>Permission</th>
35-
{{ else }}
36-
{{ if and (eq $i 2) }}
37-
<th>Description</th>
38-
{{ else }}
39-
<th>{{ $col }}</th>
40-
{{ end }}{{ end }}
36+
{{ range $i, $col := $header }}
37+
{{ if not (in $excludedColumns $col) }}
38+
{{ if eq $col "Function" }}
39+
<th>Permission</th>
40+
{{ else if eq $col "Feature" }}
41+
<th>Description</th>
42+
{{ else }}
43+
{{ $sectionName := $col | lower }}
44+
{{ $urlPath := "roles" }}
45+
{{ if hasPrefix $sectionName "workspace" }}
46+
{{ $urlPath = "roles/workspace-roles" }}
47+
{{ else if hasPrefix $sectionName "team" }}
48+
{{ $urlPath = "roles/team-roles" }}
49+
{{ else if hasPrefix $sectionName "org" }}
50+
{{ $urlPath = "roles/organization-roles" }}
51+
{{ else if hasPrefix $sectionName "provider" }}
52+
{{ $urlPath = "roles/#provider-admin-role" }}
53+
{{ else if hasPrefix $sectionName "user" }}
54+
{{ $urlPath = "roles/user-role" }}
55+
{{ else }}
56+
{{ $urlPath = print "roles/" }}
57+
{{ end }}
58+
<th><a href="/cloud/security/{{ $urlPath }}">{{ $col }}</a></th>
59+
{{ end }}
4160
{{ end }}
4261
{{ end }}
4362
</tr>
4463
</thead>
4564
<tbody>
4665
{{ range $i, $row := $data }}
47-
{{ if and (gt $i 0) (eq (trim (index $row 0) " ") $category) }}
66+
{{ if and (gt $i 1) (eq (trim (index $row 0) " ") $category) }}
4867
<tr>
4968
{{ range $j, $cell := $row }}
50-
{{ if and (not (in $excludedColumns $j)) (or (gt $j 2) (lt $j 10)) }}
69+
{{ $col := index $header $j }}
70+
{{ if not (in $excludedColumns $col) }}
5171
<td>
52-
{{ if and (gt $j 2) (lt $j 10) }}
72+
{{ if and (gt $j 2) (lt $j 10) }}
5373
{{ if eq $cell "X" }}
5474
5575
{{ else if eq $cell "X*" }}

0 commit comments

Comments
 (0)