github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/model/settings/init.go (about)

     1  package settings
     2  
     3  import (
     4  	"github.com/cozy/cozy-stack/model/cloudery"
     5  	"github.com/cozy/cozy-stack/model/instance"
     6  	"github.com/cozy/cozy-stack/model/token"
     7  	"github.com/cozy/cozy-stack/pkg/couchdb"
     8  	"github.com/cozy/cozy-stack/pkg/emailer"
     9  	"github.com/cozy/cozy-stack/pkg/prefixer"
    10  )
    11  
    12  var service *SettingsService
    13  
    14  type Service interface {
    15  	PublicName(db prefixer.Prefixer) (string, error)
    16  	GetInstanceSettings(inst prefixer.Prefixer) (*couchdb.JSONDoc, error)
    17  	SetInstanceSettings(inst prefixer.Prefixer, doc *couchdb.JSONDoc) error
    18  	StartEmailUpdate(inst *instance.Instance, cmd *UpdateEmailCmd) error
    19  	ResendEmailUpdate(inst *instance.Instance) error
    20  	ConfirmEmailUpdate(inst *instance.Instance, tok string) error
    21  	CancelEmailUpdate(inst *instance.Instance) error
    22  	GetExternalTies(inst *instance.Instance) (*ExternalTies, error)
    23  }
    24  
    25  func Init(
    26  	emailer emailer.Emailer,
    27  	instance instance.Service,
    28  	token token.Service,
    29  	cloudery cloudery.Service,
    30  ) *SettingsService {
    31  	storage := NewCouchdbStorage()
    32  
    33  	service = NewService(emailer, instance, token, cloudery, storage)
    34  
    35  	return service
    36  }
    37  
    38  // PublicName returns the settings' public name or a default one if missing
    39  //
    40  // Deprecated: Use [Service.PublicName] instead.
    41  func PublicName(db prefixer.Prefixer) (string, error) {
    42  	return service.PublicName(db)
    43  }
    44  
    45  // SettingsDocument returns the document with the settings of this instance
    46  //
    47  // Deprecated: Use [Service.GetInstanceSettings] instead.
    48  func SettingsDocument(inst prefixer.Prefixer) (*couchdb.JSONDoc, error) {
    49  	return service.GetInstanceSettings(inst)
    50  }