mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* MF-1443 - add policies Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * fix users create Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * MF-1454 - Add Policies for sharing a Thing (#1463) * MF-1454 - Add policies for sharing a Thing Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Add a test case for sharing thing and update mock of AddPolicy Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update ShareThing parameter naming Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * MF-1454 - Policy Removal (#1466) * Add DeletePolicy gRPC endpoint in auth package Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update default admin creation Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Add policy addition endpoint (#1479) * NOISSUE - Add policy addition endpoint Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update name of the method Signed-off-by: Burak Sekili <buraksekili@gmail.com> remove build tag Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Add tests for AddPolicies (#1480) * NOISSUE - Add tests for adding policy and update authz check Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Add more tests and update request body validation Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update test case structure and utilize mock prefix for test ids Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * MF-1454 - Add initial policies for Group access control (#1467) Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Resolve PR comments Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Co-authored-by: Author: Burak Sekili <buraksekili@gmail.com>
133 lines
2.3 KiB
Go
133 lines
2.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
groups "github.com/mainflux/mainflux/auth"
|
|
"github.com/mainflux/mainflux/users"
|
|
)
|
|
|
|
type userReq struct {
|
|
user users.User
|
|
}
|
|
|
|
func (req userReq) validate() error {
|
|
return req.user.Validate()
|
|
}
|
|
|
|
type createUserReq struct {
|
|
user users.User
|
|
token string
|
|
}
|
|
|
|
func (req createUserReq) validate() error {
|
|
return req.user.Validate()
|
|
}
|
|
|
|
type viewUserReq struct {
|
|
token string
|
|
userID string
|
|
}
|
|
|
|
func (req viewUserReq) validate() error {
|
|
if req.token == "" {
|
|
return users.ErrUnauthorizedAccess
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type listUsersReq struct {
|
|
token string
|
|
offset uint64
|
|
limit uint64
|
|
email string
|
|
metadata users.Metadata
|
|
}
|
|
|
|
func (req listUsersReq) validate() error {
|
|
if req.token == "" {
|
|
return users.ErrUnauthorizedAccess
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type updateUserReq struct {
|
|
token string
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req updateUserReq) validate() error {
|
|
if req.token == "" {
|
|
return users.ErrUnauthorizedAccess
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type passwResetReq struct {
|
|
Email string `json:"email"`
|
|
Host string `json:"host"`
|
|
}
|
|
|
|
func (req passwResetReq) validate() error {
|
|
if req.Email == "" || req.Host == "" {
|
|
return users.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type resetTokenReq struct {
|
|
Token string `json:"token"`
|
|
Password string `json:"password"`
|
|
ConfPass string `json:"confirm_password"`
|
|
}
|
|
|
|
func (req resetTokenReq) validate() error {
|
|
if req.Password == "" || req.ConfPass == "" {
|
|
return users.ErrMalformedEntity
|
|
}
|
|
if req.Token == "" {
|
|
return users.ErrMissingResetToken
|
|
}
|
|
if req.Password != req.ConfPass {
|
|
return users.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type passwChangeReq struct {
|
|
Token string `json:"token"`
|
|
Password string `json:"password"`
|
|
OldPassword string `json:"old_password"`
|
|
}
|
|
|
|
func (req passwChangeReq) validate() error {
|
|
if req.Token == "" {
|
|
return users.ErrUnauthorizedAccess
|
|
}
|
|
if req.OldPassword == "" {
|
|
return users.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type listMemberGroupReq struct {
|
|
token string
|
|
offset uint64
|
|
limit uint64
|
|
metadata users.Metadata
|
|
groupID string
|
|
}
|
|
|
|
func (req listMemberGroupReq) validate() error {
|
|
if req.token == "" {
|
|
return groups.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.groupID == "" {
|
|
return groups.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|