About how to set permissions in a YAML file and read them using Viper.
Automatically Review permissions and update database.
And create a system user (username: admin, password: in .env) with all permissions each time the project is launched.
With logFile to record all log.
- Language: Go v1.21.1
- Web FrameWork: Gin v1.9.1
- DataBase: MongoDB v7.0.2
go get -u && go mod tidy -v
go run main.go
copy etc/apiPermission.yaml.default and rename as etc/apiPermission.yaml to restrict api access rights.
PermissionDefs:
ChangePassword:
Category: "PASSWORD"
Code: "changePassword"
APIToPermission:
- Url: "/user/:userId/password"
Methods: "PATCH"
PermissionName: "ChangePassword"
copy .env.default and rename as .env
MONGO_URL=
DB_NAME=
API_PORT=
ADMIN_PASSWORD=
JWTKey=
- POST /auth/login: 登入(不需要帶token)
- POST /auth/logout: 登出
- PATCH /user/myPassword: 修改自己的密碼
- PATCH /user/{userId}/password: 修改別人的密碼(需有權限)
- POST /user: 建立使用者(需有權限)
- POST /user/find: 搜尋使用者
- POST /mapUserPermission: 建立使用者與權限關聯(需有權限)
- POST /mapUserPermission/find: 搜尋使用者與權限關聯(需有權限)
- DELETE /mapUserPermission/{id}: 刪除使用者與權限關聯(需有權限)
- POST /permission/find: 搜尋所有權限(需有權限)
- GET /setting/{code}: 搜尋設定
- PATCH /setting/{code}/{value}: 更新設定值(需有權限)
- POST /task: 分派任務(需有權限)
- POST /task/find: 搜尋所有任務
- PATCH /task/{id}/progressType/{progressType}: 更新任務進度(需為原先指派者或被指派者/DONE前須驗收完畢/DELETE需為原先指派者), 移致測試會發送通知原先指派者驗收
- PATCH /task/{id}/checked/{checked}: 驗收/驗收失敗任務(需有權限/需為原先指派者), 驗收成功會發送通知給被指派者
- DELETE /task/{id}: 刪除任務(需有權限/需為原先指派者)
- GET /notification: 搜尋所有通知(時間從近排到遠)
- PATCH /notification/{id}/read: 已讀通知(需為被發送者)
- PATCH /notification/read/all: 已讀自己所有通知
- InternalServerError: 000001
- InvalidTokenError: 000002
- WrongPasswordError: 000003
- UserNotFoundError: 000004
- PermissionDeniedError: 000107
- InvalidParameterError: 000108