// AddRwUser add a read / write user on selected topic func (t *TopicsController) AddRwUser(ctx *gin.Context) { var paramJSON tat.ParamTopicUserJSON ctx.Bind(¶mJSON) topic, e := t.preCheckUser(ctx, ¶mJSON) if e != nil { return } err := topicDB.AddRwUser(topic, getCtxUsername(ctx), paramJSON.Username, paramJSON.Recursive) if err != nil { log.Errorf("Error while adding read write user: %s", err) ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } ctx.JSON(http.StatusCreated, "") }
// SetParam update Topic Parameters : MaxLength, CanForeceDate, CanUpdateMsg, CanDeleteMsg, CanUpdateAllMsg, CanDeleteAllMsg, AdminCanDeleteAllMsg // admin only, except on Private topic func (t *TopicsController) SetParam(ctx *gin.Context) { var paramsBind paramsJSON ctx.Bind(¶msBind) topic := &tat.Topic{} var errFind, err error if strings.HasPrefix(paramsBind.Topic, "/Private/"+getCtxUsername(ctx)) { topic, errFind = topicDB.FindByTopic(paramsBind.Topic, false, false, false, nil) if errFind != nil { ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error while fetching topic /Private/" + getCtxUsername(ctx)}) return } } else { topic, err = t.preCheckUserAdminOnTopic(ctx, paramsBind.Topic) if err != nil { ctx.JSON(tat.Error(err)) return } } for _, p := range paramsBind.Parameters { if strings.HasPrefix(p.Key, tat.HookTypeKafka) && !isTatAdmin(ctx) { ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Only Tat Admin can use tathook-kafka"}) return } } err = topicDB.SetParam(topic, getCtxUsername(ctx), paramsBind.Recursive, paramsBind.MaxLength, paramsBind.CanForceDate, paramsBind.CanUpdateMsg, paramsBind.CanDeleteMsg, paramsBind.CanUpdateAllMsg, paramsBind.CanDeleteAllMsg, paramsBind.AdminCanUpdateAllMsg, paramsBind.AdminCanDeleteAllMsg, paramsBind.IsAutoComputeTags, paramsBind.IsAutoComputeLabels, paramsBind.Parameters) // add tat2xmpp_username RO or RW on this topic if a key is xmpp for _, p := range paramsBind.Parameters { if strings.HasPrefix(p.Key, tat.HookTypeXMPPOut) { found := false for _, u := range topic.ROUsers { if u == viper.GetString("tat2xmpp_username") { found = true } } for _, u := range topic.RWUsers { if u == viper.GetString("tat2xmpp_username") { found = true } } if !found { if errf := topicDB.AddRoUser(topic, getCtxUsername(ctx), viper.GetString("tat2xmpp_username"), false); errf != nil { log.Errorf("Error while adding read only user tat2xmpp_username: %s", errf) ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } } } else if strings.HasPrefix(p.Key, tat.HookTypeXMPP) { found := false for _, u := range topic.RWUsers { if u == viper.GetString("tat2xmpp_username") { found = true } } if !found { if errf := topicDB.AddRwUser(topic, getCtxUsername(ctx), viper.GetString("tat2xmpp_username"), false); errf != nil { log.Errorf("Error while adding read write user tat2xmpp_username: %s", errf) ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } } } } if err != nil { log.Errorf("Error while setting parameters: %s", err) ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } ctx.JSON(http.StatusCreated, gin.H{"info": fmt.Sprintf("Topic %s updated", topic.Topic)}) }