forked from tinode/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alow root user to find suspended topics and accounts
- Loading branch information
Showing
7 changed files
with
49 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2341,10 +2341,14 @@ func (a *adapter) SubsDelForUser(user t.Uid, hard bool) error { | |
|
||
// Returns a list of users who match given tags, such as "email:[email protected]" or "tel:+18003287448". | ||
// Searching the 'users.Tags' for the given tags using respective index. | ||
func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string) ([]t.Subscription, error) { | ||
func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string, activeOnly bool) ([]t.Subscription, error) { | ||
index := make(map[string]struct{}) | ||
var args []interface{} | ||
args = append(args, t.StateOK) | ||
stateConstraint := "" | ||
if activeOnly { | ||
args = append(args, t.StateOK) | ||
stateConstraint = "u.state=? AND " | ||
} | ||
allReq := t.FlattenDoubleSlice(req) | ||
for _, tag := range append(allReq, opt...) { | ||
args = append(args, tag) | ||
|
@@ -2353,7 +2357,7 @@ func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string) ([]t.Subscr | |
|
||
query := "SELECT u.id,u.createdat,u.updatedat,u.access,u.public,u.trusted,u.tags,COUNT(*) AS matches " + | ||
"FROM users AS u LEFT JOIN usertags AS t ON t.userid=u.id " + | ||
"WHERE u.state=? AND t.tag IN (?" + strings.Repeat(",?", len(allReq)+len(opt)-1) + ") " + | ||
"WHERE " + stateConstraint + "t.tag IN (?" + strings.Repeat(",?", len(allReq)+len(opt)-1) + ") " + | ||
"GROUP BY u.id,u.createdat,u.updatedat,u.access,u.public,u.trusted,u.tags " | ||
if len(allReq) > 0 { | ||
query += "HAVING" | ||
|
@@ -2429,10 +2433,14 @@ func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string) ([]t.Subscr | |
|
||
// Returns a list of topics with matching tags. | ||
// Searching the 'topics.Tags' for the given tags using respective index. | ||
func (a *adapter) FindTopics(req [][]string, opt []string) ([]t.Subscription, error) { | ||
func (a *adapter) FindTopics(req [][]string, opt []string, activeOnly bool) ([]t.Subscription, error) { | ||
index := make(map[string]struct{}) | ||
var args []interface{} | ||
args = append(args, t.StateOK) | ||
stateConstraint := "" | ||
if activeOnly { | ||
args = append(args, t.StateOK) | ||
stateConstraint = "u.state=? AND " | ||
} | ||
var allReq []string | ||
for _, el := range req { | ||
allReq = append(allReq, el...) | ||
|
@@ -2444,7 +2452,7 @@ func (a *adapter) FindTopics(req [][]string, opt []string) ([]t.Subscription, er | |
|
||
query := "SELECT t.name AS topic,t.createdat,t.updatedat,t.usebt,t.access,t.public,t.trusted,t.tags,COUNT(*) AS matches " + | ||
"FROM topics AS t LEFT JOIN topictags AS tt ON t.name=tt.topic " + | ||
"WHERE t.state=? AND tt.tag IN (?" + strings.Repeat(",?", len(allReq)+len(opt)-1) + ") " + | ||
"WHERE " + stateConstraint + "tt.tag IN (?" + strings.Repeat(",?", len(allReq)+len(opt)-1) + ") " + | ||
"GROUP BY t.name,t.createdat,t.updatedat,t.usebt,t.access,t.public,t.trusted,t.tags " | ||
if len(allReq) > 0 { | ||
query += "HAVING" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1863,7 +1863,7 @@ func (a *adapter) subsDelForUser(user t.Uid, hard bool) error { | |
|
||
// FindUsers returns a list of users who match given tags, such as "email:[email protected]" or "tel:+18003287448". | ||
// Searching the 'users.Tags' for the given tags using respective index. | ||
func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string) ([]t.Subscription, error) { | ||
func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string, activeOnly bool) ([]t.Subscription, error) { | ||
index := make(map[string]struct{}) | ||
allReq := t.FlattenDoubleSlice(req) | ||
var allTags []interface{} | ||
|
@@ -1888,9 +1888,11 @@ func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string) ([]t.Subscr | |
// Get users matched by tags, sort by number of matches from high to low. | ||
query := rdb.DB(a.dbName). | ||
Table("users"). | ||
GetAllByIndex("Tags", allTags...). | ||
Filter(rdb.Row.Field("State").Eq(t.StateOK)). | ||
Pluck("Id", "Access", "CreatedAt", "UpdatedAt", "Public", "Trusted", "Tags"). | ||
GetAllByIndex("Tags", allTags...) | ||
if activeOnly { | ||
query = query.Filter(rdb.Row.Field("State").Eq(t.StateOK)) | ||
} | ||
query = query.Pluck("Id", "Access", "CreatedAt", "UpdatedAt", "Public", "Trusted", "Tags"). | ||
Group("Id"). | ||
Ungroup(). | ||
Map(func(row rdb.Term) rdb.Term { | ||
|
@@ -1948,7 +1950,7 @@ func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string) ([]t.Subscr | |
|
||
// FindTopics returns a list of topics with matching tags. | ||
// Searching the 'topics.Tags' for the given tags using respective index. | ||
func (a *adapter) FindTopics(req [][]string, opt []string) ([]t.Subscription, error) { | ||
func (a *adapter) FindTopics(req [][]string, opt []string, activeOnly bool) ([]t.Subscription, error) { | ||
index := make(map[string]struct{}) | ||
var allReq []string | ||
for _, el := range req { | ||
|
@@ -1961,9 +1963,11 @@ func (a *adapter) FindTopics(req [][]string, opt []string) ([]t.Subscription, er | |
} | ||
query := rdb.DB(a.dbName). | ||
Table("topics"). | ||
GetAllByIndex("Tags", allTags...). | ||
Filter(rdb.Row.Field("State").Eq(t.StateOK)). | ||
Pluck("Id", "Access", "CreatedAt", "UpdatedAt", "UseBt", "Public", "Trusted", "Tags"). | ||
GetAllByIndex("Tags", allTags...) | ||
if activeOnly { | ||
query = query.Filter(rdb.Row.Field("State").Eq(t.StateOK)) | ||
} | ||
query = query.Pluck("Id", "Access", "CreatedAt", "UpdatedAt", "UseBt", "Public", "Trusted", "Tags"). | ||
Group("Id"). | ||
Ungroup(). | ||
Map(func(row rdb.Term) rdb.Term { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters