mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2026-02-08 23:30:43 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c30ad145c | ||
|
|
06b0a8e873 | ||
|
|
b7de2ccadd | ||
|
|
b52c5cfca1 | ||
|
|
fe910c37cf | ||
|
|
337ef330eb | ||
|
|
ffa47177aa | ||
|
|
46a76853c3 | ||
|
|
2cd7dfb2b3 | ||
|
|
fee2808bca | ||
|
|
49e5eb186a | ||
|
|
dee2865466 | ||
|
|
eb340b2615 | ||
|
|
e714549a95 | ||
|
|
a1367bcd3d | ||
|
|
642351dafd | ||
|
|
90b9b5adba | ||
|
|
5bf4bbe45f | ||
|
|
036f928fa3 | ||
|
|
94e7b31fb6 |
26
.dockerignore
Normal file
26
.dockerignore
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# Ignore Docker Compose configuration files
|
||||||
|
docker-compose.yaml
|
||||||
|
|
||||||
|
# Ignore development Dockerfile
|
||||||
|
Dockerfile.dev
|
||||||
|
|
||||||
|
# Ignore the data directory
|
||||||
|
data/
|
||||||
|
|
||||||
|
# Ignore version control system directories
|
||||||
|
.git/
|
||||||
|
|
||||||
|
# Ignore log and temporary files
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
# Ignore editor/IDE configuration files
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Ignore binaries and build cache
|
||||||
|
release/
|
||||||
|
bin/
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
72
Dockerfile.dev
Normal file
72
Dockerfile.dev
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# Use build arguments for Go version and architecture
|
||||||
|
ARG GO_VERSION=1.22
|
||||||
|
ARG BUILDARCH=amd64
|
||||||
|
|
||||||
|
# Stage 1: Builder Stage
|
||||||
|
# FROM golang:${GO_VERSION}-alpine AS builder
|
||||||
|
FROM crazymax/xgo:${GO_VERSION} AS builder
|
||||||
|
|
||||||
|
# Set up working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Step 1: Copy the source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Step 2: Download dependencies
|
||||||
|
RUN go mod tidy && go mod download
|
||||||
|
|
||||||
|
|
||||||
|
# Step 3: Install swag and Run the build script
|
||||||
|
RUN go install github.com/swaggo/swag/cmd/swag@latest && \
|
||||||
|
swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin && \
|
||||||
|
swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
||||||
|
|
||||||
|
# Build the Go application with CGO enabled and specified ldflags
|
||||||
|
RUN CGO_ENABLED=1 GOOS=linux go build -a \
|
||||||
|
-ldflags "-s -w --extldflags '-static -fpic'" \
|
||||||
|
-installsuffix cgo -o release/apimain cmd/apimain.go
|
||||||
|
|
||||||
|
# Stage 2: Frontend Build Stage (builder2)
|
||||||
|
FROM node:18-alpine AS builder2
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /frontend
|
||||||
|
|
||||||
|
RUN apk update && apk add git --no-cache
|
||||||
|
|
||||||
|
# Clone the frontend repository
|
||||||
|
RUN git clone https://github.com/lejianwen/rustdesk-api-web .
|
||||||
|
|
||||||
|
# Install npm dependencies and build the frontend
|
||||||
|
RUN npm install && npm run build
|
||||||
|
|
||||||
|
# Stage 2: Final Image
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
# Set up working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install necessary runtime dependencies
|
||||||
|
RUN apk add --no-cache tzdata file
|
||||||
|
|
||||||
|
# Copy the built application and resources from the builder stage
|
||||||
|
COPY --from=builder /app/release /app/
|
||||||
|
COPY --from=builder /app/conf /app/conf/
|
||||||
|
COPY --from=builder /app/resources /app/resources/
|
||||||
|
COPY --from=builder /app/docs /app/docs/
|
||||||
|
# Copy frontend build from builder2 stage
|
||||||
|
COPY --from=builder2 /frontend/dist/ /app/resources/admin/
|
||||||
|
|
||||||
|
# Ensure the binary is correctly built and linked
|
||||||
|
RUN file /app/apimain && \
|
||||||
|
mkdir -p /app/data && \
|
||||||
|
mkdir -p /app/runtime
|
||||||
|
|
||||||
|
# Set up a volume for persistent data
|
||||||
|
VOLUME /app/data
|
||||||
|
|
||||||
|
# Expose the necessary port
|
||||||
|
EXPOSE 21114
|
||||||
|
|
||||||
|
# Define the command to run the application
|
||||||
|
CMD ["./apimain"]
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
|
|
||||||
3. 分组可以自定义,方便管理,暂时支持两种类型: `共享组` 和 `普通组`
|
3. 分组可以自定义,方便管理,暂时支持两种类型: `共享组` 和 `普通组`
|
||||||

|

|
||||||
4. You can directly launch the client, or open the web client for convenient use; you can also share it with guests, allowing them to remotely access the device through the web client.
|
4. 可以直接打开webclient,方便使用;也可以分享给游客,游客可以直接通过webclient远程到设备
|
||||||
|
|
||||||

|

