fixed queries and added change permissions
This commit is contained in:
parent
106b7326f2
commit
01eedc6246
@ -21,11 +21,14 @@ type ImageData struct {
|
|||||||
DisplayName string
|
DisplayName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertImageToImageData(imageSummary image.Summary) ImageData {
|
func convertImageToImageData(imageSummary image.Summary) *ImageData {
|
||||||
|
if len(imageSummary.RepoTags) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
imageId := imageSummary.RepoTags[0]
|
imageId := imageSummary.RepoTags[0]
|
||||||
splitImageId := strings.Split(imageId, ":")
|
splitImageId := strings.Split(imageId, ":")
|
||||||
imageName, imageVersion := splitImageId[0], splitImageId[1]
|
imageName, imageVersion := splitImageId[0], splitImageId[1]
|
||||||
return ImageData{
|
return &ImageData{
|
||||||
Id: imageId,
|
Id: imageId,
|
||||||
Name: imageName,
|
Name: imageName,
|
||||||
Version: imageVersion,
|
Version: imageVersion,
|
||||||
@ -38,9 +41,15 @@ func (con Connection) GetImages(c *gin.Context) {
|
|||||||
c.AbortWithError(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
imagesData := make([]ImageData, len(images))
|
imagesData := make([]ImageData, 0, len(images))
|
||||||
for index, imageSummary := range images {
|
|
||||||
imagesData[index] = convertImageToImageData(imageSummary)
|
for _, imageSummary := range images {
|
||||||
|
imageData := convertImageToImageData(imageSummary)
|
||||||
|
if imageData == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
imagesData = append(imagesData, *imageData)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, imagesData)
|
c.JSON(200, imagesData)
|
||||||
|
@ -609,6 +609,7 @@ func (con Connection) UpdateServer(ctx *gin.Context) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.AbortWithError(500, err)
|
ctx.AbortWithError(500, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOperation := bson.M{}
|
updateOperation := bson.M{}
|
||||||
@ -790,6 +791,34 @@ func (con Connection) GetServerUserPermissions(ctx *gin.Context) {
|
|||||||
ctx.JSON(200, serverData.UserPermissions[claims.(*auth.AuthClaims).Username])
|
ctx.JSON(200, serverData.UserPermissions[claims.(*auth.AuthClaims).Username])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SetServerUserPermissionsRequest struct {
|
||||||
|
Username string
|
||||||
|
Permissions models.Permission
|
||||||
|
}
|
||||||
|
|
||||||
|
func (con Connection) SetServerUserPermissions(ctx *gin.Context) {
|
||||||
|
server_id := ctx.Param("server_id")
|
||||||
|
if server_id == "" {
|
||||||
|
ctx.AbortWithStatus(500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var request SetServerUserPermissionsRequest
|
||||||
|
err := json.NewDecoder(ctx.Request.Body).Decode(&request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ctx.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = con.databaseConnection.Database("Backend").Collection("Servers").UpdateOne(context.TODO(), bson.D{{Key: "Id", Value: server_id}}, bson.D{{Key: "$set", Value: bson.D{{Key: fmt.Sprintf("UserPermissions.%s", request.Username), Value: request.Permissions}}}})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ctx.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(200, "OK")
|
||||||
|
}
|
||||||
|
|
||||||
func LoadGroup(group *gin.RouterGroup, mongo_client *mongo.Client, config models.GlobalConfig) {
|
func LoadGroup(group *gin.RouterGroup, mongo_client *mongo.Client, config models.GlobalConfig) {
|
||||||
apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -808,4 +837,5 @@ func LoadGroup(group *gin.RouterGroup, mongo_client *mongo.Client, config models
|
|||||||
group.PATCH("/:server_id", auth.AuthorizedTo(models.Admin, connection.serverAuthorized(models.Admin)), connection.UpdateServer)
|
group.PATCH("/:server_id", auth.AuthorizedTo(models.Admin, connection.serverAuthorized(models.Admin)), connection.UpdateServer)
|
||||||
group.POST("/:server_id/browse", auth.AuthorizedTo(models.Browse, connection.serverAuthorized(models.Admin)), connection.BrowseServer)
|
group.POST("/:server_id/browse", auth.AuthorizedTo(models.Browse, connection.serverAuthorized(models.Admin)), connection.BrowseServer)
|
||||||
group.GET("/:server_id/permissions", auth.AuthorizedTo(models.Browse, connection.serverAuthorized(models.Admin)), connection.GetServerUserPermissions)
|
group.GET("/:server_id/permissions", auth.AuthorizedTo(models.Browse, connection.serverAuthorized(models.Admin)), connection.GetServerUserPermissions)
|
||||||
|
group.POST("/:server_id/permissions", auth.AuthorizedTo(models.Browse, connection.serverAuthorized(models.Admin)), connection.SetServerUserPermissions)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user