mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 12:51:40 +02:00
Add support for multiple projects per manager
- Handled like roles in admin view - !! NEW COLUMN CHANGED TO "projects"
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'sveltestrap'
|
||||
|
||||
export let username // empty string if auth. is disabled, otherwise the username as string
|
||||
export let project // empty string if user has no project in db (= not manager), otherwise the managed projectid as string
|
||||
export let authlevel // integer
|
||||
export let clusters // array of names
|
||||
|
||||
@@ -17,8 +16,8 @@
|
||||
|
||||
const managerviews = [
|
||||
{ title: 'My Jobs', href: `/monitoring/user/${username}`, icon: 'bar-chart-line-fill' },
|
||||
{ title: `'${project}' Jobs`, href: '/monitoring/jobs/', icon: 'card-list' },
|
||||
{ title: `'${project}' Users`, href: '/monitoring/users/', icon: 'people-fill' },
|
||||
{ title: `Managed Jobs`, href: '/monitoring/jobs/', icon: 'card-list' },
|
||||
{ title: `Managed Users`, href: '/monitoring/users/', icon: 'people-fill' },
|
||||
{ title: 'Tags', href: '/monitoring/tags/', icon: 'tags' }
|
||||
]
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
const ccconfig = getContext('cc-config')
|
||||
|
||||
export let filterPresets = {}
|
||||
export let project = ""
|
||||
export let projects = []
|
||||
export let isManager = false
|
||||
|
||||
let filters, jobList, matchedJobs = null
|
||||
@@ -72,7 +72,7 @@
|
||||
<Row>
|
||||
<Col>
|
||||
<JobList
|
||||
project={project}
|
||||
projects={projects}
|
||||
isManager={isManager}
|
||||
bind:metrics={metrics}
|
||||
bind:sorting={sorting}
|
||||
|
@@ -14,17 +14,19 @@
|
||||
|
||||
export let type
|
||||
export let filterPresets
|
||||
export let project = false
|
||||
export let projects = []
|
||||
export let isManager = false
|
||||
|
||||
console.assert(type == 'USER' || type == 'PROJECT', 'Invalid list type provided!')
|
||||
|
||||
let projectFilter = null
|
||||
let projectsFilter = null
|
||||
//Setup default filter
|
||||
if (type == 'USER' && isManager == true && project != '') {
|
||||
projectFilter = { project: {eq: project} }
|
||||
} else if (type == 'USER' && isManager == true && project == '') {
|
||||
projectFilter = { project: {eq: "noProjectForManager"} }
|
||||
if (type == 'USER' && isManager == true && projects.length == 0) {
|
||||
projectsFilter = { project: {eq: "noProjectForManager"} }
|
||||
} else if (type == 'USER' && isManager == true && projects.length == 1) {
|
||||
projectsFilter = { project: {eq: projects[0]} }
|
||||
} else {
|
||||
projectsFilter = { multiProject: projects }
|
||||
}
|
||||
|
||||
const stats = operationStore(`query($filter: [JobFilter!]!) {
|
||||
@@ -88,8 +90,8 @@
|
||||
menuText="Only {type.toLowerCase()}s with jobs that match the filters will show up"
|
||||
on:update={({ detail }) => {
|
||||
$stats.variables = { filter: detail.filters }
|
||||
if (projectFilter != null) {
|
||||
$stats.variables.filter.push(projectFilter)
|
||||
if (projectsFilter != null) {
|
||||
$stats.variables.filter.push(projectsFilter)
|
||||
}
|
||||
$stats.context.pause = false
|
||||
$stats.reexecute()
|
||||
|
@@ -87,7 +87,7 @@
|
||||
<input type="text" class="form-control" placeholder="project-id" id="project-id"/>
|
||||
<!-- PreventDefault on Sveltestrap-Button more complex to achieve than just use good ol' html button -->
|
||||
<!-- see: https://stackoverflow.com/questions/69630422/svelte-how-to-use-event-modifiers-in-my-own-components -->
|
||||
<button class="btn btn-primary" type="button" id="add-project-button" on:click|preventDefault={handleAddProject}>Reset</button>
|
||||
<button class="btn btn-primary" type="button" id="add-project-button" on:click|preventDefault={handleAddProject}>Add</button>
|
||||
<button class="btn btn-danger" type="button" id="remove-project-button" on:click|preventDefault={handleRemoveProject}>Remove</button>
|
||||
</div>
|
||||
<p>
|
||||
|
@@ -41,7 +41,7 @@
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Name</th>
|
||||
<th>Project</th>
|
||||
<th>Project(s)</th>
|
||||
<th>Email</th>
|
||||
<th>Roles</th>
|
||||
<th>JWT</th>
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
<td>{user.username}</td>
|
||||
<td>{user.name}</td>
|
||||
<td>{user.project}</td>
|
||||
<td>{user.projects}</td>
|
||||
<td>{user.email}</td>
|
||||
<td><code>{user.roles.join(', ')}</code></td>
|
||||
<td>
|
||||
|
@@ -35,16 +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 || '',
|
||||
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 || '',
|
||||
multiProject: filterPresets.multiProject || [],
|
||||
|
||||
numNodes: filterPresets.numNodes || { from: null, to: null },
|
||||
numHWThreads: filterPresets.numHWThreads || { from: null, to: null },
|
||||
@@ -94,6 +95,8 @@
|
||||
items.push({ user: { [filters.userMatch]: filters.user } })
|
||||
if (filters.project)
|
||||
items.push({ project: { [filters.projectMatch]: filters.project } })
|
||||
if (filters.multiProject.length != 0)
|
||||
items.push({ multiProject: filters.multiProject })
|
||||
for (let stat of filters.stats)
|
||||
items.push({ [stat.field]: { from: stat.from, to: stat.to } })
|
||||
|
||||
@@ -129,6 +132,9 @@
|
||||
opts.push(`userMatch=${filters.userMatch}`)
|
||||
if (filters.project)
|
||||
opts.push(`project=${filters.project}`)
|
||||
if (filters.multiProject.length != 0)
|
||||
for (let singleProj of filters.multiProject)
|
||||
opts.push(`multiProject=${singleProj}`)
|
||||
if (filters.projectMatch != 'contains')
|
||||
opts.push(`projectMatch=${filters.projectMatch}`)
|
||||
|
||||
|
@@ -23,7 +23,7 @@
|
||||
export let sorting = { field: "startTime", order: "DESC" }
|
||||
export let matchedJobs = 0
|
||||
export let metrics = ccconfig.plot_list_selectedMetrics
|
||||
export let project
|
||||
export let projects = []
|
||||
export let isManager
|
||||
|
||||
let itemsPerPage = ccconfig.plot_list_jobsPerPage
|
||||
@@ -32,11 +32,15 @@
|
||||
let filter = []
|
||||
|
||||
//Setup default filter
|
||||
if (isManager == true && project != '') {
|
||||
filter.push({project: {eq: project}})
|
||||
} else if (isManager == true && project == '') {
|
||||
filter.push({project: {eq: "noProjectForManager"}})
|
||||
if (isManager == true && projects.length == 0) {
|
||||
filter.push({ project: {eq: "noProjectForManager"} })
|
||||
} else if (isManager == true && projects.length == 1) {
|
||||
filter.push({ project: {eq: projects[0]} })
|
||||
} else {
|
||||
filter.push({ multiProject: projects })
|
||||
}
|
||||
|
||||
|
||||
|
||||
const jobs = operationStore(`
|
||||
query($filter: [JobFilter!]!, $sorting: OrderByInput!, $paging: PageRequest! ){
|
||||
@@ -78,10 +82,12 @@
|
||||
}
|
||||
|
||||
// (Re-)Add Manager-Filter
|
||||
if (isManager == true && project != '') {
|
||||
filters.push({project: {eq: project}})
|
||||
} else if (isManager == true && project == '') {
|
||||
filters.push({project: {eq: "noProjectForManager"}})
|
||||
if (isManager == true && projects.length == 0) {
|
||||
filter.push({ project: {eq: "noProjectForManager"} })
|
||||
} else if (isManager == true && projects.length == 1) {
|
||||
filter.push({ project: {eq: projects[0]} })
|
||||
} else {
|
||||
filter.push({ multiProject: projects })
|
||||
}
|
||||
|
||||
$jobs.variables.filter = filters
|
||||
|
@@ -5,7 +5,7 @@ new Jobs({
|
||||
target: document.getElementById('svelte-app'),
|
||||
props: {
|
||||
filterPresets: filterPresets,
|
||||
project: project,
|
||||
projects: projects,
|
||||
isManager: isManager
|
||||
},
|
||||
context: new Map([
|
||||
|
@@ -6,7 +6,7 @@ new List({
|
||||
props: {
|
||||
filterPresets: filterPresets,
|
||||
type: listType,
|
||||
project: project,
|
||||
projects: projects,
|
||||
isManager: isManager
|
||||
},
|
||||
context: new Map([
|
||||
|
@@ -16,9 +16,9 @@
|
||||
<script>
|
||||
const header = {
|
||||
"username": "{{ .User.Username }}",
|
||||
"project": "{{ .User.Project }}",
|
||||
"authlevel": {{ .User.AuthLevel }},
|
||||
"clusters": {{ .Clusters }},
|
||||
"projects": {{ .User.Projects }},
|
||||
"authlevel": {{ .User.AuthLevel }},
|
||||
"clusters": {{ .Clusters }},
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<script>
|
||||
const filterPresets = {{ .FilterPresets }};
|
||||
const clusterCockpitConfig = {{ .Config }};
|
||||
const project = {{ .User.Project }};
|
||||
const projects = {{ .User.Projects }};
|
||||
const isManager = {{ eq .User.AuthLevel 3 }};
|
||||
</script>
|
||||
<script src='/build/jobs.js'></script>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
const listType = {{ .Infos.listType }};
|
||||
const filterPresets = {{ .FilterPresets }};
|
||||
const clusterCockpitConfig = {{ .Config }};
|
||||
const project = {{ .User.Project }};
|
||||
const projects = {{ .User.Projects }};
|
||||
const isManager = {{ eq .User.AuthLevel 3 }};
|
||||
</script>
|
||||
<script src='/build/list.js'></script>
|
||||
|
12
web/web.go
12
web/web.go
@@ -54,14 +54,14 @@ func init() {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Username string // Username of the currently logged in user
|
||||
Project string // Project of the user (relevant for managers only)
|
||||
AuthLevel int // Level of authorization
|
||||
Username string // Username of the currently logged in user
|
||||
Projects []string // Project(s) of the user (relevant for managers only)
|
||||
AuthLevel int // Level of authorization
|
||||
}
|
||||
|
||||
type Build struct {
|
||||
Version string
|
||||
Hash string
|
||||
Version string
|
||||
Hash string
|
||||
Buildtime string
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ type Page struct {
|
||||
Error string // For generic use (e.g. the exact error message on /login)
|
||||
Info string // For generic use (e.g. "Logout successfull" on /login)
|
||||
User User // Information about the currently logged in user
|
||||
Build Build // Latest information about the application
|
||||
Build Build // Latest information about the application
|
||||
Clusters []schema.ClusterConfig // List of all clusters for use in the Header
|
||||
FilterPresets map[string]interface{} // For pages with the Filter component, this can be used to set initial filters.
|
||||
Infos map[string]interface{} // For generic use (e.g. username for /monitoring/user/<id>, job id for /monitoring/job/<id>)
|
||||
|
Reference in New Issue
Block a user