From e1a1f00e12635a1830749594b916402cebd2d489 Mon Sep 17 00:00:00 2001 From: Ronan Date: Fri, 31 May 2024 19:42:44 +0200 Subject: [PATCH] can add shared address book rule in web consolle --- libs/state/src/database.rs | 74 ++++++++ libs/state/src/state.rs | 8 + libs/utils/src/types.rs | 13 ++ src/lib.rs | 70 +++++++ webconsole/package.json | 46 ++--- webconsole/src/api/apis/address-book-api.ts | 176 ++++++++++++++++++ .../src/api/models/ab-rule-add-request.ts | 46 +++++ .../src/api/models/ab-rule-delete-request.ts | 28 +++ webconsole/src/api/models/index.ts | 2 + webconsole/src/api/openapi.json | 106 +++++++++++ webconsole/src/components/AddRule.vue | 72 +++++++ webconsole/src/components/AddressBook.vue | 2 +- webconsole/src/components/GroupsCard.vue | 6 +- webconsole/src/components/Modal.vue | 4 +- webconsole/src/components/UsersCard.vue | 23 +-- webconsole/src/components/ViewRules.vue | 1 - webconsole/src/utilities/api.ts | 50 +++++ 17 files changed, 676 insertions(+), 51 deletions(-) create mode 100644 webconsole/src/api/models/ab-rule-add-request.ts create mode 100644 webconsole/src/api/models/ab-rule-delete-request.ts create mode 100644 webconsole/src/components/AddRule.vue create mode 100644 webconsole/src/utilities/api.ts diff --git a/libs/state/src/database.rs b/libs/state/src/database.rs index 96f8b06..2230f03 100644 --- a/libs/state/src/database.rs +++ b/libs/state/src/database.rs @@ -1394,4 +1394,78 @@ impl Database { } Some(ab_rules) } + + pub async fn delete_ab_rule(&self, rule: &str) -> Option<()> { + let mut conn = self.pool.acquire().await.unwrap(); + let rule_guid = Uuid::parse_str(rule); + if rule_guid.is_err() { + log::error!("delete_ab_rule error: {:?}", rule_guid); + return None; + } + let rule_guid = rule_guid.unwrap().as_bytes().to_vec(); + let res = sqlx::query!( + r#" + DELETE FROM ab_rule WHERE guid = ? + "#, + rule_guid + ) + .execute(&mut conn) + .await; + if res.is_err() { + log::error!("delete_ab_rule error: {:?}", res); + return None; + } + Some(()) + } + + pub async fn add_ab_rule(&self, rule: AbRule) -> Option<()> { + let mut conn = self.pool.acquire().await.unwrap(); + let rule_guid = Uuid::new_v4().as_bytes().to_vec(); + let ab_guid = Uuid::parse_str(&rule.guid); + if ab_guid.is_err() { + log::error!("add_ab_rule error: {:?}", ab_guid); + return None; + } + let ab_guid = ab_guid.unwrap().as_bytes().to_vec(); + let user_guid = if (rule.user.is_some()) { + let uuid = Uuid::parse_str(&rule.user.unwrap()); + if (uuid.is_err()){ + None + }else{ + Some(uuid.unwrap().as_bytes().to_vec()) + } + } else { + None + }; + + let group_guid = if (rule.group.is_some()) { + let uuid = Uuid::parse_str(&rule.group.unwrap()); + if (uuid.is_err()){ + None + }else{ + Some(uuid.unwrap().as_bytes().to_vec()) + } + } else { + None + }; + + let res = sqlx::query!( + r#" + INSERT OR IGNORE INTO ab_rule (guid, ab, user, grp, rule) + VALUES (?, ?, ?, ?, ?) + "#, + rule_guid, + ab_guid, + user_guid, + group_guid, + rule.rule + ) + .execute(&mut conn) + .await; + if res.is_err() { + log::error!("add_ab_rule error: {:?}", res); + return None; + } + Some(()) + } } diff --git a/libs/state/src/state.rs b/libs/state/src/state.rs index 1f663c4..2061a30 100644 --- a/libs/state/src/state.rs +++ b/libs/state/src/state.rs @@ -668,4 +668,12 @@ impl ApiState { pub async fn get_ab_rules(&self, offset:u32, page_size: u32, ab: &str) -> Option> { self.db.get_ab_rules(offset,page_size, ab).await } + + pub async fn delete_ab_rule(&self, rule: &str) -> Option<()> { + self.db.delete_ab_rule(rule).await + } + + pub async fn add_ab_rule(&self, rule: AbRule) -> Option<()> { + self.db.add_ab_rule(rule).await + } } diff --git a/libs/utils/src/types.rs b/libs/utils/src/types.rs index 9abd6d6..885caaa 100644 --- a/libs/utils/src/types.rs +++ b/libs/utils/src/types.rs @@ -733,4 +733,17 @@ pub struct AbRulesResponse { pub msg: String, pub total: u32, pub data: Vec, +} + +#[derive(Serialize, Deserialize, Clone, JsonSchema)] +pub struct AbRuleAddRequest { + pub guid: String, // address book guid + pub user: Option, // user=None and group=None means all users + pub group: Option, + pub rule: u32, +} + +#[derive(Serialize, Deserialize, Clone, JsonSchema)] +pub struct AbRuleDeleteRequest { + pub guid: String, // rule guid } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 87d3da7..8102a9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,6 +39,9 @@ use state::{self}; use ui; use utils::guid_into_uuid; use utils::AbProfile; +use utils::AbRule; +use utils::AbRuleAddRequest; +use utils::AbRuleDeleteRequest; use utils::AbRulesResponse; use utils::AbSharedAddRequest; use utils::{ @@ -146,6 +149,8 @@ pub async fn build_rocket(figment: Figment) -> Rocket { ab_shared_add, ab_settings, ab_rules, + ab_rule_add, + ab_rule_delete, software, software_version, webconsole_index, @@ -1739,6 +1744,71 @@ async fn ab_rules( Ok(Json(response)) } +/// # Add a Rule +/// +/// This function is an API endpoint that adds a new rule to a shared address book. +/// It is tagged with "address book" for OpenAPI documentation. +/// +/// ## Parameters +/// +/// - `request`: The request containing the details of the rule to be added. +/// +/// ## Returns +/// +/// If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully added.
+/// If the system is in maintenance mode, this function returns a `status::Unauthorized` error. +/// +/// ## Errors +/// +/// This function will return an error if the system is in maintenance mode. +#[openapi(tag = "address book")] +#[post("/api/ab/rule", format = "application/json", data = "")] +async fn ab_rule_add( + state: &State, + _user: AuthenticatedAdmin, + request: Json, +) -> Result> { + state.check_maintenance().await; + let rule = AbRule { + guid: request.0.guid, + user: request.0.user, + group: request.0.group, + rule: request.0.rule, + }; + state.add_ab_rule(rule).await; + Ok(ActionResponse::Empty) +} + +/// # Delete a Rule +/// +/// This function is an API endpoint that deletes a rule from a shared address book. +/// It is tagged with "address book" for OpenAPI documentation. +/// +/// ## Parameters +/// +/// - `request`: The request containing the GUID of the rule to be deleted. +/// +/// ## Returns +/// +/// If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully deleted.
+/// If the system is in maintenance mode, this function returns a `status::Unauthorized` error. +/// +/// ## Errors +/// +/// This function will return an error if the system is in maintenance mode. +#[openapi(tag = "address book")] +#[delete("/api/ab/rule", format = "application/json", data = "")] +async fn ab_rule_delete( + state: &State, + _user: AuthenticatedAdmin, + request: Json, +) -> Result> { + state.check_maintenance().await; + let rule = request.0.guid; + state.delete_ab_rule(rule.as_str()).await; + Ok(ActionResponse::Empty) +} + async fn webconsole_index_multi() -> Redirect { Redirect::to(uri!("/ui/")) } diff --git a/webconsole/package.json b/webconsole/package.json index 5070ec0..e936674 100644 --- a/webconsole/package.json +++ b/webconsole/package.json @@ -4,43 +4,43 @@ "version": "1.1.99-29", "type": "module", "scripts": { - "preview": "vite preview", - "build": "vite build && gulp licenses", "devserver": "npx nodemon -V -w ./src -e js,vue,ts,css,html --exec 'npm run build && node devserver.js'", "create-cert": "openssl req -x509 -newkey rsa:4096 -keyout localhost.key -out localhost.pem -sha256 -nodes -days 365", - "dev": "vite" + "build": "vite build && gulp licenses", + "dev": "vite", + "preview": "vite preview" }, "dependencies": { - "@pqina/flip": "^1.8.3", - "jdenticon": "^3.3.0", "vue-router": "^4.3.2", - "@heroicons/vue": "^2.1.3", - "vue": "^3.4.27", "pinia": "^2.1.7", - "@headlessui/vue": "^1.7.22", - "axios": "^1.7.2" + "vue": "^3.4.27", + "jdenticon": "^3.3.0", + "axios": "^1.7.2", + "@pqina/flip": "^1.8.3", + "@heroicons/vue": "^2.1.3", + "@headlessui/vue": "^1.7.22" }, "devDependencies": { "nodemon": "^3.1.0", - "glob": "10.4.1", - "autoprefixer": "^10.4.19", "gulp-append-prepend": "^1.0.9", - "postcss": "^8.4.38", - "express": "^4.19.2", - "sass": "^1.77.2", - "@tailwindcss/typography": "^0.5.13", - "ts-node": "^10.9.2", - "@tailwindcss/forms": "^0.5.7", + "vite-plugin-static-copy": "^1.0.5", + "typescript": "^5.4.5", + "@fullhuman/postcss-purgecss": "^6.0.0", "tailwindcss": "^3.4.3", "postcss-purgefonts": "^1.0.2", - "@fullhuman/postcss-purgecss": "^6.0.0", - "@vitejs/plugin-vue": "^5.0.4", - "typescript": "^5.4.5", - "vite": "^5.2.11", - "vite-plugin-static-copy": "^1.0.5", + "express": "^4.19.2", + "npm-check-updates": "^16.14.20", + "autoprefixer": "^10.4.19", + "@tailwindcss/forms": "^0.5.7", "@types/glob": "^8.1.0", "gulp-if": "^3.0.0", + "@vitejs/plugin-vue": "^5.0.4", + "glob": "10.4.1", + "sass": "^1.77.2", + "@tailwindcss/typography": "^0.5.13", + "postcss": "^8.4.38", + "vite": "^5.2.11", "gulp": "^5.0.0", - "npm-check-updates": "^16.14.20" + "ts-node": "^10.9.2" } } \ No newline at end of file diff --git a/webconsole/src/api/apis/address-book-api.ts b/webconsole/src/api/apis/address-book-api.ts index f3dfea3..0a530b7 100644 --- a/webconsole/src/api/apis/address-book-api.ts +++ b/webconsole/src/api/apis/address-book-api.ts @@ -21,6 +21,8 @@ import { AbGetResponse } from '../models'; import { AbPeer } from '../models'; import { AbPeersResponse } from '../models'; import { AbPersonal } from '../models'; +import { AbRuleAddRequest } from '../models'; +import { AbRuleDeleteRequest } from '../models'; import { AbRulesResponse } from '../models'; import { AbSettingsResponse } from '../models'; import { AbSharedAddRequest } from '../models'; @@ -360,6 +362,110 @@ export const AddressBookApiAxiosParamCreator = function (configuration?: Configu options: localVarRequestOptions, }; }, + /** + * This function is an API endpoint that adds a new rule to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the details of the rule to be added. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully added.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Add a Rule + * @param {AbRuleAddRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + abRuleAdd: async (body: AbRuleAddRequest, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('body','Required parameter body was null or undefined when calling abRuleAdd.'); + } + const localVarPath = `/api/ab/rule`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, 'https://example.com'); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication authorization_admin required + // http bearer authentication required + if (configuration && configuration.accessToken) { + const accessToken = typeof configuration.accessToken === 'function' + ? await configuration.accessToken() + : await configuration.accessToken; + localVarHeaderParameter["Authorization"] = "Bearer " + accessToken; + } + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + const query = new URLSearchParams(localVarUrlObj.search); + for (const key in localVarQueryParameter) { + query.set(key, localVarQueryParameter[key]); + } + for (const key in options.params) { + query.set(key, options.params[key]); + } + localVarUrlObj.search = (new URLSearchParams(query)).toString(); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; + localVarRequestOptions.data = needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || ""); + + return { + url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash, + options: localVarRequestOptions, + }; + }, + /** + * This function is an API endpoint that deletes a rule from a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the GUID of the rule to be deleted. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully deleted.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Delete a Rule + * @param {AbRuleDeleteRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + abRuleDelete: async (body: AbRuleDeleteRequest, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('body','Required parameter body was null or undefined when calling abRuleDelete.'); + } + const localVarPath = `/api/ab/rule`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, 'https://example.com'); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + const localVarRequestOptions :AxiosRequestConfig = { method: 'DELETE', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication authorization_admin required + // http bearer authentication required + if (configuration && configuration.accessToken) { + const accessToken = typeof configuration.accessToken === 'function' + ? await configuration.accessToken() + : await configuration.accessToken; + localVarHeaderParameter["Authorization"] = "Bearer " + accessToken; + } + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + const query = new URLSearchParams(localVarUrlObj.search); + for (const key in localVarQueryParameter) { + query.set(key, localVarQueryParameter[key]); + } + for (const key in options.params) { + query.set(key, options.params[key]); + } + localVarUrlObj.search = (new URLSearchParams(query)).toString(); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; + localVarRequestOptions.data = needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || ""); + + return { + url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash, + options: localVarRequestOptions, + }; + }, /** * This function is an API endpoint that lists the rules attached to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `current`: The current page number for pagination. This parameter is currently unused. - `pageSize`: The number of items per page for pagination. This parameter is currently unused. - `ab`: The identifier of the shared address book. ## Returns If successful, this function returns a `Json` object containing the rules for the address book.
If the address book does not exist or the user is not authorized to access it, this function returns a `status::Unauthorized` error.
## Errors This function will return an error if the system is in maintenance mode, or if the address book does not exist or the user is not authorized to access it. * @summary List the rules @@ -940,6 +1046,34 @@ export const AddressBookApiFp = function(configuration?: Configuration) { return axios.request(axiosRequestArgs); }; }, + /** + * This function is an API endpoint that adds a new rule to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the details of the rule to be added. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully added.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Add a Rule + * @param {AbRuleAddRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async abRuleAdd(body: AbRuleAddRequest, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise>> { + const localVarAxiosArgs = await AddressBookApiAxiosParamCreator(configuration).abRuleAdd(body, options); + return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; + return axios.request(axiosRequestArgs); + }; + }, + /** + * This function is an API endpoint that deletes a rule from a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the GUID of the rule to be deleted. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully deleted.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Delete a Rule + * @param {AbRuleDeleteRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async abRuleDelete(body: AbRuleDeleteRequest, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise>> { + const localVarAxiosArgs = await AddressBookApiAxiosParamCreator(configuration).abRuleDelete(body, options); + return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; + return axios.request(axiosRequestArgs); + }; + }, /** * This function is an API endpoint that lists the rules attached to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `current`: The current page number for pagination. This parameter is currently unused. - `pageSize`: The number of items per page for pagination. This parameter is currently unused. - `ab`: The identifier of the shared address book. ## Returns If successful, this function returns a `Json` object containing the rules for the address book.
If the address book does not exist or the user is not authorized to access it, this function returns a `status::Unauthorized` error.
## Errors This function will return an error if the system is in maintenance mode, or if the address book does not exist or the user is not authorized to access it. * @summary List the rules @@ -1137,6 +1271,26 @@ export const AddressBookApiFactory = function (configuration?: Configuration, ba async abPost(options?: AxiosRequestConfig): Promise> { return AddressBookApiFp(configuration).abPost(options).then((request) => request(axios, basePath)); }, + /** + * This function is an API endpoint that adds a new rule to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the details of the rule to be added. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully added.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Add a Rule + * @param {AbRuleAddRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async abRuleAdd(body: AbRuleAddRequest, options?: AxiosRequestConfig): Promise> { + return AddressBookApiFp(configuration).abRuleAdd(body, options).then((request) => request(axios, basePath)); + }, + /** + * This function is an API endpoint that deletes a rule from a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the GUID of the rule to be deleted. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully deleted.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Delete a Rule + * @param {AbRuleDeleteRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async abRuleDelete(body: AbRuleDeleteRequest, options?: AxiosRequestConfig): Promise> { + return AddressBookApiFp(configuration).abRuleDelete(body, options).then((request) => request(axios, basePath)); + }, /** * This function is an API endpoint that lists the rules attached to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `current`: The current page number for pagination. This parameter is currently unused. - `pageSize`: The number of items per page for pagination. This parameter is currently unused. - `ab`: The identifier of the shared address book. ## Returns If successful, this function returns a `Json` object containing the rules for the address book.
If the address book does not exist or the user is not authorized to access it, this function returns a `status::Unauthorized` error.
## Errors This function will return an error if the system is in maintenance mode, or if the address book does not exist or the user is not authorized to access it. * @summary List the rules @@ -1305,6 +1459,28 @@ export class AddressBookApi extends BaseAPI { public async abPost(options?: AxiosRequestConfig) : Promise> { return AddressBookApiFp(this.configuration).abPost(options).then((request) => request(this.axios, this.basePath)); } + /** + * This function is an API endpoint that adds a new rule to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the details of the rule to be added. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully added.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Add a Rule + * @param {AbRuleAddRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressBookApi + */ + public async abRuleAdd(body: AbRuleAddRequest, options?: AxiosRequestConfig) : Promise> { + return AddressBookApiFp(this.configuration).abRuleAdd(body, options).then((request) => request(this.axios, this.basePath)); + } + /** + * This function is an API endpoint that deletes a rule from a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `request`: The request containing the GUID of the rule to be deleted. ## Returns If successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully deleted.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error. ## Errors This function will return an error if the system is in maintenance mode. + * @summary Delete a Rule + * @param {AbRuleDeleteRequest} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressBookApi + */ + public async abRuleDelete(body: AbRuleDeleteRequest, options?: AxiosRequestConfig) : Promise> { + return AddressBookApiFp(this.configuration).abRuleDelete(body, options).then((request) => request(this.axios, this.basePath)); + } /** * This function is an API endpoint that lists the rules attached to a shared address book. It is tagged with \"address book\" for OpenAPI documentation. ## Parameters - `current`: The current page number for pagination. This parameter is currently unused. - `pageSize`: The number of items per page for pagination. This parameter is currently unused. - `ab`: The identifier of the shared address book. ## Returns If successful, this function returns a `Json` object containing the rules for the address book.
If the address book does not exist or the user is not authorized to access it, this function returns a `status::Unauthorized` error.
## Errors This function will return an error if the system is in maintenance mode, or if the address book does not exist or the user is not authorized to access it. * @summary List the rules diff --git a/webconsole/src/api/models/ab-rule-add-request.ts b/webconsole/src/api/models/ab-rule-add-request.ts new file mode 100644 index 0000000..1f78ce0 --- /dev/null +++ b/webconsole/src/api/models/ab-rule-add-request.ts @@ -0,0 +1,46 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * sctgdesk-api-server + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: 0.1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + /** + * + * + * @export + * @interface AbRuleAddRequest + */ +export interface AbRuleAddRequest { + + /** + * @type {string} + * @memberof AbRuleAddRequest + */ + guid: string; + + /** + * @type {string} + * @memberof AbRuleAddRequest + */ + user?: string | null; + + /** + * @type {string} + * @memberof AbRuleAddRequest + */ + group?: string | null; + + /** + * @type {number} + * @memberof AbRuleAddRequest + */ + rule: number; +} diff --git a/webconsole/src/api/models/ab-rule-delete-request.ts b/webconsole/src/api/models/ab-rule-delete-request.ts new file mode 100644 index 0000000..acf952a --- /dev/null +++ b/webconsole/src/api/models/ab-rule-delete-request.ts @@ -0,0 +1,28 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * sctgdesk-api-server + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: 0.1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + /** + * + * + * @export + * @interface AbRuleDeleteRequest + */ +export interface AbRuleDeleteRequest { + + /** + * @type {string} + * @memberof AbRuleDeleteRequest + */ + guid: string; +} diff --git a/webconsole/src/api/models/index.ts b/webconsole/src/api/models/index.ts index cf86c22..6c3eb9e 100644 --- a/webconsole/src/api/models/index.ts +++ b/webconsole/src/api/models/index.ts @@ -5,6 +5,8 @@ export * from './ab-personal'; export * from './ab-profile'; export * from './ab-request'; export * from './ab-rule'; +export * from './ab-rule-add-request'; +export * from './ab-rule-delete-request'; export * from './ab-rules-response'; export * from './ab-settings-response'; export * from './ab-shared-add-request'; diff --git a/webconsole/src/api/openapi.json b/webconsole/src/api/openapi.json index 9e26dbc..1894a68 100644 --- a/webconsole/src/api/openapi.json +++ b/webconsole/src/api/openapi.json @@ -1559,6 +1559,76 @@ ] } }, + "/api/ab/rule": { + "post": { + "tags": [ + "address book" + ], + "summary": "Add a Rule", + "description": "This function is an API endpoint that adds a new rule to a shared address book. It is tagged with \"address book\" for OpenAPI documentation.\n\n## Parameters\n\n- `request`: The request containing the details of the rule to be added.\n\n## Returns\n\nIf successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully added.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error.\n\n## Errors\n\nThis function will return an error if the system is in maintenance mode.", + "operationId": "ab_rule_add", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AbRuleAddRequest" + } + } + }, + "required": true + }, + "responses": { + "422": { + "description": "# [422 Unprocessable Entity](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422)\nThis response is given when you request body is not correctly formatted. " + }, + "200": { + "description": "\\\n # [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200) \n This response is given when the request is successful. \n The body is empty if there is no error, \n The body contains a json object with the error {\"error\":\"Error message\"} \n " + }, + "401": { + "description": "" + } + }, + "security": [ + { + "authorization_admin": [] + } + ] + }, + "delete": { + "tags": [ + "address book" + ], + "summary": "Delete a Rule", + "description": "This function is an API endpoint that deletes a rule from a shared address book. It is tagged with \"address book\" for OpenAPI documentation.\n\n## Parameters\n\n- `request`: The request containing the GUID of the rule to be deleted.\n\n## Returns\n\nIf successful, this function returns an `ActionResponse::Empty` indicating that the rule was successfully deleted.
If the system is in maintenance mode, this function returns a `status::Unauthorized` error.\n\n## Errors\n\nThis function will return an error if the system is in maintenance mode.", + "operationId": "ab_rule_delete", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AbRuleDeleteRequest" + } + } + }, + "required": true + }, + "responses": { + "422": { + "description": "# [422 Unprocessable Entity](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422)\nThis response is given when you request body is not correctly formatted. " + }, + "200": { + "description": "\\\n # [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200) \n This response is given when the request is successful. \n The body is empty if there is no error, \n The body contains a json object with the error {\"error\":\"Error message\"} \n " + }, + "401": { + "description": "" + } + }, + "security": [ + { + "authorization_admin": [] + } + ] + } + }, "/api/software/client-download-link/{key}": { "get": { "tags": [ @@ -2709,6 +2779,42 @@ } } }, + "AbRuleAddRequest": { + "type": "object", + "required": [ + "guid", + "rule" + ], + "properties": { + "guid": { + "type": "string" + }, + "user": { + "type": "string", + "nullable": true + }, + "group": { + "type": "string", + "nullable": true + }, + "rule": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + }, + "AbRuleDeleteRequest": { + "type": "object", + "required": [ + "guid" + ], + "properties": { + "guid": { + "type": "string" + } + } + }, "SoftwareResponse": { "type": "object", "required": [ diff --git a/webconsole/src/components/AddRule.vue b/webconsole/src/components/AddRule.vue new file mode 100644 index 0000000..ebd823f --- /dev/null +++ b/webconsole/src/components/AddRule.vue @@ -0,0 +1,72 @@ + + \ No newline at end of file diff --git a/webconsole/src/components/AddressBook.vue b/webconsole/src/components/AddressBook.vue index 4c2379c..956ec10 100644 --- a/webconsole/src/components/AddressBook.vue +++ b/webconsole/src/components/AddressBook.vue @@ -123,7 +123,7 @@ This website use: - +