Skip to content

Commit

Permalink
Merge branch 'master' into Tip
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Ukhalkar <[email protected]>
  • Loading branch information
iushdoescode authored Aug 1, 2024
2 parents 890a1fd + 73aaef9 commit e10099f
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 179 deletions.
180 changes: 113 additions & 67 deletions layouts/shortcodes/csvtable-roles.html
Original file line number Diff line number Diff line change
@@ -1,70 +1,116 @@
{{ $data := "" }} {{ $p := "static/data/csv/keys.csv" }} {{ $excludedColumns :=
slice 0 10 11 12 13 14 15 16 17 18 }} {{ if os.FileExists $p }} {{ $opts := dict
"delimiter" "," }} {{ $data = (os.ReadFile $p | transform.Unmarshal $opts) }} {{
else }} {{ errorf "Unable to get resource %q" $p }} {{ end }} {{ if $data }} {{
$uniqueCategories := slice }} {{ $stopAddingCategories := false }} {{ range $i,
$header := index $data 1 }} {{ if gt $i 3 }} {{if eq $header "Keychain ID"}} {{
$stopAddingCategories = true }} {{end}} {{ if not $stopAddingCategories }} {{ if
and (ne (trim $header "") "") (not (in $uniqueCategories $header)) }} {{
$uniqueCategories = $uniqueCategories | append $header }} {{ end }} {{ end }} {{
end }} {{end}} {{ range $index, $category := $uniqueCategories }}
<div class="csvtable-div">
<h2 id="{{ $category | urlquery }}">{{ $category }} Role </h2>
<table class="csvtable td-initial">
<thead>
<tr>
{{ range $i, $col := index $data 1 }} {{ if and (not (in
$excludedColumns $i)) (or (eq $i 0) (ne $i 1) (ne $i 2)) }} {{ if and
(eq $i 1) }}
<th>Permission</th>
{{ else }} {{ if and (eq $i 2) }}
<th>Description</th>
{{ end }}{{ end }} {{ end }} {{ end }}
</tr>
</thead>
<tbody>
{{ range $i, $row := $data }} {{ if gt $i 0 }} {{/* Skip the header row */}}
{{ $hasAccess := false }} {{/* Flag to track if the row has access for the category */}}
{{ $functionValue := "" }} {{/* Variable to hold the Function value */}}
{{ $featureValue := "" }} {{/* Variable to hold the Feature value */}}

{{/* Find the column indices for Category, Function, and Feature */}}
{{ $categoryIndex := -1 }}
{{ $functionIndex := -1 }}
{{ $featureIndex := -1 }}
{{ range $j, $header := index $data 1 }} {{/* Assuming the first row contains headers */}}
{{ if eq $header $category }} {{/* Check if the header matches the current category */}}
{{ $categoryIndex = $j }}
{{ end }}
{{ if eq $header "Function" }}
{{ $functionIndex = $j }}
{{ end }}
{{ if eq $header "Feature" }}
{{ $featureIndex = $j }}
{{ end }}
{{ end }}
{{/* Check if the row has access for the category */}}
{{ if and (ge $categoryIndex 0) (or (eq (index $row $categoryIndex) "X") (eq (index $row $categoryIndex) "X*")) }}
{{ $hasAccess = true }}
{{ end }}
{{/* Get the Function and Feature values if the row has access */}}
{{ if $hasAccess }}
{{ $functionValue = index $row $functionIndex }}
{{ $featureValue = index $row $featureIndex }}
{{ end }}
{{/* Print the row if it has access */}}
{{ if $hasAccess }}
{{ $data := "" }}
{{ $p := "static/data/csv/keys.csv" }}
{{ $excludedColumns := slice 0 10 11 12 13 14 15 16 17 18 }}

{{ if os.FileExists $p }}
{{ $opts := dict "delimiter" "," }}
{{ $data = (os.ReadFile $p | transform.Unmarshal $opts) }}
{{ else }}
{{ errorf "Unable to get resource %q" $p }}
{{ end }}

{{ if $data }}
{{ $uniqueCategories := slice }}
{{ $stopAddingCategories := false }}

{{ range $i, $header := index $data 1 }}
{{ if gt $i 3 }}
{{ if eq $header "Keychain ID" }}
{{ $stopAddingCategories = true }}
{{ end }}

{{ if not $stopAddingCategories }}
{{ if and (ne (trim $header "") "") (not (in $uniqueCategories $header)) }}
{{ $uniqueCategories = $uniqueCategories | append $header }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}

