mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-04 22:17:59 +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>
178 lines
3.4 KiB
Go
178 lines
3.4 KiB
Go
package groups
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
)
|
|
|
|
var (
|
|
_ mainflux.Response = (*memberPageRes)(nil)
|
|
_ mainflux.Response = (*groupRes)(nil)
|
|
_ mainflux.Response = (*deleteRes)(nil)
|
|
_ mainflux.Response = (*assignRes)(nil)
|
|
_ mainflux.Response = (*unassignRes)(nil)
|
|
)
|
|
|
|
type memberPageRes struct {
|
|
pageRes
|
|
Members []interface{}
|
|
}
|
|
|
|
func (res memberPageRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res memberPageRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res memberPageRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type shareGroupRes struct {
|
|
}
|
|
|
|
func (res shareGroupRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res shareGroupRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res shareGroupRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type viewGroupRes struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
OwnerID string `json:"owner_id"`
|
|
ParentID string `json:"parent_id,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
// Indicates a level in tree hierarchy from first group node - root.
|
|
Level int `json:"level"`
|
|
// Path in a tree consisting of group ids
|
|
// parentID1.parentID2.childID1
|
|
// e.g. 01EXPM5Z8HRGFAEWTETR1X1441.01EXPKW2TVK74S5NWQ979VJ4PJ.01EXPKW2TVK74S5NWQ979VJ4PJ
|
|
Path string `json:"path"`
|
|
Children []*viewGroupRes `json:"children,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (res viewGroupRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res viewGroupRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res viewGroupRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type groupRes struct {
|
|
id string
|
|
created bool
|
|
}
|
|
|
|
func (res groupRes) Code() int {
|
|
if res.created {
|
|
return http.StatusCreated
|
|
}
|
|
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res groupRes) Headers() map[string]string {
|
|
if res.created {
|
|
return map[string]string{
|
|
"Location": fmt.Sprintf("/groups/%s", res.id),
|
|
}
|
|
}
|
|
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res groupRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type groupPageRes struct {
|
|
pageRes
|
|
Groups []viewGroupRes `json:"groups"`
|
|
}
|
|
|
|
type pageRes struct {
|
|
Limit uint64 `json:"limit,omitempty"`
|
|
Offset uint64 `json:"offset,omitempty"`
|
|
Total uint64 `json:"total"`
|
|
Level uint64 `json:"level"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (res groupPageRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res groupPageRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res groupPageRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type deleteRes struct{}
|
|
|
|
func (res deleteRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res deleteRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res deleteRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type assignRes struct{}
|
|
|
|
func (res assignRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res assignRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res assignRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type unassignRes struct{}
|
|
|
|
func (res unassignRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res unassignRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res unassignRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type errorRes struct {
|
|
Err string `json:"error"`
|
|
}
|