[MM-43917] Cloud Freemium limits API: messages/posts (#20152)

* WIP - Add api and app funcs

* Add test cases

* Add utils testcases

* Exclude deleted posts

* Add doc for func

* Move api from cloud to usage

* Allow api access to authenticated users

* Change int to int64

* Fix lint issue

* Simplify err check

Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com>

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com>
Этот коммит содержится в:
Vishal
2022-05-17 17:00:40 +05:30
коммит произвёл GitHub
родитель 9c851e996c
Коммит fd703a365b
29 изменённых файлов: 341 добавлений и 43 удалений

Просмотреть файл

@@ -324,6 +324,10 @@ func (c *Client4) cloudRoute() string {
return "/cloud"
}
func (c *Client4) usageRoute() string {
return "/usage"
}
func (c *Client4) testEmailRoute() string {
return "/email/test"
}
@@ -8078,3 +8082,18 @@ func (c *Client4) GetAppliedSchemaMigrations() ([]AppliedMigration, *Response, e
}
return list, BuildResponse(r), nil
}
// Usage Section
// GetPostsUsage returns rounded off total usage of posts for the instance
func (c *Client4) GetPostsUsage() (*PostsUsage, *Response, error) {
r, err := c.DoAPIGet(c.usageRoute()+"/posts", "")
if err != nil {
return nil, BuildResponse(r), err
}
defer closeBody(r)
var usage *PostsUsage
err = json.NewDecoder(r.Body).Decode(&usage)
return usage, BuildResponse(r), err
}

Просмотреть файл

@@ -274,6 +274,14 @@ type GetPostsOptions struct {
Direction string // Only accepts up|down. Indicates the order in which to send the items.
}
type PostCountOptions struct {
// Only include posts on a specific team. "" for any team.
TeamId string
MustHaveFile bool
MustHaveHashtag bool
ExcludeDeleted bool
}
func (o *Post) Etag() string {
return Etag(o.Id, o.UpdateAt)
}

8
model/usage.go Обычный файл
Просмотреть файл

@@ -0,0 +1,8 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
type PostsUsage struct {
Count int64 `json:"count"`
}