github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/meeting/v1/users/requests.go (about)

     1  package users
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/chnsz/golangsdk"
     7  )
     8  
     9  type CreateOpts struct {
    10  	// Enterprise user name.
    11  	// maxLength: 64
    12  	// minLength: 1
    13  	Name string `json:"name" required:"true"`
    14  	// HUAWEI CLOUD meeting user account, if it is carried, it shall prevail; otherwise, it will be automatically generated in the background. The account is unique in the whole system
    15  	// The account number can only contain uppercase and lowercase letters, numbers, _, -, ., and @ symbols, and cannot be pure numbers and a . sign after @.
    16  	// maxLength: 64
    17  	// minLength: 0
    18  	// Description: used for account/password authentication
    19  	Account string `json:"account,omitempty"`
    20  	// Third-party User ID
    21  	// Description: used in App ID authentication mode
    22  	ThirdAccount string `json:"thirdAccount,omitempty"`
    23  	// The country the phone number belongs to.
    24  	// Default: chinaPR.
    25  	// maxLength: 255
    26  	// minLength: 0
    27  	Country string `json:"country,omitempty"`
    28  	// Department ID, if not carried, the default root department.
    29  	// Default: 1
    30  	// maxLength: 32
    31  	// minLength: 0
    32  	DeptCode string `json:"deptCode,omitempty"`
    33  	// Description.
    34  	// maxLength: 128
    35  	// minLength: 0
    36  	Description string `json:"desc,omitempty"`
    37  	// Email.
    38  	// maxLength: 255
    39  	// minLength: 0
    40  	// Unified email format, if the enterprise turns off the SMS function, the email is required,
    41  	// otherwise the mobile phone and email are required.
    42  	Email string `json:"email,omitempty"`
    43  	// The English name of the enterprise user.
    44  	// maxLength: 64
    45  	// minLength: 0
    46  	EnglishName string `json:"englishName,omitempty"`
    47  	// User function bits.
    48  	Function *UserFunction `json:"function,omitempty"`
    49  	// Mobile phone number, country code must be added.
    50  	// For example, the mobile phone in mainland China is "+86xxxxxxxxxxxx".
    51  	// When filling in the mobile phone number, the "country" parameter is required.
    52  	// Only pure numbers are allowed for mobile phone numbers.
    53  	// Description: Fill in at least one mobile phone number or email address.
    54  	// maxLength: 32
    55  	// minLength: 0
    56  	Phone string `json:"phone,omitempty"`
    57  	// Whether to hide the phone number.
    58  	// When set to true, the mobile phone number will not be displayed in the address book and conference.
    59  	// Default: false
    60  	HidePhone *bool `json:"hidePhone,omitempty"`
    61  	// The password of the enterprise user account. If it is carried, the actual carrying shall prevail.
    62  	// Otherwise, it will be generated by default in the background, and the password must meet the following
    63  	// requirements:
    64  	//   1, 8-32 bits
    65  	//   2. It cannot be consistent with the positive and reverse order of the account
    66  	//   3. Contains at least two character types: lowercase letters, uppercase letters, numbers,
    67  	//      special characters (` ~ ! @ # $ % ^ & * ( ) - _ = + | [ { } ] ; : " ,' < . > / ?)
    68  	Password string `json:"pwd,omitempty"`
    69  	// Whether to send email and SMS notifications for account opening.
    70  	// 0: do not send
    71  	// Send without filling in or other values, and send by default
    72  	// maxLength: 32
    73  	// minLength: 0
    74  	SendNotify string `json:"sendNotify,omitempty"`
    75  	// Signature.
    76  	// maxLength: 512
    77  	// minLength: 0
    78  	Signature string `json:"signature,omitempty"`
    79  	// Address book sorting level, the lower the serial number, the higher the priority.
    80  	// Default: 10000
    81  	// maximum: 10000
    82  	//minimum: 1
    83  	SortLevel int `json:"sortLevel,omitempty"`
    84  	// user status.
    85  	//   0: normal
    86  	//   1: disable
    87  	// default: 0
    88  	Status *int `json:"status,omitempty"`
    89  	// Position (title).
    90  	// maxLength: 32
    91  	// minLength: 0
    92  	Title string `json:"title,omitempty"`
    93  	// Authorization token.
    94  	Token string `json:"-" required:"true"`
    95  }
    96  
    97  type UserFunction struct {
    98  	// Whether to enable the intelligent collaborative whiteboard function.
    99  	// If it is enabled, it means that the account is used for the intelligent collaborative whiteboard,
   100  	// which occupies the resources of the enterprise intelligent collaborative whiteboard.
   101  	// If the resources are insufficient, it cannot be opened.
   102  	// Default: false.
   103  	EnableRoom bool `json:"enableRoom,omitempty"`
   104  }
   105  
   106  // Create is a method to create a new (enterprise) user using given parameters.
   107  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*User, error) {
   108  	b, err := golangsdk.BuildRequestBody(opts, "")
   109  	if err != nil {
   110  		return nil, err
   111  	}
   112  
   113  	var r User
   114  	_, err = c.Post(rootURL(c), b, &r, &golangsdk.RequestOpts{
   115  		MoreHeaders: map[string]string{
   116  			"Content-Type":   "application/json;charset=UTF-8",
   117  			"X-Access-Token": opts.Token,
   118  		},
   119  	})
   120  	return &r, err
   121  }
   122  
   123  type GetOpts struct {
   124  	// account account.
   125  	// If it is an account/password authentication method, it refers to the HUAWEI CLOUD conference account
   126  	// If it is the App ID authentication method, it refers to the third-party User ID
   127  	Account string `json:"-"`
   128  	// Account type.
   129  	//   0: HUAWEI CLOUD conference account. Used for account/password authentication.
   130  	//   1: Third-party User ID, used for App ID authentication.
   131  	// default 0
   132  	AccountType int `q:"accountType"`
   133  	// Authorization token.
   134  	Token string `json:"-"`
   135  }
   136  
   137  // Get is a method to create a new (enterprise) user using given parameters.
   138  func Get(c *golangsdk.ServiceClient, opts GetOpts) (*User, error) {
   139  	if opts.Account == "" || opts.Token == "" {
   140  		return nil, fmt.Errorf("The account and authorization token must be supported.")
   141  	}
   142  
   143  	url := resourceURL(c, opts.Account)
   144  	query, err := golangsdk.BuildQueryString(opts)
   145  	if err != nil {
   146  		return nil, err
   147  	}
   148  	url += query.String()
   149  
   150  	var r User
   151  	_, err = c.Get(url, &r, &golangsdk.RequestOpts{
   152  		MoreHeaders: map[string]string{
   153  			"Content-Type":   "application/json;charset=UTF-8",
   154  			"X-Access-Token": opts.Token,
   155  		},
   156  	})
   157  	return &r, err
   158  }
   159  
   160  type UpdateOpts struct {
   161  	// account account.
   162  	// If it is an account/password authentication method, it refers to the HUAWEI CLOUD conference account
   163  	// If it is the App ID authentication method, it refers to the third-party User ID
   164  	Account string `json:"-" required:"true"`
   165  	// Account type.
   166  	//   0: HUAWEI CLOUD conference account. Used for account/password authentication.
   167  	//   1: Third-party User ID, used for App ID authentication.
   168  	// default 0
   169  	AccountType *int `q:"accountType"`
   170  	// The country the phone number belongs to.
   171  	// Default: chinaPR.
   172  	// maxLength: 255
   173  	// minLength: 0
   174  	Country string `json:"country,omitempty"`
   175  	// Department ID, if not carried, the default root department.
   176  	// Default: 1
   177  	// maxLength: 32
   178  	// minLength: 0
   179  	DeptCode *string `json:"deptCode,omitempty"`
   180  	// Description.
   181  	// maxLength: 128
   182  	// minLength: 0
   183  	Description *string `json:"desc,omitempty"`
   184  	// Email.
   185  	// maxLength:255
   186  	// minLength:0
   187  	Email *string `json:"email,omitempty"`
   188  	// The English name of the enterprise user.
   189  	// maxLength: 64
   190  	// minLength: 0
   191  	EnglishName *string `json:"englishName,omitempty"`
   192  	// Whether to hide the phone number.
   193  	// Default: false
   194  	HidePhone *bool `json:"hidePhone,omitempty"`
   195  	// Enterprise user name.
   196  	// maxLength: 64
   197  	// minLength: 1
   198  	Name string `json:"name,omitempty"`
   199  	// Mobile phone number, country code must be added.
   200  	// For example, the mobile phone in mainland China is "+86xxxxxxxxxxxx".
   201  	// When filling in the mobile phone number, the "country" parameter is required.
   202  	// Only pure numbers are allowed for mobile phone numbers.
   203  	// Description: Fill in at least one mobile phone number or email address.
   204  	// maxLength: 32
   205  	// minLength: 0
   206  	Phone string `json:"phone,omitempty"`
   207  	// Signature.
   208  	// maxLength:512
   209  	// minLength:0
   210  	Signature *string `json:"signature,omitempty"`
   211  	// Address book sorting level, the lower the serial number, the higher the priority.
   212  	// Default: 10000
   213  	// maximum: 10000
   214  	//minimum: 1
   215  	SortLevel int `json:"sortLevel,omitempty"`
   216  	// user status.
   217  	// 0: normal
   218  	// 1: disable
   219  	// default: 0
   220  	Status *int `json:"status,omitempty"`
   221  	// Position (Title).
   222  	// maxLength: 32
   223  	// minLength: 0
   224  	Title *string `json:"title,omitempty"`
   225  	// Personal meeting ID, if not carried, it will be generated by default in the background.
   226  	// maxLength: 32
   227  	// minLength: 0
   228  	VmrId *string `json:"vmrId,omitempty"`
   229  	// Authorization token.
   230  	Token string `json:"-" required:"true"`
   231  }
   232  
   233  // Update is a method to create a new (enterprise) user using given parameters.
   234  func Update(c *golangsdk.ServiceClient, opts UpdateOpts) (*User, error) {
   235  	b, err := golangsdk.BuildRequestBody(opts, "")
   236  	if err != nil {
   237  		return nil, err
   238  	}
   239  
   240  	var r User
   241  	_, err = c.Put(resourceURL(c, opts.Account), b, &r, &golangsdk.RequestOpts{
   242  		MoreHeaders: map[string]string{
   243  			"Content-Type":   "application/json;charset=UTF-8",
   244  			"X-Access-Token": opts.Token,
   245  		},
   246  	})
   247  	return &r, err
   248  }
   249  
   250  type DeleteOpts struct {
   251  	// Account type.
   252  	//   0: HUAWEI CLOUD conference account. Used for account/password authentication.
   253  	//   1: Third-party User ID, used for App ID authentication.
   254  	// default 0
   255  	AccountType *int `q:"accountType"`
   256  	// Authorization token.
   257  	Token string `json:"-"`
   258  }
   259  
   260  // BatchDelete is a method to delete all (enterprise) users using given list.
   261  func BatchDelete(c *golangsdk.ServiceClient, opts DeleteOpts, accounts []string) error {
   262  	url := deleteURL(c)
   263  	query, err := golangsdk.BuildQueryString(opts)
   264  	if err != nil {
   265  		return err
   266  	}
   267  	url += query.String()
   268  
   269  	if opts.Token == "" {
   270  		return fmt.Errorf("The authorization token must be supported.")
   271  	}
   272  
   273  	_, err = c.Post(url, accounts, nil, &golangsdk.RequestOpts{
   274  		MoreHeaders: map[string]string{
   275  			"Content-Type":   "application/json;charset=UTF-8",
   276  			"X-Access-Token": opts.Token,
   277  		},
   278  	})
   279  	return err
   280  }