diff options
author | JoramWilander <jwawilander@gmail.com> | 2016-02-04 13:00:03 -0500 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2016-02-04 13:35:44 -0500 |
commit | e45282deaa1d78d7ff3a125e9fd11e3fdc120b07 (patch) | |
tree | c116beae6abed1b703c481dfd63df36d689a8af5 /api | |
parent | 7e8389cd0538fb6aff3931fb23714158d3f24449 (diff) | |
download | chat-e45282deaa1d78d7ff3a125e9fd11e3fdc120b07.tar.gz chat-e45282deaa1d78d7ff3a125e9fd11e3fdc120b07.tar.bz2 chat-e45282deaa1d78d7ff3a125e9fd11e3fdc120b07.zip |
Move license storage to database
Diffstat (limited to 'api')
-rw-r--r-- | api/license.go | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/api/license.go b/api/license.go index 4077c0e46..23e7946c8 100644 --- a/api/license.go +++ b/api/license.go @@ -81,9 +81,24 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := writeFileLocally(data, utils.LicenseLocation()); err != nil { - c.LogAudit("failed - could not save license file") - c.Err = model.NewLocAppError("addLicense", "api.license.add_license.save.app_error", nil, "path="+utils.LicenseLocation()) + record := &model.LicenseRecord{} + record.Id = license.Id + record.Bytes = string(data) + rchan := Srv.Store.License().Save(record) + + sysVar := &model.System{} + sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID + sysVar.Value = license.Id + schan := Srv.Store.System().SaveOrUpdate(sysVar) + + if result := <-rchan; result.Err != nil { + c.Err = model.NewLocAppError("addLicense", "api.license.add_license.save.app_error", nil, "err="+result.Err.Error()) + utils.RemoveLicense() + return + } + + if result := <-schan; result.Err != nil { + c.Err = model.NewLocAppError("addLicense", "api.license.add_license.save_active.app_error", nil, "") utils.RemoveLicense() return } @@ -100,9 +115,14 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("") - if ok := utils.RemoveLicense(); !ok { - c.LogAudit("failed - could not remove license file") - c.Err = model.NewLocAppError("removeLicense", "api.license.remove_license.remove.app_error", nil, "") + utils.RemoveLicense() + + sysVar := &model.System{} + sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID + sysVar.Value = "" + + if result := <-Srv.Store.System().Update(sysVar); result.Err != nil { + c.Err = model.NewLocAppError("removeLicense", "api.license.remove_license.update.app_error", nil, "") return } |