github.com/adacta-ru/mattermost-server/v6@v6.0.0/app/plugin_api_tests/test_update_user_active_plugin/main.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package main
     5  
     6  import (
     7  	"github.com/adacta-ru/mattermost-server/v6/app/plugin_api_tests"
     8  	"github.com/adacta-ru/mattermost-server/v6/model"
     9  	"github.com/adacta-ru/mattermost-server/v6/plugin"
    10  )
    11  
    12  type MyPlugin struct {
    13  	plugin.MattermostPlugin
    14  	configuration plugin_api_tests.BasicConfig
    15  }
    16  
    17  func (p *MyPlugin) OnConfigurationChange() error {
    18  	if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
    19  		return err
    20  	}
    21  	return nil
    22  }
    23  
    24  func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
    25  	uid := p.configuration.BasicUserId
    26  	if err := p.API.UpdateUserActive(uid, true); err != nil {
    27  		return nil, err.Error()
    28  	}
    29  
    30  	user, err := p.API.GetUser(uid)
    31  	if err != nil {
    32  		return nil, err.Error()
    33  	}
    34  
    35  	if int64(0) != user.DeleteAt {
    36  		return nil, "DeleteAt value is not 0"
    37  	}
    38  
    39  	if err = p.API.UpdateUserActive(uid, false); err != nil {
    40  		return nil, err.Error()
    41  	}
    42  
    43  	user, err = p.API.GetUser(uid)
    44  	if err != nil {
    45  		return nil, err.Error()
    46  	}
    47  	if user == nil {
    48  		return nil, "GetUser returned nil"
    49  	}
    50  
    51  	if int64(0) == user.DeleteAt {
    52  		return nil, "DeleteAt value is 0"
    53  	}
    54  
    55  	if err = p.API.UpdateUserActive(uid, true); err != nil {
    56  		return nil, err.Error()
    57  	}
    58  
    59  	if err = p.API.UpdateUserActive(uid, true); err != nil {
    60  		return nil, err.Error()
    61  	}
    62  
    63  	user, err = p.API.GetUser(uid)
    64  	if err != nil {
    65  		return nil, err.Error()
    66  	}
    67  
    68  	if int64(0) != user.DeleteAt {
    69  		return nil, "DeleteAt value is not 0"
    70  	}
    71  
    72  	return nil, "OK"
    73  }
    74  
    75  func main() {
    76  	plugin.ClientMain(&MyPlugin{})
    77  }