Skip to content

Commit

Permalink
Merge pull request #154 from ClusterCockpit/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
moebiusband73 authored Jun 20, 2023
2 parents 1f60963 + c973a29 commit d0516f1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 52 deletions.
8 changes: 6 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ before:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
- CGO_ENABLED=1
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goamd64:
- v2
- v3
goarm:
- "7"
id: "cc-backend"
main: ./cmd/cc-backend
tags:
- static_build
hooks:
pre: make frontend
ignore:
- goos: linux
goarch: arm64

archives:
- format: tar.gz
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ SVELTE_SRC = $(wildcard $(FRONTEND)/src/*.svelte) \
$(wildcard $(FRONTEND)/src/plots/*.svelte) \
$(wildcard $(FRONTEND)/src/joblist/*.svelte)

.PHONY: clean test tags $(TARGET)
.PHONY: clean test tags frontend $(TARGET)

.NOTPARALLEL:

$(TARGET): $(VAR) $(CFG) $(SVELTE_TARGETS)
$(info ===> BUILD cc-backend)
@go build -ldflags=${LD_FLAGS} ./cmd/cc-backend

frontend:
$(info ===> BUILD frontend)
cd web/frontend && npm install && npm run build

clean:
$(info ===> CLEAN)
@go clean
Expand Down
1 change: 1 addition & 0 deletions internal/api/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func decode(r io.Reader, val interface{}) error {
// @security ApiKeyAuth
// @router /jobs/ [get]
func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) {

if user := auth.GetUser(r.Context()); user != nil && !user.HasRole(auth.RoleApi) {
handleError(fmt.Errorf("missing role: %v", auth.GetRoleString(auth.RoleApi)), http.StatusForbidden, rw)
return
Expand Down
10 changes: 4 additions & 6 deletions internal/repository/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func (r *JobRepository) testQueryJobs(
page *model.PageRequest,
order *model.OrderByInput) ([]*schema.Job, error) {

return r.queryJobs(sq.Select(jobColumns...).From("job"),
filters, page, order)
return r.queryJobs(sq.Select(jobColumns...).From("job"), filters, page, order)
}

// Public function with added securityCheck, calls private queryJobs function above
Expand All @@ -98,8 +97,7 @@ func (r *JobRepository) QueryJobs(
return nil, qerr
}

return r.queryJobs(query,
filters, page, order)
return r.queryJobs(query, filters, page, order)
}

// SecurityCheck-less, private: returns a list of minimal job information (DB-ID and jobId) of shared jobs for link-building based the provided filters.
Expand Down Expand Up @@ -202,12 +200,12 @@ func (r *JobRepository) CountJobs(
return r.countJobs(query, filters)
}

func SecurityCheck(ctx context.Context, query sq.SelectBuilder) (queryOut sq.SelectBuilder, err error) {
func SecurityCheck(ctx context.Context, query sq.SelectBuilder) (sq.SelectBuilder, error) {
user := auth.GetUser(ctx)
if user == nil {
var qnil sq.SelectBuilder
return qnil, fmt.Errorf("user context is nil!")
} else if user.HasAnyRole([]auth.Role{auth.RoleAdmin, auth.RoleSupport}) { // Admin & Co. : All jobs
} else if user.HasAnyRole([]auth.Role{auth.RoleAdmin, auth.RoleSupport, auth.RoleApi}) { // Admin & Co. : All jobs
return query, nil
} else if user.HasRole(auth.RoleManager) { // Manager : Add filter for managed projects' jobs only + personal jobs
if len(user.Projects) != 0 {
Expand Down
10 changes: 10 additions & 0 deletions web/frontend/src/List.root.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
export let type;
export let filterPresets;
// By default, look at the jobs of the last 30 days:
if (filterPresets?.startTime == null) {
if (filterPresets == null)
filterPresets = {}
const lastMonth = (new Date(Date.now() - (30*24*60*60*1000))).toISOString()
const now = (new Date(Date.now())).toISOString()
filterPresets.startTime = { from: lastMonth, to: now, text: 'Last 30 Days', url: 'last30d' }
}
console.assert(
type == "USER" || type == "PROJECT",
"Invalid list type provided!"
Expand Down
79 changes: 36 additions & 43 deletions web/frontend/src/filters/Filters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
projectMatch: filterPresets.projectMatch || 'contains',
userMatch: filterPresets.userMatch || 'contains',
cluster: filterPresets.cluster || null,
partition: filterPresets.partition || null,
states: filterPresets.states || filterPresets.state ? [filterPresets.state].flat() : allJobStates,
startTime: filterPresets.startTime || { from: null, to: null },
tags: filterPresets.tags || [],
duration: filterPresets.duration || { from: null, to: null },
jobId: filterPresets.jobId || '',
arrayJobId: filterPresets.arrayJobId || null,
user: filterPresets.user || '',
project: filterPresets.project || '',
jobName: filterPresets.jobName || '',
cluster: filterPresets.cluster || null,
partition: filterPresets.partition || null,
states: filterPresets.states || filterPresets.state ? [filterPresets.state].flat() : allJobStates,
startTime: filterPresets.startTime || { from: null, to: null },
tags: filterPresets.tags || [],
duration: filterPresets.duration || { from: null, to: null },
jobId: filterPresets.jobId || '',
arrayJobId: filterPresets.arrayJobId || null,
user: filterPresets.user || '',
project: filterPresets.project || '',
jobName: filterPresets.jobName || '',
numNodes: filterPresets.numNodes || { from: null, to: null },
numHWThreads: filterPresets.numHWThreads || { from: null, to: null },
Expand Down Expand Up @@ -120,7 +120,11 @@
for (let state of filters.states)
opts.push(`state=${state}`)
if (filters.startTime.from && filters.startTime.to)
opts.push(`startTime=${dateToUnixEpoch(filters.startTime.from)}-${dateToUnixEpoch(filters.startTime.to)}`)
// if (filters.startTime.url) {
// opts.push(`startTime=${filters.startTime.url}`)
// } else {
opts.push(`startTime=${dateToUnixEpoch(filters.startTime.from)}-${dateToUnixEpoch(filters.startTime.to)}`)
// }
for (let tag of filters.tags)
opts.push(`tag=${tag}`)
if (filters.duration.from && filters.duration.to)
Expand Down Expand Up @@ -193,16 +197,18 @@
<DropdownItem divider/>
<DropdownItem disabled>Start Time Qick Selection</DropdownItem>
{#each [
{ text: 'Last 6hrs', seconds: 6*60*60 },
{ text: 'Last 12hrs', seconds: 12*60*60 },
{ text: 'Last 24hrs', seconds: 24*60*60 },
{ text: 'Last 48hrs', seconds: 48*60*60 },
{ text: 'Last 7 days', seconds: 7*24*60*60 },
{ text: 'Last 30 days', seconds: 30*24*60*60 }
] as {text, seconds}}
{ text: 'Last 6hrs', url: 'last6h', seconds: 6*60*60 },
// { text: 'Last 12hrs', seconds: 12*60*60 },
{ text: 'Last 24hrs', url: 'last24h', seconds: 24*60*60 },
// { text: 'Last 48hrs', seconds: 48*60*60 },
{ text: 'Last 7 days', url: 'last7d', seconds: 7*24*60*60 },
{ text: 'Last 30 days', url: 'last30d', seconds: 30*24*60*60 }
] as {text, url, seconds}}
<DropdownItem on:click={() => {
filters.startTime.from = (new Date(Date.now() - seconds * 1000)).toISOString()
filters.startTime.to = (new Date(Date.now())).toISOString()
filters.startTime.text = text,
filters.startTime.url = url
update()
}}>
<Icon name="calendar-range"/> {text}
Expand All @@ -212,27 +218,6 @@
</DropdownMenu>
</ButtonDropdown>
</Col>
<!-- {#if startTimeQuickSelect}
<Col xs="auto">
<TimeSelection customEnabled={false} anyEnabled={true}
from={filters.startTime.from ? new Date(filters.startTime.from) : null}
to={filters.startTime.to ? new Date(filters.startTime.to) : null}
options={{
'Last 6hrs': 6*60*60,
'Last 12hrs': 12*60*60,
'Last 24hrs': 24*60*60,
'Last 48hrs': 48*60*60,
'Last 7 days': 7*24*60*60,
'Last 30 days': 30*24*60*60}}
on:change={({ detail: { from, to } }) => {
filters.startTime.from = from?.toISOString()
filters.startTime.to = to?.toISOString()
// console.log(filters.startTime)
update()
}}
/>
</Col>
{/if} -->
<Col xs="auto">
{#if filters.cluster}
<Info icon="cpu" on:click={() => (isClusterOpen = true)}>
Expand All @@ -251,8 +236,12 @@

{#if filters.startTime.from || filters.startTime.to}
<Info icon="calendar-range" on:click={() => (isStartTimeOpen = true)}>
{new Date(filters.startTime.from).toLocaleString()} - {new Date(filters.startTime.to).toLocaleString()}
</Info>
{#if filters.startTime.text}
{filters.startTime.text}
{:else}
{new Date(filters.startTime.from).toLocaleString()} - {new Date(filters.startTime.to).toLocaleString()}
{/if}
</Info>
{/if}

{#if filters.duration.from || filters.duration.to}
Expand Down Expand Up @@ -307,7 +296,11 @@
bind:isOpen={isStartTimeOpen}
bind:from={filters.startTime.from}
bind:to={filters.startTime.to}
on:update={() => update()} />
on:update={() => {
delete filters.startTime['text']
delete filters.startTime['url']
update()
}} />

<Duration
bind:isOpen={isDurationOpen}
Expand Down

0 comments on commit d0516f1

Please sign in to comment.