Skip to content

Commit

Permalink
start reporting default access in fnd results
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Oct 11, 2018
1 parent 33ab495 commit 32734c3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
16 changes: 8 additions & 8 deletions server/db/mysql/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ func (a *adapter) FindUsers(uid t.Uid, req, opt []string) ([]t.Subscription, err
index[tag] = struct{}{}
}

query := "SELECT u.id,u.createdat,u.updatedat,u.public,u.tags,COUNT(*) AS matches " +
query := "SELECT u.id,u.createdat,u.updatedat,u.access,u.public,u.tags,COUNT(*) AS matches " +
"FROM users AS u LEFT JOIN usertags AS t ON t.userid=u.id " +
"WHERE t.tag IN (?" + strings.Repeat(",?", len(req)+len(opt)-1) + ") " +
"GROUP BY u.id,u.createdat,u.updatedat,u.public,u.tags "
Expand All @@ -1297,13 +1297,14 @@ func (a *adapter) FindUsers(uid t.Uid, req, opt []string) ([]t.Subscription, err

var userId int64
var public interface{}
var access t.DefaultAccess
var userTags t.StringSlice
var ignored int
var sub t.Subscription
var subs []t.Subscription
thisUser := store.DecodeUid(uid)
for rows.Next() {
if err = rows.Scan(&userId, &sub.CreatedAt, &sub.UpdatedAt, &public, &userTags, &ignored); err != nil {
if err = rows.Scan(&userId, &sub.CreatedAt, &sub.UpdatedAt, &access, &public, &userTags, &ignored); err != nil {
subs = nil
break
}
Expand All @@ -1314,8 +1315,7 @@ func (a *adapter) FindUsers(uid t.Uid, req, opt []string) ([]t.Subscription, err
}
sub.User = store.EncodeUid(userId).String()
sub.SetPublic(fromJSON(public))
// TODO: maybe report default access to user
// sub.SetDefaultAccess(user.Access.Auth, user.Access.Anon)
sub.SetDefaultAccess(access.Auth, access.Anon)
foundTags := make([]string, 0, 1)
for _, tag := range userTags {
if _, ok := index[tag]; ok {
Expand All @@ -1341,7 +1341,7 @@ func (a *adapter) FindTopics(req, opt []string) ([]t.Subscription, error) {
index[tag] = struct{}{}
}

query := "SELECT t.name AS topic,t.createdat,t.updatedat,t.public,t.tags,COUNT(*) AS matches " +
query := "SELECT t.name AS topic,t.createdat,t.updatedat,t.access,t.public,t.tags,COUNT(*) AS matches " +
"FROM topics AS t LEFT JOIN topictags AS tt ON t.name=tt.topic " +
"WHERE tt.tag IN (?" + strings.Repeat(",?", len(req)+len(opt)-1) + ") " +
"GROUP BY t.name,t.createdat,t.updatedat,t.public,t.tags "
Expand All @@ -1359,20 +1359,20 @@ func (a *adapter) FindTopics(req, opt []string) ([]t.Subscription, error) {
return nil, err
}

var access t.DefaultAccess
var public interface{}
var topicTags t.StringSlice
var ignored int
var sub t.Subscription
var subs []t.Subscription
for rows.Next() {
if err = rows.Scan(&sub.Topic, &sub.CreatedAt, &sub.UpdatedAt, &public, &topicTags, &ignored); err != nil {
if err = rows.Scan(&sub.Topic, &sub.CreatedAt, &sub.UpdatedAt, &access, &public, &topicTags, &ignored); err != nil {
subs = nil
break
}

sub.SetPublic(fromJSON(public))
// TODO: maybe report default access to user
// sub.SetDefaultAccess(user.Access.Auth, user.Access.Anon)
sub.SetDefaultAccess(access.Auth, access.Anon)
foundTags := make([]string, 0, 1)
for _, tag := range topicTags {
if _, ok := index[tag]; ok {
Expand Down
6 changes: 2 additions & 4 deletions server/db/rethinkdb/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,7 @@ func (a *adapter) FindUsers(uid t.Uid, req, opt []string) ([]t.Subscription, err
sub.UpdatedAt = user.UpdatedAt
sub.User = user.Id
sub.SetPublic(user.Public)
// TODO: maybe report default access to user
// sub.SetDefaultAccess(user.Access.Auth, user.Access.Anon)
sub.SetDefaultAccess(user.Access.Auth, user.Access.Anon)
tags := make([]string, 0, 1)
for _, tag := range user.Tags {
if _, ok := index[tag]; ok {
Expand Down Expand Up @@ -1138,8 +1137,7 @@ func (a *adapter) FindTopics(req, opt []string) ([]t.Subscription, error) {
sub.UpdatedAt = topic.UpdatedAt
sub.Topic = topic.Id
sub.SetPublic(topic.Public)
// TODO: maybe report default access to user
// sub.SetDefaultAccess(user.Access.Auth, user.Access.Anon)
sub.SetDefaultAccess(topic.Access.Auth, topic.Access.Anon)
tags := make([]string, 0, 1)
for _, tag := range topic.Tags {
if _, ok := index[tag]; ok {
Expand Down
16 changes: 13 additions & 3 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ func (t *Topic) run(hub *Hub) {
case meta := <-t.meta:
// Request to get/set topic metadata
asUid := types.ParseUserId(meta.pkt.from)
authLevel := auth.Level(meta.pkt.authLvl)
switch {
case meta.pkt.Get != nil:
// Get request
Expand All @@ -492,7 +493,7 @@ func (t *Topic) run(hub *Hub) {
}
}
if meta.what&constMsgMetaSub != 0 {
if err := t.replyGetSub(meta.sess, asUid, meta.pkt.Get.Id, meta.pkt.Get.Sub); err != nil {
if err := t.replyGetSub(meta.sess, asUid, authLevel, meta.pkt.Get.Id, meta.pkt.Get.Sub); err != nil {
log.Printf("topic[%s] meta.Get.Sub failed: %s", t.name, err)
}
}
Expand Down Expand Up @@ -610,6 +611,7 @@ func (t *Topic) run(hub *Hub) {
// Session subscribed to a topic, created == true if topic was just created and {pres} needs to be announced
func (t *Topic) handleSubscription(h *Hub, sreg *sessionJoin) error {
asUid := types.ParseUserId(sreg.pkt.from)
authLevel := auth.Level(sreg.pkt.authLvl)

msgsub := sreg.pkt.Sub
getWhat := 0
Expand Down Expand Up @@ -694,7 +696,7 @@ func (t *Topic) handleSubscription(h *Hub, sreg *sessionJoin) error {

if getWhat&constMsgMetaSub != 0 {
// Send get.sub response as a separate {meta} packet
if err := t.replyGetSub(sreg.sess, asUid, sreg.pkt.id, msgsub.Get.Sub); err != nil {
if err := t.replyGetSub(sreg.sess, asUid, authLevel, sreg.pkt.id, msgsub.Get.Sub); err != nil {
log.Printf("topic[%s] handleSubscription Get.Sub failed: %v", t.name, err)
}
}
Expand Down Expand Up @@ -1438,7 +1440,7 @@ func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, set *MsgClientSet)

// replyGetSub is a response to a get.sub request on a topic - load a list of subscriptions/subscribers,
// send it just to the session as a {meta} packet
func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, id string, req *MsgGetOpts) error {
func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, authLevel auth.Level, id string, req *MsgGetOpts) error {
now := types.TimeNow()

if req != nil && (req.SinceId != 0 || req.BeforeId != 0) {
Expand Down Expand Up @@ -1626,6 +1628,14 @@ func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, id string, req *MsgG
mts.Acs.Want = sub.ModeWant.String()
mts.Acs.Given = sub.ModeGiven.String()
}
} else if defacs := sub.GetDefaultAccess(); defacs != nil {
// Topic 'fnd'
switch authLevel {
case auth.LevelAnon:
mts.Acs.Mode = defacs.Anon.String()
case auth.LevelAuth, auth.LevelRoot:
mts.Acs.Mode = defacs.Auth.String()
}
}

// Returning public and private only if they have changed since ifModified
Expand Down

0 comments on commit 32734c3

Please sign in to comment.