{{ range $index, $category := $uniqueCategories }}
<div class="csvtable-div">
{{ $sectionName := $category | lower }}
{{ $urlPath := "roles" }}
{{ if hasPrefix $sectionName "workspace" }}
{{ $urlPath = "roles/workspace-roles" }}
{{ else if hasPrefix $sectionName "team" }}
{{ $urlPath = "roles/team-roles" }}
{{ else if hasPrefix $sectionName "org" }}
{{ $urlPath = "roles/organization-roles" }}
{{ else if hasPrefix $sectionName "provider" }}
{{ $urlPath = "roles/#provider-admin-role" }}
{{ else }}
{{ $urlPath = print "roles/" $sectionName | urlize }}
{{ end }}
<h2><a href="/cloud/security/{{ $urlPath }}">{{ $category }} Role</a></h2>
<table class="csvtable td-initial">
<thead>
<tr>
<td>{{ $functionValue }} </td>
<td>{{ $featureValue }}</td>
{{ range $i, $col := index $data 1 }}
{{ if and (not (in $excludedColumns $i)) (or (eq $i 0) (ne $i 1) (ne $i 2)) }}
{{ if and (eq $i 1) }}
<th>Permission</th>
{{ else }}
{{ if and (eq $i 2) }}
<th>Description</th>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</tr>
{{end}}
{{ end }} {{ end }}
</tbody>
</table>
</div>
{{ end }} {{ else }}
</thead>
<tbody>
{{ range $i, $row := $data }}
{{ if gt $i 0 }}
{{/* Skip the header row */}}
{{ $hasAccess := false }}
{{/* Flag to track if the row has access for the category */}}
{{ $functionValue := "" }}
{{/* Variable to hold the Function value */}}
{{ $featureValue := "" }}
{{/* Variable to hold the Feature value */}}

{{/* Find the column indices for Category, Function, and Feature */}}
{{ $categoryIndex := -1 }}
{{ $functionIndex := -1 }}
{{ $featureIndex := -1 }}
{{ range $j, $header := index $data 1 }}
{{/* Assuming the first row contains headers */}}
{{ if eq $header $category }}
{{/* Check if the header matches the current category */}}
{{ $categoryIndex = $j }}
{{ end }}
{{ if eq $header "Function" }}
{{ $functionIndex = $j }}
{{ end }}
{{ if eq $header "Feature" }}
{{ $featureIndex = $j }}
{{ end }}
{{ end }}

{{/* Check if the row has access for the category */}}
{{ if and (ge $categoryIndex 0) (or (eq (index $row $categoryIndex) "X") (eq (index $row $categoryIndex) "X*")) }}
{{ $hasAccess = true }}
{{ end }}
{{/* Get the Function and Feature values if the row has access */}}
{{ if $hasAccess }}
{{ $functionValue = index $row $functionIndex }}
{{ $featureValue = index $row $featureIndex }}
{{ end }}

{{/* Print the row if it has access */}}
{{ if $hasAccess }}
<tr>
<td>{{ $functionValue }} </td>
<td>{{ $featureValue }}</td>
</tr>
{{ end }}
{{ end }}
{{ end }}
</tbody>
</table>
</div>
{{ end }}
{{ else }}
<p>No data available.</p>
{{ end }}


{{ end }}
50 changes: 35 additions & 15 deletions layouts/shortcodes/csvtable.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ $data := "" }}

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

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


{{ if $data }}
{{ $uniqueCategories := slice }}
{{ $header := index $data 1 }}
{{ $headerMap := dict }}

{{ range $i, $col := $header }}
{{ $headerMap = merge $headerMap (dict $col $i) }}
{{ end }}

{{ range $i, $row := $data }}
{{ if gt $i 1 }}
Expand All @@ -28,28 +33,43 @@ <h2>{{ $category }} Permissions</h2>
<table class="csvtable td-initial">
<thead>
<tr>
{{ range $i, $col := index $data 1 }}
{{ if and (not (in $excludedColumns $i)) (or (eq $i 0) (ne $i 1) (ne $i 2)) }}
{{ if and (eq $i 1) }}
<th>Permission</th>
{{ else }}
{{ if and (eq $i 2) }}
<th>Description</th>
{{ else }}
<th>{{ $col }}</th>
{{ end }}{{ end }}
{{ range $i, $col := $header }}
{{ if not (in $excludedColumns $col) }}
{{ if eq $col "Function" }}
<th>Permission</th>
{{ else if eq $col "Feature" }}
<th>Description</th>
{{ else }}
{{ $sectionName := $col | lower }}
{{ $urlPath := "roles" }}
{{ if hasPrefix $sectionName "workspace" }}
{{ $urlPath = "roles/workspace-roles" }}
{{ else if hasPrefix $sectionName "team" }}
{{ $urlPath = "roles/team-roles" }}
{{ else if hasPrefix $sectionName "org" }}
{{ $urlPath = "roles/organization-roles" }}
{{ else if hasPrefix $sectionName "provider" }}
{{ $urlPath = "roles/#provider-admin-role" }}
{{ else if hasPrefix $sectionName "user" }}
{{ $urlPath = "roles/user-role" }}
{{ else }}
{{ $urlPath = print "roles/" }}
{{ end }}
<th><a href="/cloud/security/{{ $urlPath }}">{{ $col }}</a></th>
{{ end }}
{{ end }}
{{ end }}
</tr>
</thead>
<tbody>
{{ range $i, $row := $data }}
{{ if and (gt $i 0) (eq (trim (index $row 0) " ") $category) }}
{{ if and (gt $i 1) (eq (trim (index $row 0) " ") $category) }}
<tr>
{{ range $j, $cell := $row }}
{{ if and (not (in $excludedColumns $j)) (or (gt $j 2) (lt $j 10)) }}
{{ $col := index $header $j }}
{{ if not (in $excludedColumns $col) }}
<td>
{{ if and (gt $j 2) (lt $j 10) }}
{{ if and (gt $j 2) (lt $j 10) }}
{{ if eq $cell "X" }}
{{ else if eq $cell "X*" }}
Expand Down
Loading

0 comments on commit e10099f

Please sign in to comment.