setting open access in admin dashboard

This commit is contained in:
Roland Osborne 2023-07-17 22:39:38 -07:00
parent ed19501b6e
commit d28f9e08bf
10 changed files with 73 additions and 12 deletions

View File

@ -123,6 +123,12 @@ paths:
required: true required: true
schema: schema:
type: string type: string
- name: update
in: query
description: if open access should be updated
required: false
schema:
type: string
responses: responses:
'200': '200':
description: success description: success
@ -3897,6 +3903,11 @@ components:
type: string type: string
icePassword: icePassword:
type: string type: string
enableOpenAccess:
type: boolean
openAccessLimit:
type: integer
format: int64
Seal: Seal:
type: object type: object

View File

@ -19,8 +19,8 @@ func GetAccountAvailable(w http.ResponseWriter, r *http.Request) {
func getAvailableAccounts() (available int64, err error) { func getAvailableAccounts() (available int64, err error) {
open := getBoolConfigValue(CNFOpenAccess, false) open := getBoolConfigValue(CNFEnableOpenAccess, false)
limit := getNumConfigValue(CNFAccountLimit, 0) limit := getNumConfigValue(CNFOpenAccessLimit, 0)
var count int64 var count int64
if err = store.DB.Model(&store.Account{}).Count(&count).Error; err != nil { if err = store.DB.Model(&store.Account{}).Count(&count).Error; err != nil {

View File

@ -26,6 +26,8 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) {
config.IceUrl = getStrConfigValue(CNFIceUrl, "") config.IceUrl = getStrConfigValue(CNFIceUrl, "")
config.IceUsername = getStrConfigValue(CNFIceUsername, "") config.IceUsername = getStrConfigValue(CNFIceUsername, "")
config.IcePassword = getStrConfigValue(CNFIcePassword, "") config.IcePassword = getStrConfigValue(CNFIcePassword, "")
config.EnableOpenAccess = getBoolConfigValue(CNFEnableOpenAccess, false);
config.OpenAccessLimit = getNumConfigValue(CNFOpenAccessLimit, 0);
WriteResponse(w, config) WriteResponse(w, config)
} }

View File

@ -16,6 +16,9 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
return return
} }
// update open access
updateAccess := r.FormValue("update") == "open"
// parse node config // parse node config
var config NodeConfig var config NodeConfig
if err := ParseRequest(r, w, &config); err != nil { if err := ParseRequest(r, w, &config); err != nil {
@ -114,6 +117,24 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
return res return res
} }
if updateAccess {
// upsert enable open access
if res := tx.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "config_id"}},
DoUpdates: clause.AssignmentColumns([]string{"bool_value"}),
}).Create(&store.Config{ConfigID: CNFEnableOpenAccess, BoolValue: config.EnableOpenAccess}).Error; res != nil {
return res
}
// upsert open access limit
if res := tx.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "config_id"}},
DoUpdates: clause.AssignmentColumns([]string{"num_value"}),
}).Create(&store.Config{ConfigID: CNFOpenAccessLimit, NumValue: config.OpenAccessLimit}).Error; res != nil {
return res
}
}
return nil return nil
}) })
if err != nil { if err != nil {

View File

@ -9,11 +9,11 @@ import (
//CNFPushSupported for allowing push notifications //CNFPushSupported for allowing push notifications
const CNFPushSupported = "push_notifications" const CNFPushSupported = "push_notifications"
//CNFOpenAccess for allowing for public account creation //CNFEnableOpenAccess for allowing for public account creation
const CNFOpenAccess = "open_access" const CNFEnableOpenAccess = "open_access"
//CNFAccountLimit for limiting number of accounts for public creation //CNFOpenAccessLimit for limiting number of accounts for public creation
const CNFAccountLimit = "account_limit" const CNFOpenAccessLimit = "account_limit"
//CNFConfigured set when admin token has been set //CNFConfigured set when admin token has been set
const CNFConfigured = "configured" const CNFConfigured = "configured"

View File

@ -371,6 +371,10 @@ type NodeConfig struct {
AccountStorage int64 `json:"accountStorage"` AccountStorage int64 `json:"accountStorage"`
PushSupported bool `json:"pushSupported"` PushSupported bool `json:"pushSupported"`
EnableOpenAccess bool `json:"enableOpenAccess,omitempty"`
OpenAccessLimit int64 `json:"openAccessLimit,omitempty"`
} }
//Profile public attributes of account //Profile public attributes of account

View File

@ -2,7 +2,7 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setNodeConfig(token, config) { export async function setNodeConfig(token, config) {
let body = JSON.stringify(config); let body = JSON.stringify(config);
let settings = await fetchWithTimeout(`/admin/config?token=${token}`, { method: 'PUT', body }); let settings = await fetchWithTimeout(`/admin/config?update=open&token=${token}`, { method: 'PUT', body });
checkResponse(settings); checkResponse(settings);
} }

View File

@ -1,5 +1,5 @@
import { AlertIcon, DashboardWrapper, SettingsButton, AddButton, SettingsLayout, CreateLayout } from './Dashboard.styled'; import { AlertIcon, DashboardWrapper, SettingsButton, AddButton, SettingsLayout, CreateLayout } from './Dashboard.styled';
import { Tooltip, Switch, Select, Button, Modal, Input, InputNumber, List } from 'antd'; import { Tooltip, Switch, Select, Button, Space, Modal, Input, InputNumber, List } from 'antd';
import { ExclamationCircleOutlined, SettingOutlined, CopyOutlined, UserAddOutlined, LogoutOutlined, ReloadOutlined } from '@ant-design/icons'; import { ExclamationCircleOutlined, SettingOutlined, CopyOutlined, UserAddOutlined, LogoutOutlined, ReloadOutlined } from '@ant-design/icons';
import { useDashboard } from './useDashboard.hook'; import { useDashboard } from './useDashboard.hook';
import { AccountItem } from './accountItem/AccountItem'; import { AccountItem } from './accountItem/AccountItem';
@ -122,6 +122,17 @@ export function Dashboard() {
<Select.Option value="RSA4096">RSA 4096</Select.Option> <Select.Option value="RSA4096">RSA 4096</Select.Option>
</Select> </Select>
</div> </div>
<div className="field">
<Space className="minHeight" size="middle">
<div>Open Access:</div>
<Switch onChange={(e) => actions.setEnableOpenAccess(e)} size="small"
defaultChecked={false} checked={state.enableOpenAccess} />
{ state.enableOpenAccess && (
<InputNumber defaultValue={0} onChange={(e) => actions.setOpenAccessLimit(e)}
placeholder="Account Limit" value={state.openAccessLimit} />
)}
</Space>
</div>
<div className="field"> <div className="field">
<div>Enable Push Notification:&nbsp;</div> <div>Enable Push Notification:&nbsp;</div>
<Switch onChange={(e) => actions.setPushSupported(e)} size="small" <Switch onChange={(e) => actions.setPushSupported(e)} size="small"

View File

@ -92,6 +92,10 @@ export const SettingsLayout = styled(Space)`
margin-top: 8px; margin-top: 8px;
} }
.minHeight {
min-height: 32px;
}
.field { .field {
white-space: nowrap; white-space: nowrap;
display: flex; display: flex;

View File

@ -21,6 +21,8 @@ export function useDashboard() {
iceUrl: null, iceUrl: null,
iceUsername: null, iceUsername: null,
icePassword: null, icePassword: null,
enableOpenAccess: null,
openAccessLimit: null,
configError: false, configError: false,
accountsError: false, accountsError: false,
@ -103,6 +105,12 @@ export function useDashboard() {
setIcePassword: (icePassword) => { setIcePassword: (icePassword) => {
updateState({ icePassword }); updateState({ icePassword });
}, },
setEnableOpenAccess: (enableOpenAccess) => {
updateState({ enableOpenAccess });
},
setOpenAccessLimit: (openAccessLimit) => {
updateState({ openAccessLimit });
},
setShowSettings: (value) => { setShowSettings: (value) => {
updateState({ showSettings: value }); updateState({ showSettings: value });
}, },
@ -117,9 +125,9 @@ export function useDashboard() {
if (!state.busy) { if (!state.busy) {
updateState({ busy: true }); updateState({ busy: true });
try { try {
const { domain, keyType, accountStorage, pushSupported, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword } = state; const { domain, keyType, accountStorage, pushSupported, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = state;
const storage = accountStorage * 1073741824; const storage = accountStorage * 1073741824;
const config = { domain, accountStorage: storage, keyType, enableImage, enableAudio, enableVideo, pushSupported, enableIce, iceUrl, iceUsername, icePassword }; const config = { domain, accountStorage: storage, keyType, enableImage, enableAudio, enableVideo, pushSupported, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit };
await setNodeConfig(app.state.adminToken, config); await setNodeConfig(app.state.adminToken, config);
updateState({ busy: false, showSettings: false }); updateState({ busy: false, showSettings: false });
} }
@ -135,9 +143,9 @@ export function useDashboard() {
const syncConfig = async () => { const syncConfig = async () => {
try { try {
const config = await getNodeConfig(app.state.adminToken); const config = await getNodeConfig(app.state.adminToken);
const { storage, domain, keyType, pushSupported, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword } = config; const { storage, domain, keyType, pushSupported, enableImage, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = config;
const accountStorage = Math.ceil(storage / 1073741824); const accountStorage = Math.ceil(storage / 1073741824);
updateState({ configError: false, domain, accountStorage, keyType, enableImage, enableAudio, enableVideo, pushSupported, enableIce, iceUrl, iceUsername, icePassword }); updateState({ configError: false, domain, accountStorage, keyType, enableImage, enableAudio, enableVideo, pushSupported, enableIce, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit });
} }
catch(err) { catch(err) {
console.log(err); console.log(err);