github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+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  	if result := <-a.Srv.Store.Compliance().GetAll(page*perPage, perPage); result.Err != nil {
    20  		return nil, result.Err
    21  	} else {
    22  		return result.Data.(model.Compliances), nil
    23  	}
    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  	if result := <-a.Srv.Store.Compliance().Save(job); result.Err != nil {
    34  		return nil, result.Err
    35  	} else {
    36  		job = result.Data.(*model.Compliance)
    37  		a.Go(func() {
    38  			a.Compliance.RunComplianceJob(job)
    39  		})
    40  	}
    41  
    42  	return job, nil
    43  }
    44  
    45  func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
    46  	if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance || a.Compliance == nil {
    47  		return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
    48  	}
    49  
    50  	if result := <-a.Srv.Store.Compliance().Get(reportId); result.Err != nil {
    51  		return nil, result.Err
    52  	} else {
    53  		return result.Data.(*model.Compliance), nil
    54  	}
    55  }
    56  
    57  func (a *App) GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) {
    58  	if f, err := ioutil.ReadFile(*a.Config().ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip"); err != nil {
    59  		return nil, model.NewAppError("readFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusNotImplemented)
    60  	} else {
    61  		return f, nil
    62  	}
    63  }