mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
setting open access in admin dashboard
This commit is contained in:
parent
ed19501b6e
commit
d28f9e08bf
11
doc/api.oa3
11
doc/api.oa3
@ -123,6 +123,12 @@ paths:
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- name: update
|
||||
in: query
|
||||
description: if open access should be updated
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: success
|
||||
@ -3897,6 +3903,11 @@ components:
|
||||
type: string
|
||||
icePassword:
|
||||
type: string
|
||||
enableOpenAccess:
|
||||
type: boolean
|
||||
openAccessLimit:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
Seal:
|
||||
type: object
|
||||
|
@ -19,8 +19,8 @@ func GetAccountAvailable(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func getAvailableAccounts() (available int64, err error) {
|
||||
|
||||
open := getBoolConfigValue(CNFOpenAccess, false)
|
||||
limit := getNumConfigValue(CNFAccountLimit, 0)
|
||||
open := getBoolConfigValue(CNFEnableOpenAccess, false)
|
||||
limit := getNumConfigValue(CNFOpenAccessLimit, 0)
|
||||
|
||||
var count int64
|
||||
if err = store.DB.Model(&store.Account{}).Count(&count).Error; err != nil {
|
||||
|
@ -26,6 +26,8 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config.IceUrl = getStrConfigValue(CNFIceUrl, "")
|
||||
config.IceUsername = getStrConfigValue(CNFIceUsername, "")
|
||||
config.IcePassword = getStrConfigValue(CNFIcePassword, "")
|
||||
config.EnableOpenAccess = getBoolConfigValue(CNFEnableOpenAccess, false);
|
||||
config.OpenAccessLimit = getNumConfigValue(CNFOpenAccessLimit, 0);
|
||||
|
||||
WriteResponse(w, config)
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// update open access
|
||||
updateAccess := r.FormValue("update") == "open"
|
||||
|
||||
// parse node config
|
||||
var config NodeConfig
|
||||
if err := ParseRequest(r, w, &config); err != nil {
|
||||
@ -114,6 +117,24 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
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
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -9,11 +9,11 @@ import (
|
||||
//CNFPushSupported for allowing push notifications
|
||||
const CNFPushSupported = "push_notifications"
|
||||
|
||||
//CNFOpenAccess for allowing for public account creation
|
||||
const CNFOpenAccess = "open_access"
|
||||
//CNFEnableOpenAccess for allowing for public account creation
|
||||
const CNFEnableOpenAccess = "open_access"
|
||||
|
||||
//CNFAccountLimit for limiting number of accounts for public creation
|
||||
const CNFAccountLimit = "account_limit"
|
||||
//CNFOpenAccessLimit for limiting number of accounts for public creation
|
||||
const CNFOpenAccessLimit = "account_limit"
|
||||
|
||||
//CNFConfigured set when admin token has been set
|
||||
const CNFConfigured = "configured"
|
||||
|
@ -371,6 +371,10 @@ type NodeConfig struct {
|
||||
AccountStorage int64 `json:"accountStorage"`
|
||||
|
||||
PushSupported bool `json:"pushSupported"`
|
||||
|
||||
EnableOpenAccess bool `json:"enableOpenAccess,omitempty"`
|
||||
|
||||
OpenAccessLimit int64 `json:"openAccessLimit,omitempty"`
|
||||
}
|
||||
|
||||
//Profile public attributes of account
|
||||
|
@ -2,7 +2,7 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setNodeConfig(token, 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);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 { useDashboard } from './useDashboard.hook';
|
||||
import { AccountItem } from './accountItem/AccountItem';
|
||||
@ -122,6 +122,17 @@ export function Dashboard() {
|
||||
<Select.Option value="RSA4096">RSA 4096</Select.Option>
|
||||
</Select>
|
||||
</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>Enable Push Notification: </div>
|
||||
<Switch onChange={(e) => actions.setPushSupported(e)} size="small"
|
||||
|
@ -92,6 +92,10 @@ export const SettingsLayout = styled(Space)`
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.minHeight {
|
||||
min-height: 32px;
|
||||
}
|
||||
|
||||
.field {
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
|
@ -21,6 +21,8 @@ export function useDashboard() {
|
||||
iceUrl: null,
|
||||
iceUsername: null,
|
||||
icePassword: null,
|
||||
enableOpenAccess: null,
|
||||
openAccessLimit: null,
|
||||
|
||||
configError: false,
|
||||
accountsError: false,
|
||||
@ -103,6 +105,12 @@ export function useDashboard() {
|
||||
setIcePassword: (icePassword) => {
|
||||
updateState({ icePassword });
|
||||
},
|
||||
setEnableOpenAccess: (enableOpenAccess) => {
|
||||
updateState({ enableOpenAccess });
|
||||
},
|
||||
setOpenAccessLimit: (openAccessLimit) => {
|
||||
updateState({ openAccessLimit });
|
||||
},
|
||||
setShowSettings: (value) => {
|
||||
updateState({ showSettings: value });
|
||||
},
|
||||
@ -117,9 +125,9 @@ export function useDashboard() {
|
||||
if (!state.busy) {
|
||||
updateState({ busy: true });
|
||||
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 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);
|
||||
updateState({ busy: false, showSettings: false });
|
||||
}
|
||||
@ -135,9 +143,9 @@ export function useDashboard() {
|
||||
const syncConfig = async () => {
|
||||
try {
|
||||
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);
|
||||
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) {
|
||||
console.log(err);
|
||||
|
Loading…
Reference in New Issue
Block a user