|
||||||
5. Oauth,暂时只支持了`Github`和`Google`, 需要创建一个`OAuth App`,然后配置到后台
|
5. Oauth,暂时只支持了`Github`和`Google`, 需要创建一个`OAuth App`,然后配置到后台
|
||||||
|
|||||||
38
build.sh
Normal file → Executable file
38
build.sh
Normal file → Executable file
@@ -1,16 +1,46 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
rm release -rf
|
set -e
|
||||||
|
# Automatically get the current environment's GOARCH; if not defined, use the detected system architecture
|
||||||
|
GOARCH=${GOARCH:-$(go env GOARCH)}
|
||||||
|
DOCS="true"
|
||||||
|
# Safely remove the old release directory
|
||||||
|
rm -rf release
|
||||||
|
|
||||||
|
# Set Go environment variables
|
||||||
go env -w GO111MODULE=on
|
go env -w GO111MODULE=on
|
||||||
go env -w GOPROXY=https://goproxy.cn,direct
|
go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
go env -w CGO_ENABLED=1
|
go env -w CGO_ENABLED=1
|
||||||
go env -w GOOS=linux
|
go env -w GOOS=linux
|
||||||
go env -w GOARCH=amd64
|
go env -w GOARCH=${GOARCH}
|
||||||
swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
|
|
||||||
swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
|
||||||
|
# Generate Swagger documentation if DOCS is not empty
|
||||||
|
if [ -n "${DOCS}" ]; then
|
||||||
|
# Check if swag is installed
|
||||||
|
if ! command -v swag &> /dev/null; then
|
||||||
|
echo "swag command not found. Please install it using:"
|
||||||
|
echo "go install github.com/swaggo/swag/cmd/swag@latest"
|
||||||
|
echo "Skipping Swagger documentation generation due to missing swag tool."
|
||||||
|
else
|
||||||
|
echo "Generating Swagger documentation..."
|
||||||
|
swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
|
||||||
|
swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Skipping Swagger documentation generation due to DOCS is empty."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Compile the Go code and output it to the release directory
|
||||||
go build -o release/apimain cmd/apimain.go
|
go build -o release/apimain cmd/apimain.go
|
||||||
|
|
||||||
|
# Copy resource files to the release directory
|
||||||
cp -ar resources release/
|
cp -ar resources release/
|
||||||
cp -ar docs release/
|
cp -ar docs release/
|
||||||
cp -ar conf release/
|
cp -ar conf release/
|
||||||
|
|
||||||
|
# Create necessary directory structures
|
||||||
mkdir -p release/data
|
mkdir -p release/data
|
||||||
mkdir -p release/runtime
|
mkdir -p release/runtime
|
||||||
|
|
||||||
|
echo "Build and setup completed successfully."
|
||||||
@@ -101,7 +101,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DatabaseAutoUpdate() {
|
func DatabaseAutoUpdate() {
|
||||||
version := 235
|
version := 243
|
||||||
|
|
||||||
db := global.DB
|
db := global.DB
|
||||||
|
|
||||||
@@ -165,6 +165,8 @@ func Migrate(version uint) {
|
|||||||
&model.ShareRecord{},
|
&model.ShareRecord{},
|
||||||
&model.AuditConn{},
|
&model.AuditConn{},
|
||||||
&model.AuditFile{},
|
&model.AuditFile{},
|
||||||
|
&model.AddressBookCollection{},
|
||||||
|
&model.AddressBookCollectionRule{},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("migrate err :=>", err)
|
fmt.Println("migrate err :=>", err)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ logger:
|
|||||||
report-caller: true
|
report-caller: true
|
||||||
proxy:
|
proxy:
|
||||||
enable: false
|
enable: false
|
||||||
host: ""
|
host: "http://127.0.0.1:1080"
|
||||||
redis:
|
redis:
|
||||||
addr: "127.0.0.1:6379"
|
addr: "127.0.0.1:6379"
|
||||||
password: ""
|
password: ""
|
||||||
|
|||||||
@@ -11,3 +11,10 @@ type GoogleOauth struct {
|
|||||||
ClientSecret string `mapstructure:"client-secret"`
|
ClientSecret string `mapstructure:"client-secret"`
|
||||||
RedirectUrl string `mapstructure:"redirect-url"`
|
RedirectUrl string `mapstructure:"redirect-url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OidcOauth struct {
|
||||||
|
Issuer string `mapstructure:"issuer"`
|
||||||
|
ClientId string `mapstructure:"client-id"`
|
||||||
|
ClientSecret string `mapstructure:"client-secret"`
|
||||||
|
RedirectUrl string `mapstructure:"redirect-url"`
|
||||||
|
}
|
||||||
20
docker-compose-dev.yaml
Normal file
20
docker-compose-dev.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
services:
|
||||||
|
rustdesk-api:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
|
# image: lejianwen/rustdesk-api
|
||||||
|
container_name: rustdesk-api
|
||||||
|
environment:
|
||||||
|
- TZ=Asia/Shanghai
|
||||||
|
- RUSTDESK_API_RUSTDESK_ID_SERVER=192.168.1.66:21116
|
||||||
|
- RUSTDESK_API_RUSTDESK_RELAY_SERVER=192.168.1.66:21117
|
||||||
|
- RUSTDESK_API_RUSTDESK_API_SERVER=http://127.0.0.1:21114
|
||||||
|
- RUSTDESK_API_RUSTDESK_KEY=123456789
|
||||||
|
ports:
|
||||||
|
- 21114:21114
|
||||||
|
volumes:
|
||||||
|
- ./data/rustdesk/api:/app/data #将数据库挂载出来方便备份
|
||||||
|
- ./conf:/app/conf # config
|
||||||
|
# - ./resources:/app/resources # 静态资源
|
||||||
|
restart: unless-stopped
|
||||||
@@ -6,10 +6,12 @@ services:
|
|||||||
- TZ=Asia/Shanghai
|
- TZ=Asia/Shanghai
|
||||||
- RUSTDESK_API_RUSTDESK_ID_SERVER=192.168.1.66:21116
|
- RUSTDESK_API_RUSTDESK_ID_SERVER=192.168.1.66:21116
|
||||||
- RUSTDESK_API_RUSTDESK_RELAY_SERVER=192.168.1.66:21117
|
- RUSTDESK_API_RUSTDESK_RELAY_SERVER=192.168.1.66:21117
|
||||||
- RUSTDESK_API_RUSTDESK_API_SERVER=http://192.168.1.66:21114
|
- RUSTDESK_API_RUSTDESK_API_SERVER=http://127.0.0.1:21114
|
||||||
- RUSTDESK_API_RUSTDESK_KEY=123456789
|
- RUSTDESK_API_RUSTDESK_KEY=123456789
|
||||||
ports:
|
ports:
|
||||||
- 21114:21114
|
- 21114:21114
|
||||||
volumes:
|
volumes:
|
||||||
- /data/rustdesk/api:/app/data #将数据库挂载出来方便备份
|
- ./data/rustdesk/api:/app/data # database
|
||||||
|
# - ./conf:/app/conf # config
|
||||||
|
# - ./resources:/app/resources # 静态资源
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -346,6 +346,554 @@ const docTemplateadmin = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/admin/address_book_collection/create": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "创建地址簿集合",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "创建地址簿集合",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/delete": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合删除",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合删除",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/detail/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合详情",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合详情",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/list": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合列表",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合列表",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页码",
|
||||||
|
"name": "page",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页大小",
|
||||||
|
"name": "page_size",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "是否是我的",
|
||||||
|
"name": "is_my",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "用户id",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/update": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合编辑",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合编辑",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/create": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "创建地址簿集合规则",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "创建地址簿集合规则",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合规则信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/delete": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则删除",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则删除",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合规则信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/detail/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则详情",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则详情",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/list": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则列表",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则列表",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页码",
|
||||||
|
"name": "page",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页大小",
|
||||||
|
"name": "page_size",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "是否是我的",
|
||||||
|
"name": "is_my",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "用户id",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "地址簿集合id",
|
||||||
|
"name": "collection_id",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/update": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则编辑",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则编辑",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合规则信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/admin/app-config": {
|
"/admin/app-config": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -2480,6 +3028,9 @@ const docTemplateadmin = `{
|
|||||||
"alias": {
|
"alias": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"forceAlwaysRelay": {
|
"forceAlwaysRelay": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
@@ -2613,11 +3164,17 @@ const docTemplateadmin = `{
|
|||||||
"id": {
|
"id": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"issuer": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"op": {
|
"op": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"redirect_url": {
|
"redirect_url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"scopes": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -2701,6 +3258,9 @@ const docTemplateadmin = `{
|
|||||||
"name"
|
"name"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"color": {
|
"color": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -2788,6 +3348,12 @@ const docTemplateadmin = `{
|
|||||||
"alias": {
|
"alias": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"collection": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@@ -2844,6 +3410,90 @@ const docTemplateadmin = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"model.AddressBookCollection": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model.AddressBookCollectionList": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"list": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"page": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"page_size": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"total": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model.AddressBookCollectionRule": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"collection_id",
|
||||||
|
"rule",
|
||||||
|
"to_id",
|
||||||
|
"type"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"rule": {
|
||||||
|
"description": "0: 无 1: 读 2: 读写 3: 完全控制",
|
||||||
|
"type": "integer",
|
||||||
|
"maximum": 3,
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"to_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"description": "1: 个人 2: 群组",
|
||||||
|
"type": "integer",
|
||||||
|
"maximum": 2,
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"model.AddressBookList": {
|
"model.AddressBookList": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -3105,12 +3755,18 @@ const docTemplateadmin = `{
|
|||||||
"id": {
|
"id": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"issuer": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"op": {
|
"op": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"redirect_url": {
|
"redirect_url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"scopes": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"updated_at": {
|
"updated_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@@ -3151,6 +3807,9 @@ const docTemplateadmin = `{
|
|||||||
"id": {
|
"id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"last_online_ip": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"last_online_time": {
|
"last_online_time": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -3221,6 +3880,12 @@ const docTemplateadmin = `{
|
|||||||
"model.Tag": {
|
"model.Tag": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"collection": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"color": {
|
"color": {
|
||||||
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
|||||||
@@ -339,6 +339,554 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/admin/address_book_collection/create": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "创建地址簿集合",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "创建地址簿集合",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/delete": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合删除",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合删除",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/detail/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合详情",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合详情",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/list": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合列表",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合列表",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页码",
|
||||||
|
"name": "page",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页大小",
|
||||||
|
"name": "page_size",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "是否是我的",
|
||||||
|
"name": "is_my",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "用户id",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection/update": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合编辑",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合编辑",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/create": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "创建地址簿集合规则",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "创建地址簿集合规则",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合规则信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/delete": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则删除",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则删除",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合规则信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/detail/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则详情",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则详情",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/list": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则列表",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则列表",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页码",
|
||||||
|
"name": "page",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "页大小",
|
||||||
|
"name": "page_size",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "是否是我的",
|
||||||
|
"name": "is_my",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "用户id",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "地址簿集合id",
|
||||||
|
"name": "collection_id",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/admin/address_book_collection_rule/update": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "地址簿集合规则编辑",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"summary": "地址簿集合规则编辑",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "地址簿集合规则信息",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollectionRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/admin/app-config": {
|
"/admin/app-config": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -2473,6 +3021,9 @@
|
|||||||
"alias": {
|
"alias": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"forceAlwaysRelay": {
|
"forceAlwaysRelay": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
@@ -2606,11 +3157,17 @@
|
|||||||
"id": {
|
"id": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"issuer": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"op": {
|
"op": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"redirect_url": {
|
"redirect_url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"scopes": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -2694,6 +3251,9 @@
|
|||||||
"name"
|
"name"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"color": {
|
"color": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -2781,6 +3341,12 @@
|
|||||||
"alias": {
|
"alias": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"collection": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@@ -2837,6 +3403,90 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"model.AddressBookCollection": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model.AddressBookCollectionList": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"list": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"page": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"page_size": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"total": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model.AddressBookCollectionRule": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"collection_id",
|
||||||
|
"rule",
|
||||||
|
"to_id",
|
||||||
|
"type"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"rule": {
|
||||||
|
"description": "0: 无 1: 读 2: 读写 3: 完全控制",
|
||||||
|
"type": "integer",
|
||||||
|
"maximum": 3,
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"to_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"description": "1: 个人 2: 群组",
|
||||||
|
"type": "integer",
|
||||||
|
"maximum": 2,
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"model.AddressBookList": {
|
"model.AddressBookList": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -3098,12 +3748,18 @@
|
|||||||
"id": {
|
"id": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"issuer": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"op": {
|
"op": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"redirect_url": {
|
"redirect_url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"scopes": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"updated_at": {
|
"updated_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@@ -3144,6 +3800,9 @@
|
|||||||
"id": {
|
"id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"last_online_ip": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"last_online_time": {
|
"last_online_time": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -3214,6 +3873,12 @@
|
|||||||
"model.Tag": {
|
"model.Tag": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"collection": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"color": {
|
"color": {
|
||||||
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ definitions:
|
|||||||
properties:
|
properties:
|
||||||
alias:
|
alias:
|
||||||
type: string
|
type: string
|
||||||
|
collection_id:
|
||||||
|
type: integer
|
||||||
forceAlwaysRelay:
|
forceAlwaysRelay:
|
||||||
type: boolean
|
type: boolean
|
||||||
hash:
|
hash:
|
||||||
@@ -103,10 +105,14 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
id:
|
id:
|
||||||
type: integer
|
type: integer
|
||||||
|
issuer:
|
||||||
|
type: string
|
||||||
op:
|
op:
|
||||||
type: string
|
type: string
|
||||||
redirect_url:
|
redirect_url:
|
||||||
type: string
|
type: string
|
||||||
|
scopes:
|
||||||
|
type: string
|
||||||
required:
|
required:
|
||||||
- client_id
|
- client_id
|
||||||
- client_secret
|
- client_secret
|
||||||
@@ -164,6 +170,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
admin.TagForm:
|
admin.TagForm:
|
||||||
properties:
|
properties:
|
||||||
|
collection_id:
|
||||||
|
type: integer
|
||||||
color:
|
color:
|
||||||
type: integer
|
type: integer
|
||||||
id:
|
id:
|
||||||
@@ -225,6 +233,10 @@ definitions:
|
|||||||
properties:
|
properties:
|
||||||
alias:
|
alias:
|
||||||
type: string
|
type: string
|
||||||
|
collection:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
collection_id:
|
||||||
|
type: integer
|
||||||
created_at:
|
created_at:
|
||||||
type: string
|
type: string
|
||||||
forceAlwaysRelay:
|
forceAlwaysRelay:
|
||||||
@@ -262,6 +274,64 @@ definitions:
|
|||||||
username:
|
username:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
model.AddressBookCollection:
|
||||||
|
properties:
|
||||||
|
created_at:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
updated_at:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: integer
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
type: object
|
||||||
|
model.AddressBookCollectionList:
|
||||||
|
properties:
|
||||||
|
list:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
type: array
|
||||||
|
page:
|
||||||
|
type: integer
|
||||||
|
page_size:
|
||||||
|
type: integer
|
||||||
|
total:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
model.AddressBookCollectionRule:
|
||||||
|
properties:
|
||||||
|
collection_id:
|
||||||
|
type: integer
|
||||||
|
created_at:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
rule:
|
||||||
|
description: '0: 无 1: 读 2: 读写 3: 完全控制'
|
||||||
|
maximum: 3
|
||||||
|
minimum: 1
|
||||||
|
type: integer
|
||||||
|
to_id:
|
||||||
|
type: integer
|
||||||
|
type:
|
||||||
|
description: '1: 个人 2: 群组'
|
||||||
|
maximum: 2
|
||||||
|
minimum: 1
|
||||||
|
type: integer
|
||||||
|
updated_at:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: integer
|
||||||
|
required:
|
||||||
|
- collection_id
|
||||||
|
- rule
|
||||||
|
- to_id
|
||||||
|
- type
|
||||||
|
type: object
|
||||||
model.AddressBookList:
|
model.AddressBookList:
|
||||||
properties:
|
properties:
|
||||||
list:
|
list:
|
||||||
@@ -434,10 +504,14 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
id:
|
id:
|
||||||
type: integer
|
type: integer
|
||||||
|
issuer:
|
||||||
|
type: string
|
||||||
op:
|
op:
|
||||||
type: string
|
type: string
|
||||||
redirect_url:
|
redirect_url:
|
||||||
type: string
|
type: string
|
||||||
|
scopes:
|
||||||
|
type: string
|
||||||
updated_at:
|
updated_at:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
@@ -464,6 +538,8 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
id:
|
id:
|
||||||
type: string
|
type: string
|
||||||
|
last_online_ip:
|
||||||
|
type: string
|
||||||
last_online_time:
|
last_online_time:
|
||||||
type: integer
|
type: integer
|
||||||
memory:
|
memory:
|
||||||
@@ -511,6 +587,10 @@ definitions:
|
|||||||
- COMMON_STATUS_DISABLED
|
- COMMON_STATUS_DISABLED
|
||||||
model.Tag:
|
model.Tag:
|
||||||
properties:
|
properties:
|
||||||
|
collection:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
collection_id:
|
||||||
|
type: integer
|
||||||
color:
|
color:
|
||||||
description: color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色,
|
description: color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色,
|
||||||
可以转成rgba
|
可以转成rgba
|
||||||
@@ -784,6 +864,328 @@ paths:
|
|||||||
summary: 地址簿编辑
|
summary: 地址簿编辑
|
||||||
tags:
|
tags:
|
||||||
- 地址簿
|
- 地址簿
|
||||||
|
/admin/address_book_collection/create:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 创建地址簿集合
|
||||||
|
parameters:
|
||||||
|
- description: 地址簿集合信息
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 创建地址簿集合
|
||||||
|
/admin/address_book_collection/delete:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合删除
|
||||||
|
parameters:
|
||||||
|
- description: 地址簿集合信息
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合删除
|
||||||
|
/admin/address_book_collection/detail/{id}:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合详情
|
||||||
|
parameters:
|
||||||
|
- description: ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合详情
|
||||||
|
/admin/address_book_collection/list:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合列表
|
||||||
|
parameters:
|
||||||
|
- description: 页码
|
||||||
|
in: query
|
||||||
|
name: page
|
||||||
|
type: integer
|
||||||
|
- description: 页大小
|
||||||
|
in: query
|
||||||
|
name: page_size
|
||||||
|
type: integer
|
||||||
|
- description: 是否是我的
|
||||||
|
in: query
|
||||||
|
name: is_my
|
||||||
|
type: integer
|
||||||
|
- description: 用户id
|
||||||
|
in: query
|
||||||
|
name: user_id
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollectionList'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合列表
|
||||||
|
/admin/address_book_collection/update:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合编辑
|
||||||
|
parameters:
|
||||||
|
- description: 地址簿集合信息
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合编辑
|
||||||
|
/admin/address_book_collection_rule/create:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 创建地址簿集合规则
|
||||||
|
parameters:
|
||||||
|
- description: 地址簿集合规则信息
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollectionRule'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 创建地址簿集合规则
|
||||||
|
/admin/address_book_collection_rule/delete:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合规则删除
|
||||||
|
parameters:
|
||||||
|
- description: 地址簿集合规则信息
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollectionRule'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合规则删除
|
||||||
|
/admin/address_book_collection_rule/detail/{id}:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合规则详情
|
||||||
|
parameters:
|
||||||
|
- description: ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollectionRule'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合规则详情
|
||||||
|
/admin/address_book_collection_rule/list:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合规则列表
|
||||||
|
parameters:
|
||||||
|
- description: 页码
|
||||||
|
in: query
|
||||||
|
name: page
|
||||||
|
type: integer
|
||||||
|
- description: 页大小
|
||||||
|
in: query
|
||||||
|
name: page_size
|
||||||
|
type: integer
|
||||||
|
- description: 是否是我的
|
||||||
|
in: query
|
||||||
|
name: is_my
|
||||||
|
type: integer
|
||||||
|
- description: 用户id
|
||||||
|
in: query
|
||||||
|
name: user_id
|
||||||
|
type: integer
|
||||||
|
- description: 地址簿集合id
|
||||||
|
in: query
|
||||||
|
name: collection_id
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollectionList'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合规则列表
|
||||||
|
/admin/address_book_collection_rule/update:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 地址簿集合规则编辑
|
||||||
|
parameters:
|
||||||
|
- description: 地址簿集合规则信息
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollectionRule'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/response.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
security:
|
||||||
|
- token: []
|
||||||
|
summary: 地址簿集合规则编辑
|
||||||
/admin/app-config:
|
/admin/app-config:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
|||||||
@@ -834,7 +834,7 @@ const docTemplateapi = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/login-options": {
|
"/login-options": {
|
||||||
"post": {
|
"get": {
|
||||||
"description": "登录选项",
|
"description": "登录选项",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@@ -1445,9 +1445,38 @@ const docTemplateapi = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"model.AddressBookCollection": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"model.Tag": {
|
"model.Tag": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"collection": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"color": {
|
"color": {
|
||||||
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
|||||||
@@ -827,7 +827,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/login-options": {
|
"/login-options": {
|
||||||
"post": {
|
"get": {
|
||||||
"description": "登录选项",
|
"description": "登录选项",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@@ -1438,9 +1438,38 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"model.AddressBookCollection": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"model.Tag": {
|
"model.Tag": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"collection": {
|
||||||
|
"$ref": "#/definitions/model.AddressBookCollection"
|
||||||
|
},
|
||||||
|
"collection_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"color": {
|
"color": {
|
||||||
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
"description": "color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
|||||||
@@ -124,8 +124,27 @@ definitions:
|
|||||||
status:
|
status:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
model.AddressBookCollection:
|
||||||
|
properties:
|
||||||
|
created_at:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
updated_at:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: integer
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
type: object
|
||||||
model.Tag:
|
model.Tag:
|
||||||
properties:
|
properties:
|
||||||
|
collection:
|
||||||
|
$ref: '#/definitions/model.AddressBookCollection'
|
||||||
|
collection_id:
|
||||||
|
type: integer
|
||||||
color:
|
color:
|
||||||
description: color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色,
|
description: color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色,
|
||||||
可以转成rgba
|
可以转成rgba
|
||||||
@@ -696,7 +715,7 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- 登录
|
- 登录
|
||||||
/login-options:
|
/login-options:
|
||||||
post:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: 登录选项
|
description: 登录选项
|
||||||
|
|||||||
@@ -70,9 +70,14 @@ func (ct *AddressBook) Create(c *gin.Context) {
|
|||||||
if !service.AllService.UserService.IsAdmin(u) || t.UserId == 0 {
|
if !service.AllService.UserService.IsAdmin(u) || t.UserId == 0 {
|
||||||
t.UserId = u.Id
|
t.UserId = u.Id
|
||||||
}
|
}
|
||||||
ex := service.AllService.AddressBookService.InfoByUserIdAndId(t.UserId, t.Id)
|
if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ex := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(t.UserId, t.Id, t.CollectionId)
|
||||||
if ex.RowId > 0 {
|
if ex.RowId > 0 {
|
||||||
response.Fail(c, 101, response.TranslateMsg(c, "ItemExist"))
|
response.Fail(c, 101, response.TranslateMsg(c, "ItemExists"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +86,7 @@ func (ct *AddressBook) Create(c *gin.Context) {
|
|||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, u)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchCreate 批量创建地址簿
|
// BatchCreate 批量创建地址簿
|
||||||
@@ -113,7 +118,7 @@ func (ct *AddressBook) BatchCreate(c *gin.Context) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, ft := range f.Tags {
|
for _, ft := range f.Tags {
|
||||||
exTag := service.AllService.TagService.InfoByUserIdAndName(fu, ft)
|
exTag := service.AllService.TagService.InfoByUserIdAndNameAndCollectionId(fu, ft, 0)
|
||||||
if exTag.Id == 0 {
|
if exTag.Id == 0 {
|
||||||
service.AllService.TagService.Create(&model.Tag{
|
service.AllService.TagService.Create(&model.Tag{
|
||||||
UserId: fu,
|
UserId: fu,
|
||||||
@@ -161,6 +166,9 @@ func (ct *AddressBook) List(c *gin.Context) {
|
|||||||
query.UserId = int(u.Id)
|
query.UserId = int(u.Id)
|
||||||
}
|
}
|
||||||
res := service.AllService.AddressBookService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
|
res := service.AllService.AddressBookService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
|
||||||
|
tx.Preload("Collection", func(txc *gorm.DB) *gorm.DB {
|
||||||
|
return txc.Select("id,name")
|
||||||
|
})
|
||||||
if query.Id != "" {
|
if query.Id != "" {
|
||||||
tx.Where("id like ?", "%"+query.Id+"%")
|
tx.Where("id like ?", "%"+query.Id+"%")
|
||||||
}
|
}
|
||||||
@@ -173,7 +181,20 @@ func (ct *AddressBook) List(c *gin.Context) {
|
|||||||
if query.Hostname != "" {
|
if query.Hostname != "" {
|
||||||
tx.Where("hostname like ?", "%"+query.Hostname+"%")
|
tx.Where("hostname like ?", "%"+query.Hostname+"%")
|
||||||
}
|
}
|
||||||
|
if query.CollectionId != nil && *query.CollectionId >= 0 {
|
||||||
|
tx.Where("collection_id = ?", query.CollectionId)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
abCIds := make([]uint, 0)
|
||||||
|
for _, ab := range res.AddressBooks {
|
||||||
|
abCIds = append(abCIds, ab.CollectionId)
|
||||||
|
}
|
||||||
|
//获取地址簿名称
|
||||||
|
//cRes := service.AllService.AddressBookService.ListCollection(1, 999, func(tx *gorm.DB) {
|
||||||
|
// tx.Where("id in ?", abCIds)
|
||||||
|
//})
|
||||||
|
//
|
||||||
response.Success(c, res)
|
response.Success(c, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +230,11 @@ func (ct *AddressBook) Update(c *gin.Context) {
|
|||||||
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := service.AllService.AddressBookService.Update(t)
|
if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := service.AllService.AddressBookService.UpdateAll(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
@@ -241,6 +266,10 @@ func (ct *AddressBook) Delete(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
t := service.AllService.AddressBookService.InfoByRowId(f.RowId)
|
t := service.AllService.AddressBookService.InfoByRowId(f.RowId)
|
||||||
|
if t.RowId == 0 {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
|
return
|
||||||
|
}
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
||||||
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
|||||||
192
http/controller/admin/addressBookCollection.go
Normal file
192
http/controller/admin/addressBookCollection.go
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Gwen/global"
|
||||||
|
"Gwen/http/request/admin"
|
||||||
|
"Gwen/http/response"
|
||||||
|
"Gwen/model"
|
||||||
|
"Gwen/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddressBookCollection struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detail 地址簿集合
|
||||||
|
// @AddressBookCollections 地址簿集合
|
||||||
|
// @Summary 地址簿集合详情
|
||||||
|
// @Description 地址簿集合详情
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "ID"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollection}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection/detail/{id} [get]
|
||||||
|
// @Security token
|
||||||
|
func (abc *AddressBookCollection) Detail(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
iid, _ := strconv.Atoi(id)
|
||||||
|
t := service.AllService.AddressBookService.CollectionInfoById(uint(iid))
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if t.Id > 0 {
|
||||||
|
response.Success(c, t)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create 创建地址簿集合
|
||||||
|
// @AddressBookCollections 地址簿集合
|
||||||
|
// @Summary 创建地址簿集合
|
||||||
|
// @Description 创建地址簿集合
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.AddressBookCollection true "地址簿集合信息"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollection}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection/create [post]
|
||||||
|
// @Security token
|
||||||
|
func (abc *AddressBookCollection) Create(c *gin.Context) {
|
||||||
|
f := &model.AddressBookCollection{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
errList := global.Validator.ValidStruct(c, f)
|
||||||
|
if len(errList) > 0 {
|
||||||
|
response.Fail(c, 101, errList[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//t := f.ToAddressBookCollection()
|
||||||
|
t := f
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) || t.UserId == 0 {
|
||||||
|
t.UserId = u.Id
|
||||||
|
}
|
||||||
|
err := service.AllService.AddressBookService.CreateCollection(t)
|
||||||
|
if err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// List 列表
|
||||||
|
// @AddressBookCollections 地址簿集合
|
||||||
|
// @Summary 地址簿集合列表
|
||||||
|
// @Description 地址簿集合列表
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param page query int false "页码"
|
||||||
|
// @Param page_size query int false "页大小"
|
||||||
|
// @Param is_my query int false "是否是我的"
|
||||||
|
// @Param user_id query int false "用户id"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollectionList}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection/list [get]
|
||||||
|
// @Security token
|
||||||
|
func (abc *AddressBookCollection) List(c *gin.Context) {
|
||||||
|
query := &admin.AddressBookCollectionQuery{}
|
||||||
|
if err := c.ShouldBindQuery(query); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) || query.IsMy == 1 {
|
||||||
|
query.UserId = int(u.Id)
|
||||||
|
}
|
||||||
|
res := service.AllService.AddressBookService.ListCollection(query.Page, query.PageSize, func(tx *gorm.DB) {
|
||||||
|
if query.UserId > 0 {
|
||||||
|
tx.Where("user_id = ?", query.UserId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
response.Success(c, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update 编辑
|
||||||
|
// @AddressBookCollections 地址簿集合
|
||||||
|
// @Summary 地址簿集合编辑
|
||||||
|
// @Description 地址簿集合编辑
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.AddressBookCollection true "地址簿集合信息"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollection}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection/update [post]
|
||||||
|
// @Security token
|
||||||
|
func (abc *AddressBookCollection) Update(c *gin.Context) {
|
||||||
|
f := &model.AddressBookCollection{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
errList := global.Validator.ValidStruct(c, f)
|
||||||
|
if len(errList) > 0 {
|
||||||
|
response.Fail(c, 101, errList[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if f.Id == 0 {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t := f //f.ToAddressBookCollection()
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := service.AllService.AddressBookService.UpdateCollection(t)
|
||||||
|
if err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除
|
||||||
|
// @AddressBookCollections 地址簿集合
|
||||||
|
// @Summary 地址簿集合删除
|
||||||
|
// @Description 地址簿集合删除
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.AddressBookCollection true "地址簿集合信息"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection/delete [post]
|
||||||
|
// @Security token
|
||||||
|
func (abc *AddressBookCollection) Delete(c *gin.Context) {
|
||||||
|
f := &model.AddressBookCollection{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id := f.Id
|
||||||
|
errList := global.Validator.ValidVar(c, id, "required,gt=0")
|
||||||
|
if len(errList) > 0 {
|
||||||
|
response.Fail(c, 101, errList[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t := service.AllService.AddressBookService.CollectionInfoById(f.Id)
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if u.Id > 0 {
|
||||||
|
err := service.AllService.AddressBookService.DeleteCollection(t)
|
||||||
|
if err == nil {
|
||||||
|
response.Success(c, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Fail(c, 101, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
|
}
|
||||||
251
http/controller/admin/addressBookCollectionRule.go
Normal file
251
http/controller/admin/addressBookCollectionRule.go
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Gwen/global"
|
||||||
|
"Gwen/http/request/admin"
|
||||||
|
"Gwen/http/response"
|
||||||
|
"Gwen/model"
|
||||||
|
"Gwen/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddressBookCollectionRule struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// List 列表
|
||||||
|
// @AddressBookCollectionRule 地址簿集合规则
|
||||||
|
// @Summary 地址簿集合规则列表
|
||||||
|
// @Description 地址簿集合规则列表
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param page query int false "页码"
|
||||||
|
// @Param page_size query int false "页大小"
|
||||||
|
// @Param is_my query int false "是否是我的"
|
||||||
|
// @Param user_id query int false "用户id"
|
||||||
|
// @Param collection_id query int false "地址簿集合id"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollectionList}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection_rule/list [get]
|
||||||
|
// @Security token
|
||||||
|
func (abcr *AddressBookCollectionRule) List(c *gin.Context) {
|
||||||
|
query := &admin.AddressBookCollectionRuleQuery{}
|
||||||
|
if err := c.ShouldBindQuery(query); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) || query.IsMy == 1 {
|
||||||
|
query.UserId = int(u.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := service.AllService.AddressBookService.ListRules(query.Page, query.PageSize, func(tx *gorm.DB) {
|
||||||
|
if query.UserId > 0 {
|
||||||
|
tx.Where("user_id = ?", query.UserId)
|
||||||
|
}
|
||||||
|
if query.CollectionId > 0 {
|
||||||
|
tx.Where("collection_id = ?", query.CollectionId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
response.Success(c, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detail 地址簿集合规则
|
||||||
|
// @AddressBookCollectionRule 地址簿集合规则
|
||||||
|
// @Summary 地址簿集合规则详情
|
||||||
|
// @Description 地址簿集合规则详情
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "ID"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollectionRule}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection_rule/detail/{id} [get]
|
||||||
|
// @Security token
|
||||||
|
func (abcr *AddressBookCollectionRule) Detail(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
iid, _ := strconv.Atoi(id)
|
||||||
|
t := service.AllService.AddressBookService.RuleInfoById(uint(iid))
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if t.Id > 0 {
|
||||||
|
response.Success(c, t)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create 创建地址簿集合规则
|
||||||
|
// @AddressBookCollectionRule 地址簿集合规则
|
||||||
|
// @Summary 创建地址簿集合规则
|
||||||
|
// @Description 创建地址簿集合规则
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.AddressBookCollectionRule true "地址簿集合规则信息"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollection}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection_rule/create [post]
|
||||||
|
// @Security token
|
||||||
|
func (abcr *AddressBookCollectionRule) Create(c *gin.Context) {
|
||||||
|
f := &model.AddressBookCollectionRule{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
errList := global.Validator.ValidStruct(c, f)
|
||||||
|
if len(errList) > 0 {
|
||||||
|
response.Fail(c, 101, errList[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if f.Type != model.ShareAddressBookRuleTypePersonal && f.Type != model.ShareAddressBookRuleTypeGroup {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//t := f.ToAddressBookCollection()
|
||||||
|
t := f
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if t.UserId == 0 {
|
||||||
|
t.UserId = u.Id
|
||||||
|
}
|
||||||
|
msg, res := abcr.CheckForm(u, t)
|
||||||
|
if !res {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, msg))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := service.AllService.AddressBookService.CreateRule(t)
|
||||||
|
if err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abcr *AddressBookCollectionRule) CheckForm(u *model.User, t *model.AddressBookCollectionRule) (string, bool) {
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
||||||
|
return "NoAccess", false
|
||||||
|
}
|
||||||
|
if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
|
||||||
|
return "ParamsError", false
|
||||||
|
}
|
||||||
|
|
||||||
|
//check to_id
|
||||||
|
if t.Type == model.ShareAddressBookRuleTypePersonal {
|
||||||
|
if t.ToId == t.UserId {
|
||||||
|
return "ParamsError", false
|
||||||
|
}
|
||||||
|
tou := service.AllService.UserService.InfoById(t.ToId)
|
||||||
|
if tou.Id == 0 {
|
||||||
|
return "ItemNotFound", false
|
||||||
|
}
|
||||||
|
//非管理员不能分享给非本组织用户
|
||||||
|
if tou.GroupId != u.GroupId && !service.AllService.UserService.IsAdmin(u) {
|
||||||
|
return "NoAccess", false
|
||||||
|
}
|
||||||
|
} else if t.Type == model.ShareAddressBookRuleTypeGroup {
|
||||||
|
if t.ToId != u.GroupId && !service.AllService.UserService.IsAdmin(u) {
|
||||||
|
return "NoAccess", false
|
||||||
|
}
|
||||||
|
|
||||||
|
tog := service.AllService.GroupService.InfoById(t.ToId)
|
||||||
|
if tog.Id == 0 {
|
||||||
|
return "ItemNotFound", false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "ParamsError", false
|
||||||
|
}
|
||||||
|
// 重复检查
|
||||||
|
ex := service.AllService.AddressBookService.RulePersonalInfoByToIdAndCid(t.ToId, t.CollectionId)
|
||||||
|
if t.Id == 0 && ex.Id > 0 {
|
||||||
|
return "ItemExists", false
|
||||||
|
}
|
||||||
|
if t.Id > 0 && ex.Id > 0 && t.Id != ex.Id {
|
||||||
|
return "ItemExists", false
|
||||||
|
}
|
||||||
|
return "", true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update 编辑
|
||||||
|
// @AddressBookCollectionRule 地址簿集合规则
|
||||||
|
// @Summary 地址簿集合规则编辑
|
||||||
|
// @Description 地址簿集合规则编辑
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.AddressBookCollectionRule true "地址簿集合规则信息"
|
||||||
|
// @Success 200 {object} response.Response{data=model.AddressBookCollection}
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection_rule/update [post]
|
||||||
|
// @Security token
|
||||||
|
func (abcr *AddressBookCollectionRule) Update(c *gin.Context) {
|
||||||
|
f := &model.AddressBookCollectionRule{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
errList := global.Validator.ValidStruct(c, f)
|
||||||
|
if len(errList) > 0 {
|
||||||
|
response.Fail(c, 101, errList[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if f.Id == 0 {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t := f //f.ToAddressBookCollection()
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
msg, res := abcr.CheckForm(u, t)
|
||||||
|
if !res {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, msg))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := service.AllService.AddressBookService.UpdateRule(t)
|
||||||
|
if err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除
|
||||||
|
// @AddressBookCollectionRule 地址簿集合规则
|
||||||
|
// @Summary 地址簿集合规则删除
|
||||||
|
// @Description 地址簿集合规则删除
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.AddressBookCollectionRule true "地址簿集合规则信息"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Failure 500 {object} response.Response
|
||||||
|
// @Router /admin/address_book_collection_rule/delete [post]
|
||||||
|
// @Security token
|
||||||
|
func (abcr *AddressBookCollectionRule) Delete(c *gin.Context) {
|
||||||
|
f := &model.AddressBookCollectionRule{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id := f.Id
|
||||||
|
errList := global.Validator.ValidVar(c, id, "required,gt=0")
|
||||||
|
if len(errList) > 0 {
|
||||||
|
response.Fail(c, 101, errList[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t := service.AllService.AddressBookService.RuleInfoById(f.Id)
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if t.Id > 0 {
|
||||||
|
err := service.AllService.AddressBookService.DeleteRule(t)
|
||||||
|
if err == nil {
|
||||||
|
response.Success(c, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Fail(c, 101, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ func (a *Audit) ConnList(c *gin.Context) {
|
|||||||
if query.FromPeer != "" {
|
if query.FromPeer != "" {
|
||||||
tx.Where("from_peer like ?", "%"+query.FromPeer+"%")
|
tx.Where("from_peer like ?", "%"+query.FromPeer+"%")
|
||||||
}
|
}
|
||||||
|
tx.Order("id desc")
|
||||||
})
|
})
|
||||||
response.Success(c, res)
|
response.Success(c, res)
|
||||||
}
|
}
|
||||||
@@ -107,6 +108,7 @@ func (a *Audit) FileList(c *gin.Context) {
|
|||||||
if query.FromPeer != "" {
|
if query.FromPeer != "" {
|
||||||
tx.Where("from_peer like ?", "%"+query.FromPeer+"%")
|
tx.Where("from_peer like ?", "%"+query.FromPeer+"%")
|
||||||
}
|
}
|
||||||
|
tx.Order("id desc")
|
||||||
})
|
})
|
||||||
response.Success(c, res)
|
response.Success(c, res)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func (ct *Group) Create(c *gin.Context) {
|
|||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, u)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List 列表
|
// List 列表
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ func (ct *LoginLog) List(c *gin.Context) {
|
|||||||
if query.UserId > 0 {
|
if query.UserId > 0 {
|
||||||
tx.Where("user_id = ?", query.UserId)
|
tx.Where("user_id = ?", query.UserId)
|
||||||
}
|
}
|
||||||
|
tx.Order("id desc")
|
||||||
})
|
})
|
||||||
response.Success(c, res)
|
response.Success(c, res)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,13 @@ func (o *Oauth) Unbind(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if f.Op == model.OauthTypeOidc {
|
||||||
|
err = service.AllService.OauthService.UnBindOidcUser(u.Id)
|
||||||
|
if err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response.Success(c, nil)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
@@ -202,7 +209,7 @@ func (o *Oauth) Create(c *gin.Context) {
|
|||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, u)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List 列表
|
// List 列表
|
||||||
|
|||||||
@@ -59,13 +59,13 @@ func (ct *Peer) Create(c *gin.Context) {
|
|||||||
response.Fail(c, 101, errList[0])
|
response.Fail(c, 101, errList[0])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u := f.ToPeer()
|
p := f.ToPeer()
|
||||||
err := service.AllService.PeerService.Create(u)
|
err := service.AllService.PeerService.Create(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, u)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List 列表
|
// List 列表
|
||||||
@@ -207,3 +207,21 @@ func (ct *Peer) BatchDelete(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
response.Success(c, nil)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ct *Peer) SimpleData(c *gin.Context) {
|
||||||
|
f := &admin.SimpleDataQuery{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(f.Ids) == 0 {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res := service.AllService.PeerService.List(1, 99999, func(tx *gorm.DB) {
|
||||||
|
//可以公开的情报
|
||||||
|
tx.Select("id,version")
|
||||||
|
tx.Where("id in (?)", f.Ids)
|
||||||
|
})
|
||||||
|
response.Success(c, res)
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func (ct *Tag) Create(c *gin.Context) {
|
|||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, u)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List 列表
|
// List 列表
|
||||||
@@ -101,9 +101,15 @@ func (ct *Tag) List(c *gin.Context) {
|
|||||||
query.UserId = int(u.Id)
|
query.UserId = int(u.Id)
|
||||||
}
|
}
|
||||||
res := service.AllService.TagService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
|
res := service.AllService.TagService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
|
||||||
|
tx.Preload("Collection", func(txc *gorm.DB) *gorm.DB {
|
||||||
|
return txc.Select("id,name")
|
||||||
|
})
|
||||||
if query.UserId > 0 {
|
if query.UserId > 0 {
|
||||||
tx.Where("user_id = ?", query.UserId)
|
tx.Where("user_id = ?", query.UserId)
|
||||||
}
|
}
|
||||||
|
if query.CollectionId != nil && *query.CollectionId >= 0 {
|
||||||
|
tx.Where("collection_id = ?", query.CollectionId)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
response.Success(c, res)
|
response.Success(c, res)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func (ct *User) Create(c *gin.Context) {
|
|||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, u)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List 列表
|
// List 列表
|
||||||
@@ -293,3 +293,33 @@ func (ct *User) MyOauth(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
response.Success(c, res)
|
response.Success(c, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// groupUsers
|
||||||
|
func (ct *User) GroupUsers(c *gin.Context) {
|
||||||
|
q := &admin.GroupUsersQuery{}
|
||||||
|
if err := c.ShouldBindJSON(q); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
gid := u.GroupId
|
||||||
|
uid := u.Id
|
||||||
|
if service.AllService.UserService.IsAdmin(u) && q.UserId > 0 {
|
||||||
|
nu := service.AllService.UserService.InfoById(q.UserId)
|
||||||
|
gid = nu.GroupId
|
||||||
|
uid = q.UserId
|
||||||
|
}
|
||||||
|
res := service.AllService.UserService.List(1, 999, func(tx *gorm.DB) {
|
||||||
|
tx.Where("group_id = ?", gid)
|
||||||
|
})
|
||||||
|
var data []*adResp.GroupUsersPayload
|
||||||
|
for _, _u := range res.Users {
|
||||||
|
gup := &adResp.GroupUsersPayload{}
|
||||||
|
gup.FromUser(_u)
|
||||||
|
if _u.Id == uid {
|
||||||
|
gup.Status = 0
|
||||||
|
}
|
||||||
|
data = append(data, gup)
|
||||||
|
}
|
||||||
|
response.Success(c, data)
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ import (
|
|||||||
"Gwen/http/response/api"
|
"Gwen/http/response/api"
|
||||||
"Gwen/model"
|
"Gwen/model"
|
||||||
"Gwen/service"
|
"Gwen/service"
|
||||||
|
"Gwen/utils"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Ab struct {
|
type Ab struct {
|
||||||
@@ -112,6 +115,35 @@ func (a *Ab) Tags(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, tags.Tags)
|
c.JSON(http.StatusOK, tags.Tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PTags
|
||||||
|
// @Tags 地址[Personal]
|
||||||
|
// @Summary 标签
|
||||||
|
// @Description 标签
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param guid path string true "guid"
|
||||||
|
// @Success 200 {object} model.TagList
|
||||||
|
// @Failure 500 {object} response.ErrorResponse
|
||||||
|
// @Router /ab/tags/{guid} [post]
|
||||||
|
// @Security BearerAuth
|
||||||
|
func (a *Ab) PTags(c *gin.Context) {
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserReadPrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tags := service.AllService.TagService.ListByUserIdAndCollectionId(uid, cid)
|
||||||
|
c.JSON(http.StatusOK, tags.Tags)
|
||||||
|
}
|
||||||
|
|
||||||
// TagAdd
|
// TagAdd
|
||||||
// @Tags 地址[Personal]
|
// @Tags 地址[Personal]
|
||||||
// @Summary 标签添加
|
// @Summary 标签添加
|
||||||
@@ -124,19 +156,35 @@ func (a *Ab) Tags(c *gin.Context) {
|
|||||||
// @Router /ab/tag/add/{guid} [post]
|
// @Router /ab/tag/add/{guid} [post]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) TagAdd(c *gin.Context) {
|
func (a *Ab) TagAdd(c *gin.Context) {
|
||||||
|
|
||||||
t := &model.Tag{}
|
t := &model.Tag{}
|
||||||
err := c.ShouldBindJSON(t)
|
err := c.ShouldBindJSON(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
tag := service.AllService.TagService.InfoByUserIdAndName(u.Id, t.Name)
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserWritePrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := service.AllService.TagService.InfoByUserIdAndNameAndCollectionId(uid, t.Name, cid)
|
||||||
if tag != nil && tag.Id != 0 {
|
if tag != nil && tag.Id != 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemExists"))
|
response.Error(c, response.TranslateMsg(c, "ItemExists"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.UserId = u.Id
|
t.UserId = uid
|
||||||
|
t.CollectionId = cid
|
||||||
err = service.AllService.TagService.Create(t)
|
err = service.AllService.TagService.Create(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
@@ -157,6 +205,7 @@ func (a *Ab) TagAdd(c *gin.Context) {
|
|||||||
// @Router /ab/tag/rename/{guid} [put]
|
// @Router /ab/tag/rename/{guid} [put]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) TagRename(c *gin.Context) {
|
func (a *Ab) TagRename(c *gin.Context) {
|
||||||
|
|
||||||
t := &requstform.TagRenameForm{}
|
t := &requstform.TagRenameForm{}
|
||||||
err := c.ShouldBindJSON(t)
|
err := c.ShouldBindJSON(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,12 +213,25 @@ func (a *Ab) TagRename(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
tag := service.AllService.TagService.InfoByUserIdAndName(u.Id, t.Old)
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserWritePrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := service.AllService.TagService.InfoByUserIdAndNameAndCollectionId(uid, t.Old, cid)
|
||||||
if tag == nil || tag.Id == 0 {
|
if tag == nil || tag.Id == 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ntag := service.AllService.TagService.InfoByUserIdAndName(u.Id, t.New)
|
ntag := service.AllService.TagService.InfoByUserIdAndNameAndCollectionId(uid, t.New, cid)
|
||||||
if ntag != nil && ntag.Id != 0 {
|
if ntag != nil && ntag.Id != 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemExists"))
|
response.Error(c, response.TranslateMsg(c, "ItemExists"))
|
||||||
return
|
return
|
||||||
@@ -202,7 +264,20 @@ func (a *Ab) TagUpdate(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
tag := service.AllService.TagService.InfoByUserIdAndName(u.Id, t.Name)
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserWritePrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := service.AllService.TagService.InfoByUserIdAndNameAndCollectionId(uid, t.Name, cid)
|
||||||
if tag == nil || tag.Id == 0 {
|
if tag == nil || tag.Id == 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
return
|
return
|
||||||
@@ -228,6 +303,7 @@ func (a *Ab) TagUpdate(c *gin.Context) {
|
|||||||
// @Router /ab/tag/{guid} [delete]
|
// @Router /ab/tag/{guid} [delete]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) TagDel(c *gin.Context) {
|
func (a *Ab) TagDel(c *gin.Context) {
|
||||||
|
|
||||||
t := &[]string{}
|
t := &[]string{}
|
||||||
err := c.ShouldBind(t)
|
err := c.ShouldBind(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -236,8 +312,21 @@ func (a *Ab) TagDel(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
//fmt.Println(t)
|
//fmt.Println(t)
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserFullControlPrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, name := range *t {
|
for _, name := range *t {
|
||||||
tag := service.AllService.TagService.InfoByUserIdAndName(u.Id, name)
|
tag := service.AllService.TagService.InfoByUserIdAndNameAndCollectionId(uid, name, cid)
|
||||||
if tag == nil || tag.Id == 0 {
|
if tag == nil || tag.Id == 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
return
|
return
|
||||||
@@ -272,7 +361,7 @@ func (a *Ab) Personal(c *gin.Context) {
|
|||||||
rule = json['rule'] ?? 0;
|
rule = json['rule'] ?? 0;
|
||||||
*/
|
*/
|
||||||
if global.Config.Rustdesk.Personal == 1 {
|
if global.Config.Rustdesk.Personal == 1 {
|
||||||
guid := strconv.Itoa(int(user.GroupId)) + "-" + strconv.Itoa(int(user.Id))
|
guid := a.ComposeGuid(user.GroupId, user.Id, 0)
|
||||||
//如果返回了guid,后面的请求会有变化
|
//如果返回了guid,后面的请求会有变化
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"guid": guid,
|
"guid": guid,
|
||||||
@@ -315,38 +404,139 @@ func (a *Ab) Settings(c *gin.Context) {
|
|||||||
// @Router /ab/shared/profiles [post]
|
// @Router /ab/shared/profiles [post]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) SharedProfiles(c *gin.Context) {
|
func (a *Ab) SharedProfiles(c *gin.Context) {
|
||||||
//AbProfile.fromJson(Map<String, dynamic> json)
|
|
||||||
//: guid = json['guid'] ?? '',
|
var res []*api.SharedProfilesPayload
|
||||||
// name = json['name'] ?? '',
|
|
||||||
// owner = json['owner'] ?? '',
|
user := service.AllService.UserService.CurUser(c)
|
||||||
// note = json['note'] ?? '',
|
myAbCollectionList := service.AllService.AddressBookService.ListCollectionByUserId(user.Id)
|
||||||
// rule = json['rule'] ?? 0;
|
for _, ab := range myAbCollectionList.AddressBookCollection {
|
||||||
//暂时没必要返回数据,可能是为了共享地址簿
|
res = append(res, &api.SharedProfilesPayload{
|
||||||
/*item := map[string]interface{}{
|
Guid: a.ComposeGuid(user.GroupId, user.Id, ab.Id),
|
||||||
"guid": "1",
|
Name: ab.Name,
|
||||||
"name": "admin",
|
Owner: user.Username,
|
||||||
"owner": "admin",
|
Rule: model.ShareAddressBookRuleRuleFullControl,
|
||||||
"note": "admin11",
|
})
|
||||||
"rule": 3,
|
|
||||||
}
|
}
|
||||||
item2 := map[string]interface{}{
|
|
||||||
"guid": "2",
|
allAbIds := make(map[uint]int) //用map去重,并保留最大Rule
|
||||||
"name": "admin2",
|
allUserIds := make(map[uint]*model.User)
|
||||||
"owner": "admin2",
|
rules := service.AllService.AddressBookService.CollectionReadRules(user)
|
||||||
"note": "admin22",
|
for _, rule := range rules {
|
||||||
"rule": 2,
|
//先判断是否存在
|
||||||
|
r, ok := allAbIds[rule.CollectionId]
|
||||||
|
if ok {
|
||||||
|
//再判断权限大小
|
||||||
|
if r < rule.Rule {
|
||||||
|
allAbIds[rule.CollectionId] = rule.Rule
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
allAbIds[rule.CollectionId] = rule.Rule
|
||||||
|
allUserIds[rule.UserId] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
abids := utils.Keys(allAbIds)
|
||||||
|
collections := service.AllService.AddressBookService.ListCollectionByIds(abids)
|
||||||
|
|
||||||
|
ids := utils.Keys(allUserIds)
|
||||||
|
allUsers := service.AllService.UserService.ListByIds(ids)
|
||||||
|
for _, u := range allUsers {
|
||||||
|
allUserIds[u.Id] = u
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, collection := range collections {
|
||||||
|
_u, ok := allUserIds[collection.UserId]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
res = append(res, &api.SharedProfilesPayload{
|
||||||
|
Guid: a.ComposeGuid(_u.GroupId, _u.Id, collection.Id),
|
||||||
|
Name: collection.Name,
|
||||||
|
Owner: _u.Username,
|
||||||
|
Rule: allAbIds[collection.Id],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"total": 2,
|
|
||||||
"data": []interface{}{item, item2},
|
|
||||||
})*/
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"total": 0,
|
"total": 0, //len(res),
|
||||||
"data": nil,
|
"data": res,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseGuid
|
||||||
|
func (a *Ab) ParseGuid(guid string) (gid, uid, cid uint) {
|
||||||
|
//用-切割 guid
|
||||||
|
guids := strings.Split(guid, "-")
|
||||||
|
if len(guids) < 2 {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
if len(guids) != 3 {
|
||||||
|
cid = 0
|
||||||
|
} else {
|
||||||
|
s, err := strconv.Atoi(guids[2])
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
cid = uint(s)
|
||||||
|
}
|
||||||
|
g, err := strconv.Atoi(guids[0])
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
gid = uint(g)
|
||||||
|
u, err := strconv.Atoi(guids[1])
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
uid = uint(u)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComposeGuid
|
||||||
|
func (a *Ab) ComposeGuid(gid, uid, cid uint) string {
|
||||||
|
return strconv.Itoa(int(gid)) + "-" + strconv.Itoa(int(uid)) + "-" + strconv.Itoa(int(cid))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckGuid
|
||||||
|
func (a *Ab) CheckGuid(cu *model.User, guid string) (gid, uid, cid uint, err error) {
|
||||||
|
gid, uid, cid = a.ParseGuid(guid)
|
||||||
|
err = nil
|
||||||
|
if gid == 0 || uid == 0 {
|
||||||
|
err = errors.New("ParamsError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u := &model.User{}
|
||||||
|
if cu.Id == uid {
|
||||||
|
u = cu
|
||||||
|
} else {
|
||||||
|
u = service.AllService.UserService.InfoById(uid)
|
||||||
|
}
|
||||||
|
if u == nil || u.Id == 0 {
|
||||||
|
err = errors.New("ParamsError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if u.GroupId != gid {
|
||||||
|
err = errors.New("ParamsError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cid == 0 && cu.Id != uid {
|
||||||
|
err = errors.New("ParamsError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cid > 0 {
|
||||||
|
c := service.AllService.AddressBookService.CollectionInfoById(cid)
|
||||||
|
if c == nil || c.Id == 0 {
|
||||||
|
err = errors.New("ParamsError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if c.UserId != uid {
|
||||||
|
err = errors.New("ParamsError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Peers
|
// Peers
|
||||||
// @Tags 地址[Personal]
|
// @Tags 地址[Personal]
|
||||||
// @Summary 地址列表
|
// @Summary 地址列表
|
||||||
@@ -361,8 +551,21 @@ func (a *Ab) SharedProfiles(c *gin.Context) {
|
|||||||
// @Router /ab/peers [post]
|
// @Router /ab/peers [post]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) Peers(c *gin.Context) {
|
func (a *Ab) Peers(c *gin.Context) {
|
||||||
user := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
al := service.AllService.AddressBookService.ListByUserId(user.Id, 1, 1000)
|
guid := c.Query("ab")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserReadPrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
al := service.AllService.AddressBookService.ListByUserIdAndCollectionId(uid, cid, 1, 1000)
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"total": al.Total,
|
"total": al.Total,
|
||||||
"data": al.AddressBooks,
|
"data": al.AddressBooks,
|
||||||
@@ -370,24 +573,6 @@ func (a *Ab) Peers(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PTags
|
|
||||||
// @Tags 地址[Personal]
|
|
||||||
// @Summary 标签
|
|
||||||
// @Description 标签
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param guid path string true "guid"
|
|
||||||
// @Success 200 {object} model.TagList
|
|
||||||
// @Failure 500 {object} response.ErrorResponse
|
|
||||||
// @Router /ab/tags/{guid} [post]
|
|
||||||
// @Security BearerAuth
|
|
||||||
func (a *Ab) PTags(c *gin.Context) {
|
|
||||||
user := service.AllService.UserService.CurUser(c)
|
|
||||||
|
|
||||||
tags := service.AllService.TagService.ListByUserId(user.Id)
|
|
||||||
c.JSON(http.StatusOK, tags.Tags)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PeerAdd
|
// PeerAdd
|
||||||
// @Tags 地址[Personal]
|
// @Tags 地址[Personal]
|
||||||
// @Summary 添加地址
|
// @Summary 添加地址
|
||||||
@@ -402,18 +587,31 @@ func (a *Ab) PTags(c *gin.Context) {
|
|||||||
func (a *Ab) PeerAdd(c *gin.Context) {
|
func (a *Ab) PeerAdd(c *gin.Context) {
|
||||||
// forceAlwaysRelay永远是字符串"false"
|
// forceAlwaysRelay永远是字符串"false"
|
||||||
//f := &gin.H{}
|
//f := &gin.H{}
|
||||||
//guid := c.Param("guid")
|
|
||||||
f := &requstform.PersonalAddressBookForm{}
|
f := &requstform.PersonalAddressBookForm{}
|
||||||
err := c.ShouldBindJSON(f)
|
err := c.ShouldBindJSON(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//fmt.Println(f)
|
|
||||||
u := service.AllService.UserService.CurUser(c)
|
|
||||||
f.UserId = u.Id
|
|
||||||
ab := f.ToAddressBook()
|
|
||||||
|
|
||||||
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserWritePrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//fmt.Println(f)
|
||||||
|
f.UserId = uid
|
||||||
|
ab := f.ToAddressBook()
|
||||||
|
ab.CollectionId = cid
|
||||||
if ab.Platform == "" || ab.Username == "" || ab.Hostname == "" {
|
if ab.Platform == "" || ab.Username == "" || ab.Hostname == "" {
|
||||||
peer := service.AllService.PeerService.FindById(ab.Id)
|
peer := service.AllService.PeerService.FindById(ab.Id)
|
||||||
if peer.RowId != 0 {
|
if peer.RowId != 0 {
|
||||||
@@ -450,8 +648,21 @@ func (a *Ab) PeerDel(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserFullControlPrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, id := range *f {
|
for _, id := range *f {
|
||||||
ab := service.AllService.AddressBookService.InfoByUserIdAndId(u.Id, id)
|
ab := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(uid, id, cid)
|
||||||
if ab == nil || ab.RowId == 0 {
|
if ab == nil || ab.RowId == 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
return
|
return
|
||||||
@@ -478,24 +689,53 @@ func (a *Ab) PeerDel(c *gin.Context) {
|
|||||||
// @Router /ab/peer/update/{guid} [put]
|
// @Router /ab/peer/update/{guid} [put]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) PeerUpdate(c *gin.Context) {
|
func (a *Ab) PeerUpdate(c *gin.Context) {
|
||||||
//f := &gin.H{}
|
f := gin.H{}
|
||||||
f := &requstform.PersonalAddressBookForm{}
|
//f := &requstform.PersonalAddressBookForm{}
|
||||||
err := c.ShouldBindJSON(f)
|
err := c.ShouldBindJSON(&f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//fmt.Println(f)
|
|
||||||
//return
|
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
ab := service.AllService.AddressBookService.InfoByUserIdAndId(u.Id, f.Id)
|
guid := c.Param("guid")
|
||||||
|
_, uid, cid, err := a.CheckGuid(u, guid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//check privileges
|
||||||
|
if !service.AllService.AddressBookService.CheckUserWritePrivilege(u, uid, cid) {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//fmt.Println(f)
|
||||||
|
//判断f["Id"]是否存在
|
||||||
|
fid, ok := f["id"]
|
||||||
|
if !ok {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fidstr := fid.(string)
|
||||||
|
|
||||||
|
ab := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(uid, fidstr, cid)
|
||||||
if ab == nil || ab.RowId == 0 {
|
if ab == nil || ab.RowId == 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nab := f.ToAddressBook()
|
//允许的字段
|
||||||
nab.RowId = ab.RowId
|
allowUp := []string{"password", "hash", "tags", "alias"}
|
||||||
err = service.AllService.AddressBookService.Update(nab)
|
//f中的字段如果不在allowUp中,就删除
|
||||||
|
for k := range f {
|
||||||
|
if !utils.InArray(k, allowUp) {
|
||||||
|
delete(f, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//fmt.Println(f)
|
||||||
|
if tags, _ok := f["tags"]; _ok {
|
||||||
|
f["tags"], _ = json.Marshal(tags)
|
||||||
|
}
|
||||||
|
err = service.AllService.AddressBookService.UpdateByMap(ab, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -28,23 +28,23 @@ type Group struct {
|
|||||||
// @Router /users [get]
|
// @Router /users [get]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (g *Group) Users(c *gin.Context) {
|
func (g *Group) Users(c *gin.Context) {
|
||||||
u := service.AllService.UserService.CurUser(c)
|
|
||||||
|
|
||||||
if !*u.IsAdmin {
|
|
||||||
gr := service.AllService.GroupService.InfoById(u.GroupId)
|
|
||||||
if gr.Type != model.GroupTypeShare {
|
|
||||||
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
q := &apiReq.UserListQuery{}
|
q := &apiReq.UserListQuery{}
|
||||||
err := c.ShouldBindQuery(&q)
|
err := c.ShouldBindQuery(&q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, err.Error())
|
response.Error(c, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userList := service.AllService.UserService.ListByGroupId(u.GroupId, q.Page, q.PageSize)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
gr := service.AllService.GroupService.InfoById(u.GroupId)
|
||||||
|
userList := &model.UserList{}
|
||||||
|
if !*u.IsAdmin && gr.Type != model.GroupTypeShare {
|
||||||
|
//仅能获取到自己
|
||||||
|
userList.Users = append(userList.Users, u)
|
||||||
|
userList.Total = 1
|
||||||
|
} else {
|
||||||
|
userList = service.AllService.UserService.ListByGroupId(u.GroupId, q.Page, q.PageSize)
|
||||||
|
}
|
||||||
|
|
||||||
var data []*apiResp.UserPayload
|
var data []*apiResp.UserPayload
|
||||||
for _, user := range userList.Users {
|
for _, user := range userList.Users {
|
||||||
up := &apiResp.UserPayload{}
|
up := &apiResp.UserPayload{}
|
||||||
@@ -73,23 +73,21 @@ func (g *Group) Users(c *gin.Context) {
|
|||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (g *Group) Peers(c *gin.Context) {
|
func (g *Group) Peers(c *gin.Context) {
|
||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
|
|
||||||
if !*u.IsAdmin {
|
|
||||||
gr := service.AllService.GroupService.InfoById(u.GroupId)
|
|
||||||
if gr.Type != model.GroupTypeShare {
|
|
||||||
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
q := &apiReq.PeerListQuery{}
|
q := &apiReq.PeerListQuery{}
|
||||||
err := c.ShouldBindQuery(&q)
|
err := c.ShouldBindQuery(&q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, err.Error())
|
response.Error(c, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
gr := service.AllService.GroupService.InfoById(u.GroupId)
|
||||||
|
users := make([]*model.User, 0, 1)
|
||||||
|
if !*u.IsAdmin && gr.Type != model.GroupTypeShare {
|
||||||
|
//仅能获取到自己
|
||||||
|
users = append(users, u)
|
||||||
|
} else {
|
||||||
|
users = service.AllService.UserService.ListIdAndNameByGroupId(u.GroupId)
|
||||||
|
}
|
||||||
|
|
||||||
users := service.AllService.UserService.ListIdAndNameByGroupId(u.GroupId)
|
|
||||||
namesById := make(map[uint]string)
|
namesById := make(map[uint]string)
|
||||||
userIds := make([]uint, 0)
|
userIds := make([]uint, 0)
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
|
|||||||
@@ -50,14 +50,13 @@ func (i *Index) Heartbeat(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
peer := service.AllService.PeerService.FindByUuid(info.Uuid)
|
peer := service.AllService.PeerService.FindByUuid(info.Uuid)
|
||||||
if peer == nil {
|
if peer == nil || peer.RowId == 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//如果在一分钟以内则不更新
|
//如果在40s以内则不更新
|
||||||
if time.Now().Unix()-peer.LastOnlineTime > 60 {
|
if time.Now().Unix()-peer.LastOnlineTime > 40 {
|
||||||
peer.LastOnlineTime = time.Now().Unix()
|
upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()}
|
||||||
upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: peer.LastOnlineTime}
|
|
||||||
service.AllService.PeerService.Update(upp)
|
service.AllService.PeerService.Update(upp)
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func (l *Login) Login(c *gin.Context) {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} []string
|
// @Success 200 {object} []string
|
||||||
// @Failure 500 {object} response.ErrorResponse
|
// @Failure 500 {object} response.ErrorResponse
|
||||||
// @Router /login-options [post]
|
// @Router /login-options [get]
|
||||||
func (l *Login) LoginOptions(c *gin.Context) {
|
func (l *Login) LoginOptions(c *gin.Context) {
|
||||||
oauthOks := []string{}
|
oauthOks := []string{}
|
||||||
err, _ := service.AllService.OauthService.GetOauthConfig(model.OauthTypeGithub)
|
err, _ := service.AllService.OauthService.GetOauthConfig(model.OauthTypeGithub)
|
||||||
@@ -92,6 +92,10 @@ func (l *Login) LoginOptions(c *gin.Context) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
oauthOks = append(oauthOks, model.OauthTypeGoogle)
|
oauthOks = append(oauthOks, model.OauthTypeGoogle)
|
||||||
}
|
}
|
||||||
|
err, _ = service.AllService.OauthService.GetOauthConfig(model.OauthTypeOidc)
|
||||||
|
if err == nil {
|
||||||
|
oauthOks = append(oauthOks, model.OauthTypeOidc)
|
||||||
|
}
|
||||||
oauthOks = append(oauthOks, model.OauthTypeWebauth)
|
oauthOks = append(oauthOks, model.OauthTypeWebauth)
|
||||||
var oidcItems []map[string]string
|
var oidcItems []map[string]string
|
||||||
for _, v := range oauthOks {
|
for _, v := range oauthOks {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func (o *Oauth) OidcAuth(c *gin.Context) {
|
|||||||
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if f.Op != model.OauthTypeWebauth && f.Op != model.OauthTypeGoogle && f.Op != model.OauthTypeGithub {
|
if f.Op != model.OauthTypeWebauth && f.Op != model.OauthTypeGoogle && f.Op != model.OauthTypeGithub && f.Op != model.OauthTypeOidc {
|
||||||
response.Error(c, response.TranslateMsg(c, "ParamsError"))
|
response.Error(c, response.TranslateMsg(c, "ParamsError"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -254,6 +254,70 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ty == model.OauthTypeOidc {
|
||||||
|
code := c.Query("code")
|
||||||
|
err, userData := service.AllService.OauthService.OidcCallback(code)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthFailed")+response.TranslateMsg(c, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//将空格替换成_
|
||||||
|
// OidcName := strings.Replace(userData.Name, " ", "_", -1)
|
||||||
|
if ac == service.OauthActionTypeBind {
|
||||||
|
//fmt.Println("bind", ty, userData)
|
||||||
|
utr := service.AllService.OauthService.UserThirdInfo(ty, userData.Sub)
|
||||||
|
if utr.UserId > 0 {
|
||||||
|
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthHasBindOtherUser"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//绑定
|
||||||
|
u := service.AllService.UserService.InfoById(v.UserId)
|
||||||
|
if u == nil {
|
||||||
|
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//绑定, user preffered_username as username
|
||||||
|
err = service.AllService.OauthService.BindOidcUser(userData.Sub, userData.PreferredUsername, v.UserId)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "BindFail"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.String(http.StatusOK, response.TranslateMsg(c, "BindSuccess"))
|
||||||
|
return
|
||||||
|
} else if ac == service.OauthActionTypeLogin {
|
||||||
|
if v.UserId != 0 {
|
||||||
|
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthHasBeenSuccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u := service.AllService.UserService.InfoByOidcSub(userData.Sub)
|
||||||
|
if u == nil {
|
||||||
|
oa := service.AllService.OauthService.InfoByOp(ty)
|
||||||
|
if !*oa.AutoRegister {
|
||||||
|
//c.String(http.StatusInternalServerError, "还未绑定用户,请先绑定")
|
||||||
|
|
||||||
|
v.ThirdName = userData.PreferredUsername
|
||||||
|
v.ThirdOpenId = userData.Sub
|
||||||
|
v.ThirdEmail = userData.Email
|
||||||
|
url := global.Config.Rustdesk.ApiServer + "/_admin/#/oauth/bind/" + cacheKey
|
||||||
|
c.Redirect(http.StatusFound, url)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//自动注册
|
||||||
|
u = service.AllService.UserService.RegisterByOidc(userData.PreferredUsername, userData.Sub)
|
||||||
|
if u.Id == 0 {
|
||||||
|
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthRegisterFailed"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
v.UserId = u.Id
|
||||||
|
service.AllService.OauthService.SetOauthCache(cacheKey, v, 0)
|
||||||
|
c.String(http.StatusOK, response.TranslateMsg(c, "OauthSuccess"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "SystemError"))
|
c.String(http.StatusInternalServerError, response.TranslateMsg(c, "SystemError"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ type AddressBookForm struct {
|
|||||||
Online bool `json:"online"`
|
Online bool `json:"online"`
|
||||||
LoginName string `json:"loginName" `
|
LoginName string `json:"loginName" `
|
||||||
SameServer bool `json:"sameServer"`
|
SameServer bool `json:"sameServer"`
|
||||||
|
CollectionId uint `json:"collection_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AddressBookForm) ToAddressBook() *model.AddressBook {
|
func (a AddressBookForm) ToAddressBook() *model.AddressBook {
|
||||||
@@ -46,6 +47,7 @@ func (a AddressBookForm) ToAddressBook() *model.AddressBook {
|
|||||||
Online: a.Online,
|
Online: a.Online,
|
||||||
LoginName: a.LoginName,
|
LoginName: a.LoginName,
|
||||||
SameServer: a.SameServer,
|
SameServer: a.SameServer,
|
||||||
|
CollectionId: a.CollectionId,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -72,17 +74,19 @@ func (a AddressBookForm) ToAddressBooks() []*model.AddressBook {
|
|||||||
Online: a.Online,
|
Online: a.Online,
|
||||||
LoginName: a.LoginName,
|
LoginName: a.LoginName,
|
||||||
SameServer: a.SameServer,
|
SameServer: a.SameServer,
|
||||||
|
CollectionId: a.CollectionId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return abs
|
return abs
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddressBookQuery struct {
|
type AddressBookQuery struct {
|
||||||
UserId int `form:"user_id"`
|
UserId int `form:"user_id"`
|
||||||
IsMy int `form:"is_my"`
|
CollectionId *int `form:"collection_id"`
|
||||||
Username string `form:"username"`
|
IsMy int `form:"is_my"`
|
||||||
Hostname string `form:"hostname"`
|
Username string `form:"username"`
|
||||||
Id string `form:"id"`
|
Hostname string `form:"hostname"`
|
||||||
|
Id string `form:"id"`
|
||||||
PageQuery
|
PageQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,3 +106,19 @@ func (sbwcf ShareByWebClientForm) ToShareRecord() *model.ShareRecord {
|
|||||||
Expire: sbwcf.Expire,
|
Expire: sbwcf.Expire,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddressBookCollectionQuery struct {
|
||||||
|
UserId int `form:"user_id"`
|
||||||
|
IsMy int `form:"is_my"`
|
||||||
|
PageQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddressBookCollectionSimpleListQuery struct {
|
||||||
|
UserIds []uint `form:"user_ids"`
|
||||||
|
}
|
||||||
|
type AddressBookCollectionRuleQuery struct {
|
||||||
|
UserId int `form:"user_id"`
|
||||||
|
CollectionId int `form:"collection_id"`
|
||||||
|
IsMy int `form:"is_my"`
|
||||||
|
PageQuery
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ type UnBindOauthForm struct {
|
|||||||
type OauthForm struct {
|
type OauthForm struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Op string `json:"op" validate:"required"`
|
Op string `json:"op" validate:"required"`
|
||||||
|
Issuer string `json:"issuer" validate:"omitempty,url"`
|
||||||
|
Scopes string `json:"scopes" validate:"omitempty"`
|
||||||
ClientId string `json:"client_id" validate:"required"`
|
ClientId string `json:"client_id" validate:"required"`
|
||||||
ClientSecret string `json:"client_secret" validate:"required"`
|
ClientSecret string `json:"client_secret" validate:"required"`
|
||||||
RedirectUrl string `json:"redirect_url" validate:"required"`
|
RedirectUrl string `json:"redirect_url" validate:"required"`
|
||||||
@@ -28,6 +30,8 @@ func (of *OauthForm) ToOauth() *model.Oauth {
|
|||||||
ClientSecret: of.ClientSecret,
|
ClientSecret: of.ClientSecret,
|
||||||
RedirectUrl: of.RedirectUrl,
|
RedirectUrl: of.RedirectUrl,
|
||||||
AutoRegister: of.AutoRegister,
|
AutoRegister: of.AutoRegister,
|
||||||
|
Issuer: of.Issuer,
|
||||||
|
Scopes: of.Scopes,
|
||||||
}
|
}
|
||||||
oa.Id = of.Id
|
oa.Id = of.Id
|
||||||
return oa
|
return oa
|
||||||
|
|||||||
@@ -39,3 +39,7 @@ type PeerQuery struct {
|
|||||||
Id string `json:"id" form:"id"`
|
Id string `json:"id" form:"id"`
|
||||||
Hostname string `json:"hostname" form:"hostname"`
|
Hostname string `json:"hostname" form:"hostname"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SimpleDataQuery struct {
|
||||||
|
Ids []string `json:"ids" form:"ids"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ package admin
|
|||||||
import "Gwen/model"
|
import "Gwen/model"
|
||||||
|
|
||||||
type TagForm struct {
|
type TagForm struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name" validate:"required"`
|
Name string `json:"name" validate:"required"`
|
||||||
Color uint `json:"color" validate:"required"`
|
Color uint `json:"color" validate:"required"`
|
||||||
UserId uint `json:"user_id"`
|
UserId uint `json:"user_id"`
|
||||||
|
CollectionId uint `json:"collection_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TagForm) FromTag(group *model.Tag) *TagForm {
|
func (f *TagForm) FromTag(group *model.Tag) *TagForm {
|
||||||
@@ -14,6 +15,7 @@ func (f *TagForm) FromTag(group *model.Tag) *TagForm {
|
|||||||
f.Name = group.Name
|
f.Name = group.Name
|
||||||
f.Color = group.Color
|
f.Color = group.Color
|
||||||
f.UserId = group.UserId
|
f.UserId = group.UserId
|
||||||
|
f.CollectionId = group.CollectionId
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,11 +25,13 @@ func (f *TagForm) ToTag() *model.Tag {
|
|||||||
i.Name = f.Name
|
i.Name = f.Name
|
||||||
i.Color = f.Color
|
i.Color = f.Color
|
||||||
i.UserId = f.UserId
|
i.UserId = f.UserId
|
||||||
|
i.CollectionId = f.CollectionId
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagQuery struct {
|
type TagQuery struct {
|
||||||
UserId int `form:"user_id"`
|
UserId int `form:"user_id"`
|
||||||
IsMy int `form:"is_my"`
|
IsMy int `form:"is_my"`
|
||||||
|
CollectionId *int `form:"collection_id"`
|
||||||
PageQuery
|
PageQuery
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,3 +55,7 @@ type ChangeCurPasswordForm struct {
|
|||||||
OldPassword string `json:"old_password" validate:"required,gte=4,lte=20"`
|
OldPassword string `json:"old_password" validate:"required,gte=4,lte=20"`
|
||||||
NewPassword string `json:"new_password" validate:"required,gte=4,lte=20"`
|
NewPassword string `json:"new_password" validate:"required,gte=4,lte=20"`
|
||||||
}
|
}
|
||||||
|
type GroupUsersQuery struct {
|
||||||
|
IsMy int `json:"is_my"`
|
||||||
|
UserId uint `json:"user_id"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package admin
|
package admin
|
||||||
|
|
||||||
|
import "Gwen/model"
|
||||||
|
|
||||||
type LoginPayload struct {
|
type LoginPayload struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
@@ -8,7 +10,7 @@ type LoginPayload struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var UserRouteNames = []string{
|
var UserRouteNames = []string{
|
||||||
"MyTagList", "MyAddressBookList", "MyInfo",
|
"MyTagList", "MyAddressBookList", "MyInfo", "MyAddressBookCollection",
|
||||||
}
|
}
|
||||||
var AdminRouteNames = []string{"*"}
|
var AdminRouteNames = []string{"*"}
|
||||||
|
|
||||||
@@ -16,3 +18,15 @@ type UserOauthItem struct {
|
|||||||
ThirdType string `json:"third_type"`
|
ThirdType string `json:"third_type"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GroupUsersPayload struct {
|
||||||
|
Id uint `json:"id"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GroupUsersPayload) FromUser(user *model.User) {
|
||||||
|
g.Id = user.Id
|
||||||
|
g.Username = user.Username
|
||||||
|
g.Status = 1
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,3 +7,11 @@ type AbList struct {
|
|||||||
Tags []string `json:"tags,omitempty"`
|
Tags []string `json:"tags,omitempty"`
|
||||||
TagColors string `json:"tag_colors,omitempty"`
|
TagColors string `json:"tag_colors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SharedProfilesPayload struct {
|
||||||
|
Guid string `json:"guid"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
Note string `json:"note"`
|
||||||
|
Rule int `json:"rule"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ func Init(g *gin.Engine) {
|
|||||||
OauthBind(adg)
|
OauthBind(adg)
|
||||||
LoginLogBind(adg)
|
LoginLogBind(adg)
|
||||||
AuditBind(adg)
|
AuditBind(adg)
|
||||||
|
AddressBookCollectionBind(adg)
|
||||||
|
AddressBookCollectionRuleBind(adg)
|
||||||
rs := &admin.Rustdesk{}
|
rs := &admin.Rustdesk{}
|
||||||
adg.GET("/server-config", rs.ServerConfig)
|
adg.GET("/server-config", rs.ServerConfig)
|
||||||
adg.GET("/app-config", rs.AppConfig)
|
adg.GET("/app-config", rs.AppConfig)
|
||||||
@@ -48,6 +50,7 @@ func UserBind(rg *gin.RouterGroup) {
|
|||||||
aR.GET("/current", cont.Current)
|
aR.GET("/current", cont.Current)
|
||||||
aR.POST("/changeCurPwd", cont.ChangeCurPwd)
|
aR.POST("/changeCurPwd", cont.ChangeCurPwd)
|
||||||
aR.POST("/myOauth", cont.MyOauth)
|
aR.POST("/myOauth", cont.MyOauth)
|
||||||
|
aR.POST("/groupUsers", cont.GroupUsers)
|
||||||
}
|
}
|
||||||
aRP := rg.Group("/user").Use(middleware.AdminPrivilege())
|
aRP := rg.Group("/user").Use(middleware.AdminPrivilege())
|
||||||
{
|
{
|
||||||
@@ -109,6 +112,7 @@ func PeerBind(rg *gin.RouterGroup) {
|
|||||||
aR.POST("/create", cont.Create)
|
aR.POST("/create", cont.Create)
|
||||||
aR.POST("/update", cont.Update)
|
aR.POST("/update", cont.Update)
|
||||||
aR.POST("/delete", cont.Delete)
|
aR.POST("/delete", cont.Delete)
|
||||||
|
aR.POST("/simpleData", cont.SimpleData)
|
||||||
|
|
||||||
arp := aR.Use(middleware.AdminPrivilege())
|
arp := aR.Use(middleware.AdminPrivilege())
|
||||||
arp.POST("/batchDelete", cont.BatchDelete)
|
arp.POST("/batchDelete", cont.BatchDelete)
|
||||||
@@ -152,6 +156,29 @@ func AuditBind(rg *gin.RouterGroup) {
|
|||||||
afR.GET("/list", cont.FileList)
|
afR.GET("/list", cont.FileList)
|
||||||
afR.POST("/delete", cont.FileDelete)
|
afR.POST("/delete", cont.FileDelete)
|
||||||
}
|
}
|
||||||
|
func AddressBookCollectionBind(rg *gin.RouterGroup) {
|
||||||
|
aR := rg.Group("/address_book_collection")
|
||||||
|
{
|
||||||
|
cont := &admin.AddressBookCollection{}
|
||||||
|
aR.GET("/list", cont.List)
|
||||||
|
aR.GET("/detail/:id", cont.Detail)
|
||||||
|
aR.POST("/create", cont.Create)
|
||||||
|
aR.POST("/update", cont.Update)
|
||||||
|
aR.POST("/delete", cont.Delete)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func AddressBookCollectionRuleBind(rg *gin.RouterGroup) {
|
||||||
|
aR := rg.Group("/address_book_collection_rule")
|
||||||
|
{
|
||||||
|
cont := &admin.AddressBookCollectionRule{}
|
||||||
|
aR.GET("/list", cont.List)
|
||||||
|
aR.GET("/detail/:id", cont.Detail)
|
||||||
|
aR.POST("/create", cont.Create)
|
||||||
|
aR.POST("/update", cont.Update)
|
||||||
|
aR.POST("/delete", cont.Delete)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func FileBind(rg *gin.RouterGroup) {
|
func FileBind(rg *gin.RouterGroup) {
|
||||||
|
|||||||
@@ -51,30 +51,22 @@ func TestLocal_GetLock(t *testing.T) {
|
|||||||
func TestLocal_Lock(t *testing.T) {
|
func TestLocal_Lock(t *testing.T) {
|
||||||
l := NewLocal()
|
l := NewLocal()
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(3)
|
m := 10
|
||||||
|
wg.Add(m)
|
||||||
i := 0
|
i := 0
|
||||||
go func() {
|
for j := 0; j < m; j++ {
|
||||||
l.Lock("key")
|
go func() {
|
||||||
fmt.Println("l1", i)
|
l.Lock("key")
|
||||||
i++
|
//fmt.Println(j, i)
|
||||||
l.UnLock("key")
|
i++
|
||||||
wg.Done()
|
fmt.Println(j, i)
|
||||||
}()
|
l.UnLock("key")
|
||||||
go func() {
|
wg.Done()
|
||||||
l.Lock("key")
|
}()
|
||||||
fmt.Println("l2", i)
|
}
|
||||||
i++
|
|
||||||
l.UnLock("key")
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
l.Lock("key")
|
|
||||||
fmt.Println("l3", i)
|
|
||||||
i++
|
|
||||||
l.UnLock("key")
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
fmt.Println(i)
|
||||||
|
|
||||||
}
|
}
|
||||||
func TestSyncMap(t *testing.T) {
|
func TestSyncMap(t *testing.T) {
|
||||||
|
|||||||
@@ -19,22 +19,24 @@ import "Gwen/model/custom_types"
|
|||||||
|
|
||||||
// AddressBook 有些字段是Personal才会上传的
|
// AddressBook 有些字段是Personal才会上传的
|
||||||
type AddressBook struct {
|
type AddressBook struct {
|
||||||
RowId uint `gorm:"primaryKey" json:"row_id"`
|
RowId uint `gorm:"primaryKey" json:"row_id"`
|
||||||
Id string `json:"id" gorm:"default:0;not null;index"`
|
Id string `json:"id" gorm:"default:0;not null;index"`
|
||||||
Username string `json:"username" gorm:"default:'';not null;"`
|
Username string `json:"username" gorm:"default:'';not null;"`
|
||||||
Password string `json:"password" gorm:"default:'';not null;"`
|
Password string `json:"password" gorm:"default:'';not null;"`
|
||||||
Hostname string `json:"hostname" gorm:"default:'';not null;"`
|
Hostname string `json:"hostname" gorm:"default:'';not null;"`
|
||||||
Alias string `json:"alias" gorm:"default:'';not null;"`
|
Alias string `json:"alias" gorm:"default:'';not null;"`
|
||||||
Platform string `json:"platform" gorm:"default:'';not null;"`
|
Platform string `json:"platform" gorm:"default:'';not null;"`
|
||||||
Tags custom_types.AutoJson `json:"tags" gorm:"not null;" swaggertype:"array,string"`
|
Tags custom_types.AutoJson `json:"tags" gorm:"not null;" swaggertype:"array,string"`
|
||||||
Hash string `json:"hash" gorm:"default:'';not null;"`
|
Hash string `json:"hash" gorm:"default:'';not null;"`
|
||||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||||
ForceAlwaysRelay bool `json:"forceAlwaysRelay" gorm:"default:0;not null;"`
|
ForceAlwaysRelay bool `json:"forceAlwaysRelay" gorm:"default:0;not null;"`
|
||||||
RdpPort string `json:"rdpPort" gorm:"default:'';not null;"`
|
RdpPort string `json:"rdpPort" gorm:"default:'';not null;"`
|
||||||
RdpUsername string `json:"rdpUsername" gorm:"default:'';not null;"`
|
RdpUsername string `json:"rdpUsername" gorm:"default:'';not null;"`
|
||||||
Online bool `json:"online" gorm:"default:0;not null;"`
|
Online bool `json:"online" gorm:"default:0;not null;"`
|
||||||
LoginName string `json:"loginName" gorm:"default:'';not null;"`
|
LoginName string `json:"loginName" gorm:"default:'';not null;"`
|
||||||
SameServer bool `json:"sameServer" gorm:"default:0;not null;"`
|
SameServer bool `json:"sameServer" gorm:"default:0;not null;"`
|
||||||
|
CollectionId uint `json:"collection_id" gorm:"default:0;not null;index"`
|
||||||
|
Collection *AddressBookCollection `json:"collection,omitempty"`
|
||||||
TimeModel
|
TimeModel
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,3 +44,37 @@ type AddressBookList struct {
|
|||||||
AddressBooks []*AddressBook `json:"list"`
|
AddressBooks []*AddressBook `json:"list"`
|
||||||
Pagination
|
Pagination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddressBookCollection struct {
|
||||||
|
IdModel
|
||||||
|
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||||
|
Name string `json:"name" gorm:"default:'';not null;" validate:"required"`
|
||||||
|
TimeModel
|
||||||
|
}
|
||||||
|
type AddressBookCollectionList struct {
|
||||||
|
AddressBookCollection []*AddressBookCollection `json:"list"`
|
||||||
|
Pagination
|
||||||
|
}
|
||||||
|
type AddressBookCollectionRule struct {
|
||||||
|
IdModel
|
||||||
|
UserId uint `json:"user_id" gorm:"default:0;not null;"`
|
||||||
|
CollectionId uint `json:"collection_id" gorm:"default:0;not null;index" validate:"required"`
|
||||||
|
Rule int `json:"rule" gorm:"default:0;not null;" validate:"required,gte=1,lte=3"` // 0: 无 1: 读 2: 读写 3: 完全控制
|
||||||
|
Type int `json:"type" gorm:"default:1;not null;" validate:"required,gte=1,lte=2"` // 1: 个人 2: 群组
|
||||||
|
ToId uint `json:"to_id" gorm:"default:0;not null;" validate:"required,gt=0"`
|
||||||
|
TimeModel
|
||||||
|
}
|
||||||
|
type AddressBookCollectionRuleList struct {
|
||||||
|
AddressBookCollectionRule []*AddressBookCollectionRule `json:"list"`
|
||||||
|
Pagination
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
ShareAddressBookRuleTypePersonal = 1
|
||||||
|
ShareAddressBookRuleTypeGroup = 2
|
||||||
|
)
|
||||||
|
const (
|
||||||
|
ShareAddressBookRuleRuleRead = 1
|
||||||
|
ShareAddressBookRuleRuleReadWrite = 2
|
||||||
|
ShareAddressBookRuleRuleFullControl = 3
|
||||||
|
)
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ type Oauth struct {
|
|||||||
ClientSecret string `json:"client_secret"`
|
ClientSecret string `json:"client_secret"`
|
||||||
RedirectUrl string `json:"redirect_url"`
|
RedirectUrl string `json:"redirect_url"`
|
||||||
AutoRegister *bool `json:"auto_register"`
|
AutoRegister *bool `json:"auto_register"`
|
||||||
|
Scopes string `json:"scopes"`
|
||||||
|
Issuer string `json:"issuer"`
|
||||||
TimeModel
|
TimeModel
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OauthTypeGithub = "github"
|
OauthTypeGithub = "github"
|
||||||
OauthTypeGoogle = "google"
|
OauthTypeGoogle = "google"
|
||||||
|
OauthTypeOidc = "oidc"
|
||||||
OauthTypeWebauth = "webauth"
|
OauthTypeWebauth = "webauth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ type Peer struct {
|
|||||||
Uuid string `json:"uuid" gorm:"default:'';not null;index"`
|
Uuid string `json:"uuid" gorm:"default:'';not null;index"`
|
||||||
Version string `json:"version" gorm:"default:'';not null;"`
|
Version string `json:"version" gorm:"default:'';not null;"`
|
||||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||||
User User `json:"user,omitempty" gorm:""`
|
User *User `json:"user,omitempty"`
|
||||||
LastOnlineTime int64 `json:"last_online_time" gorm:"default:0;not null;"`
|
LastOnlineTime int64 `json:"last_online_time" gorm:"default:0;not null;"`
|
||||||
|
LastOnlineIp string `json:"last_online_ip" gorm:"default:'';not null;"`
|
||||||
TimeModel
|
TimeModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package model
|
|||||||
|
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
IdModel
|
IdModel
|
||||||
Name string `json:"name" gorm:"default:'';not null;"`
|
Name string `json:"name" gorm:"default:'';not null;"`
|
||||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||||
Color uint `json:"color" gorm:"default:0;not null;"` //color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba
|
Color uint `json:"color" gorm:"default:0;not null;"` //color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba
|
||||||
|
CollectionId uint `json:"collection_id" gorm:"default:0;not null;index"`
|
||||||
|
Collection *AddressBookCollection `json:"collection,omitempty"`
|
||||||
TimeModel
|
TimeModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package model
|
|||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
IdModel
|
IdModel
|
||||||
Username string `json:"username" gorm:"default:'';not null;index,unique"`
|
Username string `json:"username" gorm:"default:'';not null;uniqueIndex"`
|
||||||
Password string `json:"-" gorm:"default:'';not null;"`
|
Password string `json:"-" gorm:"default:'';not null;"`
|
||||||
Nickname string `json:"nickname" gorm:"default:'';not null;"`
|
Nickname string `json:"nickname" gorm:"default:'';not null;"`
|
||||||
Avatar string `json:"avatar" gorm:"default:'';not null;"`
|
Avatar string `json:"avatar" gorm:"default:'';not null;"`
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ func (s *AddressBookService) InfoByUserIdAndId(userid uint, id string) *model.Ad
|
|||||||
global.DB.Where("user_id = ? and id = ?", userid, id).First(p)
|
global.DB.Where("user_id = ? and id = ?", userid, id).First(p)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) InfoByUserIdAndIdAndCid(userid uint, id string, cid uint) *model.AddressBook {
|
||||||
|
p := &model.AddressBook{}
|
||||||
|
global.DB.Where("user_id = ? and id = ? and collection_id = ?", userid, id, cid).First(p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
func (s *AddressBookService) InfoByRowId(id uint) *model.AddressBook {
|
func (s *AddressBookService) InfoByRowId(id uint) *model.AddressBook {
|
||||||
p := &model.AddressBook{}
|
p := &model.AddressBook{}
|
||||||
global.DB.Where("row_id = ?", id).First(p)
|
global.DB.Where("row_id = ?", id).First(p)
|
||||||
@@ -96,7 +102,7 @@ func (s *AddressBookService) UpdateAddressBook(abs []*model.AddressBook, userId
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *AddressBookService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AddressBookList) {
|
func (s *AddressBookService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AddressBookList) {
|
||||||
res = &model.AddressBookList{}
|
res = &model.AddressBookList{}
|
||||||
res.Page = int64(page)
|
res.Page = int64(page)
|
||||||
res.PageSize = int64(pageSize)
|
res.PageSize = int64(pageSize)
|
||||||
@@ -111,34 +117,44 @@ func (t *AddressBookService) List(page, pageSize uint, where func(tx *gorm.DB))
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create 创建
|
// Create 创建
|
||||||
func (t *AddressBookService) Create(u *model.AddressBook) error {
|
func (s *AddressBookService) Create(u *model.AddressBook) error {
|
||||||
res := global.DB.Create(u).Error
|
res := global.DB.Create(u).Error
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
func (t *AddressBookService) Delete(u *model.AddressBook) error {
|
func (s *AddressBookService) Delete(u *model.AddressBook) error {
|
||||||
return global.DB.Delete(u).Error
|
return global.DB.Delete(u).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update 更新
|
// Update 更新
|
||||||
func (t *AddressBookService) Update(u *model.AddressBook) error {
|
func (s *AddressBookService) Update(u *model.AddressBook) error {
|
||||||
return global.DB.Model(u).Updates(u).Error
|
return global.DB.Model(u).Updates(u).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateByMap 更新
|
||||||
|
func (s *AddressBookService) UpdateByMap(u *model.AddressBook, data map[string]interface{}) error {
|
||||||
|
return global.DB.Model(u).Updates(data).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAll 更新
|
||||||
|
func (s *AddressBookService) UpdateAll(u *model.AddressBook) error {
|
||||||
|
return global.DB.Model(u).Select("*").Omit("created_at").Updates(u).Error
|
||||||
|
}
|
||||||
|
|
||||||
// ShareByWebClient 分享
|
// ShareByWebClient 分享
|
||||||
func (t *AddressBookService) ShareByWebClient(m *model.ShareRecord) error {
|
func (s *AddressBookService) ShareByWebClient(m *model.ShareRecord) error {
|
||||||
m.ShareToken = uuid.New().String()
|
m.ShareToken = uuid.New().String()
|
||||||
return global.DB.Create(m).Error
|
return global.DB.Create(m).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// SharedPeer
|
// SharedPeer
|
||||||
func (t *AddressBookService) SharedPeer(shareToken string) *model.ShareRecord {
|
func (s *AddressBookService) SharedPeer(shareToken string) *model.ShareRecord {
|
||||||
m := &model.ShareRecord{}
|
m := &model.ShareRecord{}
|
||||||
global.DB.Where("share_token = ?", shareToken).First(m)
|
global.DB.Where("share_token = ?", shareToken).First(m)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlatformFromOs
|
// PlatformFromOs
|
||||||
func (t *AddressBookService) PlatformFromOs(os string) string {
|
func (s *AddressBookService) PlatformFromOs(os string) string {
|
||||||
if strings.Contains(os, "Android") || strings.Contains(os, "android") {
|
if strings.Contains(os, "Android") || strings.Contains(os, "android") {
|
||||||
return "Android"
|
return "Android"
|
||||||
}
|
}
|
||||||
@@ -153,3 +169,152 @@ func (t *AddressBookService) PlatformFromOs(os string) string {
|
|||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
func (s *AddressBookService) ListByUserIdAndCollectionId(userId, cid, page, pageSize uint) (res *model.AddressBookList) {
|
||||||
|
res = s.List(page, pageSize, func(tx *gorm.DB) {
|
||||||
|
tx.Where("user_id = ? and collection_id = ?", userId, cid)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (s *AddressBookService) ListCollection(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AddressBookCollectionList) {
|
||||||
|
res = &model.AddressBookCollectionList{}
|
||||||
|
res.Page = int64(page)
|
||||||
|
res.PageSize = int64(pageSize)
|
||||||
|
tx := global.DB.Model(&model.AddressBookCollection{})
|
||||||
|
if where != nil {
|
||||||
|
where(tx)
|
||||||
|
}
|
||||||
|
tx.Count(&res.Total)
|
||||||
|
tx.Scopes(Paginate(page, pageSize))
|
||||||
|
tx.Find(&res.AddressBookCollection)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (s *AddressBookService) ListCollectionByIds(ids []uint) (res []*model.AddressBookCollection) {
|
||||||
|
global.DB.Where("id in ?", ids).Find(&res)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) ListCollectionByUserId(userId uint) (res *model.AddressBookCollectionList) {
|
||||||
|
res = s.ListCollection(1, 100, func(tx *gorm.DB) {
|
||||||
|
tx.Where("user_id = ?", userId)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (s *AddressBookService) CollectionInfoById(id uint) *model.AddressBookCollection {
|
||||||
|
p := &model.AddressBookCollection{}
|
||||||
|
global.DB.Where("id = ?", id).First(p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) CollectionReadRules(user *model.User) (res []*model.AddressBookCollectionRule) {
|
||||||
|
// personalRules
|
||||||
|
var personalRules []*model.AddressBookCollectionRule
|
||||||
|
tx2 := global.DB.Model(&model.AddressBookCollectionRule{})
|
||||||
|
tx2.Where("type = ? and to_id = ? and rule > 0", model.ShareAddressBookRuleTypePersonal, user.Id).Find(&personalRules)
|
||||||
|
res = append(res, personalRules...)
|
||||||
|
|
||||||
|
//group
|
||||||
|
var groupRules []*model.AddressBookCollectionRule
|
||||||
|
tx3 := global.DB.Model(&model.AddressBookCollectionRule{})
|
||||||
|
tx3.Where("type = ? and to_id = ? and rule > 0", model.ShareAddressBookRuleTypeGroup, user.GroupId).Find(&groupRules)
|
||||||
|
res = append(res, groupRules...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) UserMaxRule(user *model.User, uid, cid uint) int {
|
||||||
|
// ismy?
|
||||||
|
if user.Id == uid {
|
||||||
|
return model.ShareAddressBookRuleRuleFullControl
|
||||||
|
}
|
||||||
|
max := 0
|
||||||
|
personalRules := &model.AddressBookCollectionRule{}
|
||||||
|
tx := global.DB.Model(personalRules)
|
||||||
|
tx.Where("type = ? and collection_id = ? and to_id = ?", model.ShareAddressBookRuleTypePersonal, cid, user.Id).First(&personalRules)
|
||||||
|
if personalRules.Id != 0 {
|
||||||
|
max = personalRules.Rule
|
||||||
|
if max == model.ShareAddressBookRuleRuleFullControl {
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groupRules := &model.AddressBookCollectionRule{}
|
||||||
|
tx2 := global.DB.Model(groupRules)
|
||||||
|
tx2.Where("type = ? and collection_id = ? and to_id = ?", model.ShareAddressBookRuleTypeGroup, cid, user.GroupId).First(&groupRules)
|
||||||
|
if groupRules.Id != 0 {
|
||||||
|
if groupRules.Rule > max {
|
||||||
|
max = groupRules.Rule
|
||||||
|
}
|
||||||
|
if max == model.ShareAddressBookRuleRuleFullControl {
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) CheckUserReadPrivilege(user *model.User, uid, cid uint) bool {
|
||||||
|
return s.UserMaxRule(user, uid, cid) >= model.ShareAddressBookRuleRuleRead
|
||||||
|
}
|
||||||
|
func (s *AddressBookService) CheckUserWritePrivilege(user *model.User, uid, cid uint) bool {
|
||||||
|
return s.UserMaxRule(user, uid, cid) >= model.ShareAddressBookRuleRuleReadWrite
|
||||||
|
}
|
||||||
|
func (s *AddressBookService) CheckUserFullControlPrivilege(user *model.User, uid, cid uint) bool {
|
||||||
|
return s.UserMaxRule(user, uid, cid) >= model.ShareAddressBookRuleRuleFullControl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) CreateCollection(t *model.AddressBookCollection) error {
|
||||||
|
return global.DB.Create(t).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) UpdateCollection(t *model.AddressBookCollection) error {
|
||||||
|
return global.DB.Model(t).Updates(t).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) DeleteCollection(t *model.AddressBookCollection) error {
|
||||||
|
//删除集合下的所有规则、地址簿,再删除集合
|
||||||
|
tx := global.DB.Begin()
|
||||||
|
tx.Where("collection_id = ?", t.Id).Delete(&model.AddressBookCollectionRule{})
|
||||||
|
tx.Where("collection_id = ?", t.Id).Delete(&model.AddressBook{})
|
||||||
|
tx.Delete(t)
|
||||||
|
return tx.Commit().Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) RuleInfoById(u uint) *model.AddressBookCollectionRule {
|
||||||
|
p := &model.AddressBookCollectionRule{}
|
||||||
|
global.DB.Where("id = ?", u).First(p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
func (s *AddressBookService) RulePersonalInfoByToIdAndCid(toid, cid uint) *model.AddressBookCollectionRule {
|
||||||
|
p := &model.AddressBookCollectionRule{}
|
||||||
|
global.DB.Where("type = ? and to_id = ? and collection_id = ?", model.ShareAddressBookRuleTypePersonal, toid, cid).First(p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
func (s *AddressBookService) CreateRule(t *model.AddressBookCollectionRule) error {
|
||||||
|
return global.DB.Create(t).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) ListRules(page uint, size uint, f func(tx *gorm.DB)) *model.AddressBookCollectionRuleList {
|
||||||
|
res := &model.AddressBookCollectionRuleList{}
|
||||||
|
res.Page = int64(page)
|
||||||
|
res.PageSize = int64(size)
|
||||||
|
tx := global.DB.Model(&model.AddressBookCollectionRule{})
|
||||||
|
if f != nil {
|
||||||
|
f(tx)
|
||||||
|
}
|
||||||
|
tx.Count(&res.Total)
|
||||||
|
tx.Scopes(Paginate(page, size))
|
||||||
|
tx.Find(&res.AddressBookCollectionRule)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) UpdateRule(t *model.AddressBookCollectionRule) error {
|
||||||
|
return global.DB.Model(t).Updates(t).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AddressBookService) DeleteRule(t *model.AddressBookCollectionRule) error {
|
||||||
|
return global.DB.Delete(t).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckCollectionOwner 检查Collection的所有者
|
||||||
|
func (s *AddressBookService) CheckCollectionOwner(uid uint, cid uint) bool {
|
||||||
|
p := s.CollectionInfoById(cid)
|
||||||
|
return p.UserId == uid
|
||||||
|
}
|
||||||
|
|||||||
191
service/oauth.go
191
service/oauth.go
@@ -15,10 +15,19 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Define a struct to parse the .well-known/openid-configuration response
|
||||||
|
type OidcEndpoint struct {
|
||||||
|
Issuer string `json:"issuer"`
|
||||||
|
AuthURL string `json:"authorization_endpoint"`
|
||||||
|
TokenURL string `json:"token_endpoint"`
|
||||||
|
UserInfo string `json:"userinfo_endpoint"`
|
||||||
|
}
|
||||||
|
|
||||||
type OauthService struct {
|
type OauthService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +87,14 @@ type GoogleUserdata struct {
|
|||||||
Picture string `json:"picture"`
|
Picture string `json:"picture"`
|
||||||
VerifiedEmail bool `json:"verified_email"`
|
VerifiedEmail bool `json:"verified_email"`
|
||||||
}
|
}
|
||||||
|
type OidcUserdata struct {
|
||||||
|
Sub string `json:"sub"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
VerifiedEmail bool `json:"email_verified"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
PreferredUsername string `json:"preferred_username"`
|
||||||
|
}
|
||||||
|
|
||||||
type OauthCacheItem struct {
|
type OauthCacheItem struct {
|
||||||
UserId uint `json:"user_id"`
|
UserId uint `json:"user_id"`
|
||||||
Id string `json:"id"` //rustdesk的设备ID
|
Id string `json:"id"` //rustdesk的设备ID
|
||||||
@@ -137,35 +154,102 @@ func (os *OauthService) BeginAuth(op string) (error error, code, url string) {
|
|||||||
return err, code, ""
|
return err, code, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOauthConfig 获取配置
|
// Method to fetch OIDC configuration dynamically
|
||||||
|
func FetchOidcConfig(issuer string) (error, OidcEndpoint) {
|
||||||
|
configURL := strings.TrimSuffix(issuer, "/") + "/.well-known/openid-configuration"
|
||||||
|
|
||||||
|
// Get the HTTP client (with or without proxy based on configuration)
|
||||||
|
client := getHTTPClientWithProxy()
|
||||||
|
|
||||||
|
resp, err := client.Get(configURL)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("failed to fetch OIDC configuration"), OidcEndpoint{}
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return errors.New("OIDC configuration not found, status code: %d"), OidcEndpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var endpoint OidcEndpoint
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&endpoint); err != nil {
|
||||||
|
return errors.New("failed to parse OIDC configuration"), OidcEndpoint{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, endpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOauthConfig retrieves the OAuth2 configuration based on the provider type
|
||||||
func (os *OauthService) GetOauthConfig(op string) (error, *oauth2.Config) {
|
func (os *OauthService) GetOauthConfig(op string) (error, *oauth2.Config) {
|
||||||
if op == model.OauthTypeGithub {
|
switch op {
|
||||||
g := os.InfoByOp(model.OauthTypeGithub)
|
case model.OauthTypeGithub:
|
||||||
if g.Id == 0 || g.ClientId == "" || g.ClientSecret == "" || g.RedirectUrl == "" {
|
return os.getGithubConfig()
|
||||||
return errors.New("ConfigNotFound"), nil
|
case model.OauthTypeGoogle:
|
||||||
}
|
return os.getGoogleConfig()
|
||||||
return nil, &oauth2.Config{
|
case model.OauthTypeOidc:
|
||||||
ClientID: g.ClientId,
|
return os.getOidcConfig()
|
||||||
ClientSecret: g.ClientSecret,
|
default:
|
||||||
RedirectURL: g.RedirectUrl,
|
return errors.New("unsupported OAuth type"), nil
|
||||||
Endpoint: github.Endpoint,
|
|
||||||
Scopes: []string{"read:user", "user:email"},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if op == model.OauthTypeGoogle {
|
}
|
||||||
g := os.InfoByOp(model.OauthTypeGoogle)
|
|
||||||
if g.Id == 0 || g.ClientId == "" || g.ClientSecret == "" || g.RedirectUrl == "" {
|
// Helper function to get GitHub OAuth2 configuration
|
||||||
return errors.New("ConfigNotFound"), nil
|
func (os *OauthService) getGithubConfig() (error, *oauth2.Config) {
|
||||||
}
|
g := os.InfoByOp(model.OauthTypeGithub)
|
||||||
return nil, &oauth2.Config{
|
if g.Id == 0 || g.ClientId == "" || g.ClientSecret == "" || g.RedirectUrl == "" {
|
||||||
ClientID: g.ClientId,
|
return errors.New("ConfigNotFound"), nil
|
||||||
ClientSecret: g.ClientSecret,
|
}
|
||||||
RedirectURL: g.RedirectUrl,
|
return nil, &oauth2.Config{
|
||||||
Endpoint: google.Endpoint,
|
ClientID: g.ClientId,
|
||||||
Scopes: []string{"https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"},
|
ClientSecret: g.ClientSecret,
|
||||||
}
|
RedirectURL: g.RedirectUrl,
|
||||||
|
Endpoint: github.Endpoint,
|
||||||
|
Scopes: []string{"read:user", "user:email"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to get Google OAuth2 configuration
|
||||||
|
func (os *OauthService) getGoogleConfig() (error, *oauth2.Config) {
|
||||||
|
g := os.InfoByOp(model.OauthTypeGoogle)
|
||||||
|
if g.Id == 0 || g.ClientId == "" || g.ClientSecret == "" || g.RedirectUrl == "" {
|
||||||
|
return errors.New("ConfigNotFound"), nil
|
||||||
|
}
|
||||||
|
return nil, &oauth2.Config{
|
||||||
|
ClientID: g.ClientId,
|
||||||
|
ClientSecret: g.ClientSecret,
|
||||||
|
RedirectURL: g.RedirectUrl,
|
||||||
|
Endpoint: google.Endpoint,
|
||||||
|
Scopes: []string{"https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to get OIDC OAuth2 configuration
|
||||||
|
func (os *OauthService) getOidcConfig() (error, *oauth2.Config) {
|
||||||
|
g := os.InfoByOp(model.OauthTypeOidc)
|
||||||
|
if g.Id == 0 || g.ClientId == "" || g.ClientSecret == "" || g.RedirectUrl == "" || g.Issuer == "" {
|
||||||
|
return errors.New("ConfigNotFound"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set scopes
|
||||||
|
scopes := strings.TrimSpace(g.Scopes)
|
||||||
|
if scopes == "" {
|
||||||
|
scopes = "openid,profile,email"
|
||||||
|
}
|
||||||
|
scopeList := strings.Split(scopes, ",")
|
||||||
|
err, endpoint := FetchOidcConfig(g.Issuer)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
return nil, &oauth2.Config{
|
||||||
|
ClientID: g.ClientId,
|
||||||
|
ClientSecret: g.ClientSecret,
|
||||||
|
RedirectURL: g.RedirectUrl,
|
||||||
|
Endpoint: oauth2.Endpoint{
|
||||||
|
AuthURL: endpoint.AuthURL,
|
||||||
|
TokenURL: endpoint.TokenURL,
|
||||||
|
},
|
||||||
|
Scopes: scopeList,
|
||||||
}
|
}
|
||||||
return errors.New("ConfigNotFound"), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHTTPClientWithProxy() *http.Client {
|
func getHTTPClientWithProxy() *http.Client {
|
||||||
@@ -269,6 +353,53 @@ func (os *OauthService) GoogleCallback(code string) (error error, userData *Goog
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (os *OauthService) OidcCallback(code string) (error error, userData *OidcUserdata) {
|
||||||
|
err, oauthConfig := os.GetOauthConfig(model.OauthTypeOidc)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
// 使用代理配置创建 HTTP 客户端
|
||||||
|
httpClient := getHTTPClientWithProxy()
|
||||||
|
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient)
|
||||||
|
|
||||||
|
token, err := oauthConfig.Exchange(ctx, code)
|
||||||
|
if err != nil {
|
||||||
|
global.Logger.Warn("oauthConfig.Exchange() failed: ", err)
|
||||||
|
error = errors.New("GetOauthTokenError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用带有代理的 HTTP 客户端获取用户信息
|
||||||
|
client := oauthConfig.Client(ctx, token)
|
||||||
|
g := os.InfoByOp(model.OauthTypeOidc)
|
||||||
|
err, endpoint := FetchOidcConfig(g.Issuer)
|
||||||
|
if err != nil {
|
||||||
|
global.Logger.Warn("failed fetching OIDC configuration: ", err)
|
||||||
|
error = errors.New("FetchOidcConfigError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := client.Get(endpoint.UserInfo)
|
||||||
|
if err != nil {
|
||||||
|
global.Logger.Warn("failed getting user info: ", err)
|
||||||
|
error = errors.New("GetOauthUserInfoError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func(Body io.ReadCloser) {
|
||||||
|
err := Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
global.Logger.Warn("failed closing response body: ", err)
|
||||||
|
}
|
||||||
|
}(resp.Body)
|
||||||
|
|
||||||
|
// 解析用户信息
|
||||||
|
if err = json.NewDecoder(resp.Body).Decode(&userData); err != nil {
|
||||||
|
global.Logger.Warn("failed decoding user info: ", err)
|
||||||
|
error = errors.New("DecodeOauthUserInfoError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (os *OauthService) UserThirdInfo(op, openid string) *model.UserThird {
|
func (os *OauthService) UserThirdInfo(op, openid string) *model.UserThird {
|
||||||
ut := &model.UserThird{}
|
ut := &model.UserThird{}
|
||||||
global.DB.Where("open_id = ? and third_type = ?", openid, op).First(ut)
|
global.DB.Where("open_id = ? and third_type = ?", openid, op).First(ut)
|
||||||
@@ -282,6 +413,11 @@ func (os *OauthService) BindGithubUser(openid, username string, userId uint) err
|
|||||||
func (os *OauthService) BindGoogleUser(email, username string, userId uint) error {
|
func (os *OauthService) BindGoogleUser(email, username string, userId uint) error {
|
||||||
return os.BindOauthUser(model.OauthTypeGoogle, email, username, userId)
|
return os.BindOauthUser(model.OauthTypeGoogle, email, username, userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (os *OauthService) BindOidcUser(sub, username string, userId uint) error {
|
||||||
|
return os.BindOauthUser(model.OauthTypeOidc, sub, username, userId)
|
||||||
|
}
|
||||||
|
|
||||||
func (os *OauthService) BindOauthUser(thirdType, openid, username string, userId uint) error {
|
func (os *OauthService) BindOauthUser(thirdType, openid, username string, userId uint) error {
|
||||||
utr := &model.UserThird{
|
utr := &model.UserThird{
|
||||||
OpenId: openid,
|
OpenId: openid,
|
||||||
@@ -298,6 +434,9 @@ func (os *OauthService) UnBindGithubUser(userid uint) error {
|
|||||||
func (os *OauthService) UnBindGoogleUser(userid uint) error {
|
func (os *OauthService) UnBindGoogleUser(userid uint) error {
|
||||||
return os.UnBindThird(model.OauthTypeGoogle, userid)
|
return os.UnBindThird(model.OauthTypeGoogle, userid)
|
||||||
}
|
}
|
||||||
|
func (os *OauthService) UnBindOidcUser(userid uint) error {
|
||||||
|
return os.UnBindThird(model.OauthTypeOidc, userid)
|
||||||
|
}
|
||||||
func (os *OauthService) UnBindThird(thirdType string, userid uint) error {
|
func (os *OauthService) UnBindThird(thirdType string, userid uint) error {
|
||||||
return global.DB.Where("user_id = ? and third_type = ?", userid, thirdType).Delete(&model.UserThird{}).Error
|
return global.DB.Where("user_id = ? and third_type = ?", userid, thirdType).Delete(&model.UserThird{}).Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ func (s *TagService) Info(id uint) *model.Tag {
|
|||||||
global.DB.Where("id = ?", id).First(p)
|
global.DB.Where("id = ?", id).First(p)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
func (s *TagService) InfoByUserIdAndName(userid uint, name string) *model.Tag {
|
func (s *TagService) InfoByUserIdAndNameAndCollectionId(userid uint, name string, cid uint) *model.Tag {
|
||||||
p := &model.Tag{}
|
p := &model.Tag{}
|
||||||
global.DB.Where("user_id = ? and name = ?", userid, name).First(p)
|
global.DB.Where("user_id = ? and name = ? and collection_id = ?", userid, name, cid).First(p)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,12 @@ func (s *TagService) ListByUserId(userId uint) (res *model.TagList) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
func (s *TagService) ListByUserIdAndCollectionId(userId, cid uint) (res *model.TagList) {
|
||||||
|
res = s.List(1, 1000, func(tx *gorm.DB) {
|
||||||
|
tx.Where("user_id = ? and collection_id = ?", userId, cid)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
func (s *TagService) UpdateTags(userId uint, tags map[string]uint) {
|
func (s *TagService) UpdateTags(userId uint, tags map[string]uint) {
|
||||||
tx := global.DB.Begin()
|
tx := global.DB.Begin()
|
||||||
//先查询所有tag
|
//先查询所有tag
|
||||||
@@ -58,13 +63,13 @@ func (s *TagService) UpdateTags(userId uint, tags map[string]uint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InfoById 根据用户id取用户信息
|
// InfoById 根据用户id取用户信息
|
||||||
func (t *TagService) InfoById(id uint) *model.Tag {
|
func (s *TagService) InfoById(id uint) *model.Tag {
|
||||||
u := &model.Tag{}
|
u := &model.Tag{}
|
||||||
global.DB.Where("id = ?", id).First(u)
|
global.DB.Where("id = ?", id).First(u)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TagService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.TagList) {
|
func (s *TagService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.TagList) {
|
||||||
res = &model.TagList{}
|
res = &model.TagList{}
|
||||||
res.Page = int64(page)
|
res.Page = int64(page)
|
||||||
res.PageSize = int64(pageSize)
|
res.PageSize = int64(pageSize)
|
||||||
@@ -79,15 +84,15 @@ func (t *TagService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create 创建
|
// Create 创建
|
||||||
func (t *TagService) Create(u *model.Tag) error {
|
func (s *TagService) Create(u *model.Tag) error {
|
||||||
res := global.DB.Create(u).Error
|
res := global.DB.Create(u).Error
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
func (t *TagService) Delete(u *model.Tag) error {
|
func (s *TagService) Delete(u *model.Tag) error {
|
||||||
return global.DB.Delete(u).Error
|
return global.DB.Delete(u).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update 更新
|
// Update 更新
|
||||||
func (t *TagService) Update(u *model.Tag) error {
|
func (s *TagService) Update(u *model.Tag) error {
|
||||||
return global.DB.Model(u).Updates(u).Error
|
return global.DB.Model(u).Select("*").Omit("created_at").Updates(u).Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,11 @@ func (us *UserService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (us *UserService) ListByIds(ids []uint) (res []*model.User) {
|
||||||
|
global.DB.Where("id in ?", ids).Find(&res)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
// ListByGroupId 根据组id取用户列表
|
// ListByGroupId 根据组id取用户列表
|
||||||
func (us *UserService) ListByGroupId(groupId, page, pageSize uint) (res *model.UserList) {
|
func (us *UserService) ListByGroupId(groupId, page, pageSize uint) (res *model.UserList) {
|
||||||
res = us.List(page, pageSize, func(tx *gorm.DB) {
|
res = us.List(page, pageSize, func(tx *gorm.DB) {
|
||||||
@@ -191,6 +196,11 @@ func (us *UserService) InfoByGoogleEmail(email string) *model.User {
|
|||||||
return us.InfoByOauthId(model.OauthTypeGithub, email)
|
return us.InfoByOauthId(model.OauthTypeGithub, email)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InfoByOidcSub 根据oidc取用户信息
|
||||||
|
func (us *UserService) InfoByOidcSub(sub string) *model.User {
|
||||||
|
return us.InfoByOauthId(model.OauthTypeOidc, sub)
|
||||||
|
}
|
||||||
|
|
||||||
// InfoByOauthId 根据oauth取用户信息
|
// InfoByOauthId 根据oauth取用户信息
|
||||||
func (us *UserService) InfoByOauthId(thirdType, uid string) *model.User {
|
func (us *UserService) InfoByOauthId(thirdType, uid string) *model.User {
|
||||||
ut := AllService.OauthService.UserThirdInfo(thirdType, uid)
|
ut := AllService.OauthService.UserThirdInfo(thirdType, uid)
|
||||||
@@ -214,22 +224,28 @@ func (us *UserService) RegisterByGoogle(name string, email string) *model.User {
|
|||||||
return us.RegisterByOauth(model.OauthTypeGoogle, name, email)
|
return us.RegisterByOauth(model.OauthTypeGoogle, name, email)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterByOidc 注册, use PreferredUsername as username, sub as openid
|
||||||
|
func (us *UserService) RegisterByOidc(PreferredUsername string, sub string) *model.User {
|
||||||
|
return us.RegisterByOauth(model.OauthTypeOidc, PreferredUsername, sub)
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterByOauth 注册
|
// RegisterByOauth 注册
|
||||||
func (us *UserService) RegisterByOauth(thirdType, thirdName, uid string) *model.User {
|
func (us *UserService) RegisterByOauth(thirdType, thirdName, uid string) *model.User {
|
||||||
|
global.Lock.Lock("registerByOauth")
|
||||||
|
defer global.Lock.UnLock("registerByOauth")
|
||||||
|
ut := AllService.OauthService.UserThirdInfo(thirdType, uid)
|
||||||
|
if ut.Id != 0 {
|
||||||
|
u := &model.User{}
|
||||||
|
global.DB.Where("id = ?", ut.UserId).First(u)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
tx := global.DB.Begin()
|
tx := global.DB.Begin()
|
||||||
ut := &model.UserThird{
|
ut = &model.UserThird{
|
||||||
OpenId: uid,
|
OpenId: uid,
|
||||||
ThirdName: thirdName,
|
ThirdName: thirdName,
|
||||||
ThirdType: thirdType,
|
ThirdType: thirdType,
|
||||||
}
|
}
|
||||||
//global.DB.Where("open_id = ?", githubId).First(ut)
|
|
||||||
//这种情况不应该出现,如果出现说明有bug
|
|
||||||
//if ut.Id != 0 {
|
|
||||||
// u := &model.User{}
|
|
||||||
// global.DB.Where("id = ?", ut.UserId).First(u)
|
|
||||||
// tx.Commit()
|
|
||||||
// return u
|
|
||||||
//}
|
|
||||||
|
|
||||||
username := us.GenerateUsernameByOauth(thirdName)
|
username := us.GenerateUsernameByOauth(thirdName)
|
||||||
u := &model.User{
|
u := &model.User{
|
||||||
@@ -237,6 +253,10 @@ func (us *UserService) RegisterByOauth(thirdType, thirdName, uid string) *model.
|
|||||||
GroupId: 1,
|
GroupId: 1,
|
||||||
}
|
}
|
||||||
global.DB.Create(u)
|
global.DB.Create(u)
|
||||||
|
if u.Id == 0 {
|
||||||
|
tx.Rollback()
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
ut.UserId = u.Id
|
ut.UserId = u.Id
|
||||||
global.DB.Create(ut)
|
global.DB.Create(ut)
|
||||||
|
|||||||
@@ -73,3 +73,30 @@ func RandomString(n int) string {
|
|||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keys 泛型函数,K 是键类型,V 是值类型
|
||||||
|
func Keys[K comparable, V any](m map[K]V) []K {
|
||||||
|
keys := make([]K, 0, len(m))
|
||||||
|
for k := range m {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values 泛型函数,K 是键类型,V 是值类型
|
||||||
|
func Values[K comparable, V any](m map[K]V) []V {
|
||||||
|
values := make([]V, 0, len(m))
|
||||||
|
for _, v := range m {
|
||||||
|
values = append(values, v)
|
||||||
|
}
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
|
func InArray(k string, arr []string) bool {
|
||||||
|
for _, v := range arr {
|
||||||
|
if k == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user