github.com/nhannv/mattermost-server@v5.11.1+incompatible/app/compliance.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"io/ioutil"
     8  
     9  	"net/http"
    10  
    11  	"github.com/mattermost/mattermost-server/model"
    12  )
    13  
    14  func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError) {
    15  	if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance {
    16  		return nil, model.NewAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
    17  	}
    18  
    19  	result := <-a.Srv.Store.Compliance().GetAll(page*perPage, perPage)
    20  	if result.Err != nil {
    21  		return nil, result.Err
    22  	}
    23  	return result.Data.(model.Compliances), nil
    24  }
    25  
    26  func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
    27  	if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance || a.Compliance == nil {
    28  		return nil, model.NewAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
    29  	}
    30  
    31  	job.Type = model.COMPLIANCE_TYPE_ADHOC
    32  
    33  	result := <-a.Srv.Store.Compliance().Save(job)
    34  	if result.Err != nil {
    35  		return nil, result.Err
    36  	}
    37  
    38  	job = result.Data.(*model.Compliance)
    39  	a.Srv.Go(func() {
    40  		a.Compliance.RunComplianceJob(job)
    41  	})
    42  
    43  	return job, nil
    44  }
    45  
    46  func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
    47  	if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance || a.Compliance == nil {
    48  		return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
    49  	}
    50  
    51  	result := <-a.Srv.Store.Compliance().Get(reportId)
    52  	if result.Err != nil {
    53  		return nil, result.Err
    54  	}
    55  	return result.Data.(*model.Compliance), nil
    56  }
    57  
    58  func (a *App) GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) {
    59  	f, err := ioutil.ReadFile(*a.Config().ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip")
    60  	if err != nil {
    61  		return nil, model.NewAppError("readFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusNotImplemented)
    62  	}
    63  	return f, nil
    64  }