MCPcopy
hub / github.com/tinode/chat / initTopicNewGrp

Function initTopicNewGrp

server/init_topic.go:502–624  ·  view source on GitHub ↗

Create a new group topic

(t *Topic, sreg *ClientComMessage, isChan bool)

Source from the content-addressed store, hash-verified

500
501// Create a new group topic
502func initTopicNewGrp(t *Topic, sreg *ClientComMessage, isChan bool) error {
503 timestamp := types.TimeNow()
504 pktsub := sreg.Sub
505
506 t.cat = types.TopicCatGrp
507 t.isChan = isChan
508
509 // Generic topics have parameters stored in the topic object
510 t.owner = types.ParseUserId(sreg.AsUser)
511 authLevel := auth.Level(sreg.AuthLvl)
512
513 t.accessAuth = getDefaultAccess(t.cat, true, isChan)
514 t.accessAnon = getDefaultAccess(t.cat, false, isChan)
515
516 // Owner/creator gets full access to the topic. Owner may change the default modeWant through 'set'.
517 userData := perUserData{
518 modeGiven: types.ModeCFull,
519 modeWant: types.ModeCFull,
520 }
521
522 if pktsub.Set != nil {
523 // User sent initialization parameters
524 if pktsub.Set.Desc != nil {
525 if pktsub.Set.Desc.Trusted != nil && authLevel != auth.LevelRoot {
526 logs.Err.Println("hub: attempt to assign Trusted by non-ROOT", t.name)
527 return types.ErrPermissionDenied
528 }
529
530 if !isNullValue(pktsub.Set.Desc.Public) {
531 t.public = pktsub.Set.Desc.Public
532 }
533 if !isNullValue(pktsub.Set.Desc.Trusted) {
534 t.trusted = pktsub.Set.Desc.Trusted
535 }
536 if !isNullValue(pktsub.Set.Desc.Private) {
537 userData.private = pktsub.Set.Desc.Private
538 }
539
540 // set default access
541 if pktsub.Set.Desc.DefaultAcs != nil {
542 if authMode, anonMode, err := parseTopicAccess(pktsub.Set.Desc.DefaultAcs,
543 t.accessAuth, t.accessAnon); err != nil {
544
545 // Invalid access for one or both. Make it explicitly None
546 if authMode.IsInvalid() {
547 t.accessAuth = types.ModeNone
548 } else {
549 t.accessAuth = authMode
550 }
551 if anonMode.IsInvalid() {
552 t.accessAnon = types.ModeNone
553 } else {
554 t.accessAnon = anonMode
555 }
556 logs.Err.Println("hub: invalid access mode for topic '" + t.name + "': '" + err.Error() + "'")
557 } else if authMode.IsOwner() || anonMode.IsOwner() {
558 logs.Err.Println("hub: OWNER default access in topic", t.name)
559 t.accessAuth, t.accessAnon = authMode & ^types.ModeOwner, anonMode & ^types.ModeOwner

Callers 1

topicInitFunction · 0.85

Calls 15

GiveAccessMethod · 0.95
TimeNowFunction · 0.92
ParseUserIdFunction · 0.92
LevelTypeAlias · 0.92
getDefaultAccessFunction · 0.85
isNullValueFunction · 0.85
parseTopicAccessFunction · 0.85
normalizeTagsFunction · 0.85
restrictedTagsEqualFunction · 0.85
PrintlnMethod · 0.80
IsInvalidMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…