code.vegaprotocol.io/vega@v0.79.0/commands/create_referral_set.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package commands 17 18 import ( 19 "errors" 20 21 commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" 22 ) 23 24 func CheckCreateReferralSet(cmd *commandspb.CreateReferralSet) error { 25 return checkCreateReferralSet(cmd).ErrorOrNil() 26 } 27 28 func checkCreateReferralSet(cmd *commandspb.CreateReferralSet) Errors { 29 errs := NewErrors() 30 31 if cmd == nil { 32 return errs.FinalAddForProperty("create_referral_set", ErrIsRequired) 33 } 34 35 // Basically this command should be rejected if we are not creating a team 36 // but also not creating a referral set... 37 // just check if this command is ineffective... 38 if cmd.DoNotCreateReferralSet && !cmd.IsTeam { 39 return errs.FinalAddForProperty("create_referral_set", 40 errors.New("is ineffective")) 41 } 42 43 if cmd.IsTeam { 44 if cmd.Team == nil { 45 return errs.FinalAddForProperty("create_referral_set.team", ErrIsRequired) 46 } 47 48 if len(cmd.Team.Name) <= 0 { 49 errs.AddForProperty("create_referral_set.team.name", ErrIsRequired) 50 } else if len(cmd.Team.Name) > 100 { 51 errs.AddForProperty("create_referral_set.team.name", ErrMustBeLessThan100Chars) 52 } 53 54 if cmd.Team.AvatarUrl != nil && len(*cmd.Team.AvatarUrl) > 200 { 55 errs.AddForProperty("create_referral_set.team.avatar_url", ErrMustBeLessThan200Chars) 56 } 57 58 if cmd.Team.TeamUrl != nil && len(*cmd.Team.TeamUrl) > 200 { 59 errs.AddForProperty("create_referral_set.team.team_url", ErrMustBeLessThan200Chars) 60 } 61 62 if !cmd.Team.Closed && len(cmd.Team.AllowList) > 0 { 63 errs.AddForProperty("create_referral_set.team.allow_list", ErrCannotSetAllowListWhenTeamIsOpened) 64 } 65 } 66 67 return errs 68 }