Skip to content

Commit

Permalink
Added admin tab on organization view (#2872)
Browse files Browse the repository at this point in the history
* Added admin tab on organization view
  • Loading branch information
Cheshiriks authored Dec 7, 2023
1 parent f9e84be commit 424b39f
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object CosvOrganizationType : OrganizationType {
override val listTab: Array<OrganizationMenuBar> = arrayOf(
OrganizationMenuBar.INFO,
OrganizationMenuBar.VULNERABILITIES,
OrganizationMenuBar.SETTINGS
OrganizationMenuBar.SETTINGS,
OrganizationMenuBar.ADMIN,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum class OrganizationMenuBar(private val title: String? = null) {
BENCHMARKS,
CONTESTS,
SETTINGS,
ADMIN,
;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import com.saveourtool.save.validation.FrontendRoutes
import org.w3c.fetch.Response
import react.*
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.input
import react.dom.html.ReactHTML.label
import react.router.useNavigate
import web.cssom.ClassName
import web.html.InputType

private val organizationGitCredentialsManageCard = manageGitCredentialsCardComponent()

Expand Down Expand Up @@ -140,53 +138,6 @@ private fun organizationSettingsMenu() = FC<OrganizationSettingsMenuProps> { pro
}
div {
className = ClassName("card card-body mt-0 p-0")
if (props.selfRole.isSuperAdmin()) {
div {
className = ClassName("d-sm-flex justify-content-center form-check pl-3 pr-3 pt-3")
div {
input {
className = ClassName("form-check-input")
type = InputType.checkbox
value = props.organization.canCreateContests.toString()
id = "canCreateContestsCheckbox"
checked = props.organization.canCreateContests
onChange = {
props.onCanCreateContestsChange(!props.organization.canCreateContests)
}
}
}
div {
label {
className = ClassName("form-check-label")
htmlFor = "canCreateContestsCheckbox"
+"Can create contests"
}
}
}

div {
className = ClassName("d-sm-flex justify-content-center form-check pl-3 pr-3 pt-3")
div {
input {
className = ClassName("form-check-input")
type = InputType.checkbox
value = props.organization.canBulkUpload.toString()
id = "canBulkUploadCosvFilesCheckbox"
checked = props.organization.canBulkUpload
onChange = {
props.onCanBulkUploadCosvFilesChange(!props.organization.canBulkUpload)
}
}
}
div {
label {
className = ClassName("form-check-label")
htmlFor = "canBulkUploadCosvFilesCheckbox"
+"Can bulk upload COSV files"
}
}
}
}
div {
className = ClassName("d-sm-flex align-items-center justify-content-center p-3")
actionButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ val organizationView: FC<OrganizationProps> = FC { props ->
setProjects(projectsList)
}
}
OrganizationMenuBar.ADMIN -> renderAdminTab {
this.organization = organization
this.onCanCreateContestsChange = { isCreateContests ->
setCanCreateContests(isCreateContests)
onCanCreateContestsChange()
}
this.onCanBulkUploadCosvFilesChange = { isCanBulkUpload ->
setCanBulkUpload(isCanBulkUpload)
onCanBulkUploadCosvFilesChange()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
@file:Suppress("FILE_NAME_MATCH_CLASS")

package com.saveourtool.save.frontend.common.components.views.organization

import com.saveourtool.save.entities.OrganizationDto
import react.FC
import react.Props
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.input
import react.dom.html.ReactHTML.label
import web.cssom.ClassName
import web.html.InputType

val renderAdminTab: FC<RenderAdminTabProps> = FC { props ->

div {
className = ClassName("row justify-content-center mb-2 text-gray-900")
div {
className = ClassName("col-4 mb-2 pl-0 pr-0 mr-2 ml-2")
div {
className = ClassName("text-xs text-center font-weight-bold text-primary text-uppercase mb-3")
+"Main settings"
}
div {
className = ClassName("card card-body mt-0 p-0")
div {
className = ClassName("d-sm-flex justify-content-center form-check pl-3 pr-3 pt-3")
div {
input {
className = ClassName("form-check-input")
type = InputType.checkbox
value = props.organization.canCreateContests.toString()
id = "canCreateContestsCheckbox"
checked = props.organization.canCreateContests
onChange = {
props.onCanCreateContestsChange(!props.organization.canCreateContests)
}
}
}
div {
label {
className = ClassName("form-check-label")
htmlFor = "canCreateContestsCheckbox"
+"Can create contests"
}
}
}

div {
className = ClassName("d-sm-flex justify-content-center form-check pl-3 pr-3 pt-3")
div {
input {
className = ClassName("form-check-input")
type = InputType.checkbox
value = props.organization.canBulkUpload.toString()
id = "canBulkUploadCosvFilesCheckbox"
checked = props.organization.canBulkUpload
onChange = {
props.onCanBulkUploadCosvFilesChange(!props.organization.canBulkUpload)
}
}
}
div {
label {
className = ClassName("form-check-label")
htmlFor = "canBulkUploadCosvFilesCheckbox"
+"Can bulk upload COSV files"
}
}
}
}
}
}
}

/**
* RenderInfoTab component props
*/
@Suppress("MISSING_KDOC_CLASS_ELEMENTS")
external interface RenderAdminTabProps : Props {
/**
* Organization
*/
var organization: OrganizationDto

/**
* Callback invoked in order to change canCreateContests flag
*/
var onCanCreateContestsChange: (Boolean) -> Unit

/**
* Callback invoked in order to change canBulkUpload flag
*/
var onCanBulkUploadCosvFilesChange: (Boolean) -> Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ internal val renderOrganizationMenuBar: FC<RenderOrganizationMenuBarProps> = FC
}

val listTabs = props.valuesOrganizationMenuBar.filter {
it != OrganizationMenuBar.SETTINGS || props.selfRole.isHigherOrEqualThan(Role.ADMIN)
// The Settings tab should only be seen by a person with the admin role or higher in this organization.
// The Admin tab is seen only by super-admin
(it != OrganizationMenuBar.SETTINGS || props.selfRole.isHigherOrEqualThan(Role.ADMIN)) &&
(it != OrganizationMenuBar.ADMIN || props.selfRole.isSuperAdmin())
}

div {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object SaveOrganizationType : OrganizationType {
OrganizationMenuBar.TOOLS,
OrganizationMenuBar.BENCHMARKS,
OrganizationMenuBar.CONTESTS,
OrganizationMenuBar.SETTINGS
OrganizationMenuBar.SETTINGS,
OrganizationMenuBar.ADMIN,
)
}

0 comments on commit 424b39f

Please sign in to comment.