summaryrefslogtreecommitdiffstats
path: root/app/compliance.go
blob: cb1eece702d2bebc741b693c6c3eae4de04cc0c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package app

import (
	"io/ioutil"

	"github.com/mattermost/platform/einterfaces"
	"github.com/mattermost/platform/model"
	"github.com/mattermost/platform/utils"
)

func GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError) {
	if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed || !*utils.License.Features.Compliance {
		return nil, model.NewLocAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "")
	}

	if result := <-Srv.Store.Compliance().GetAll(page*perPage, perPage); result.Err != nil {
		return nil, result.Err
	} else {
		return result.Data.(model.Compliances), nil
	}
}

func SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
	if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed || !*utils.License.Features.Compliance || einterfaces.GetComplianceInterface() == nil {
		return nil, model.NewLocAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "")
	}

	job.Type = model.COMPLIANCE_TYPE_ADHOC

	if result := <-Srv.Store.Compliance().Save(job); result.Err != nil {
		return nil, result.Err
	} else {
		job = result.Data.(*model.Compliance)
		go einterfaces.GetComplianceInterface().RunComplianceJob(job)
	}

	return job, nil
}

func GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
	if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed || !*utils.License.Features.Compliance || einterfaces.GetComplianceInterface() == nil {
		return nil, model.NewLocAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "")
	}

	if result := <-Srv.Store.Compliance().Get(reportId); result.Err != nil {
		return nil, result.Err
	} else {
		return result.Data.(*model.Compliance), nil
	}
}

func GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) {
	if f, err := ioutil.ReadFile(*utils.Cfg.ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip"); err != nil {
		return nil, model.NewLocAppError("readFile", "api.file.read_file.reading_local.app_error", nil, err.Error())

	} else {
		return f, nil
	}
}