Beispiel #1
0
func CanPost(db *periwinkle.Tx, group *backend.Group, userID string) bool {
	subscribed := backend.IsSubscribed(db, userID, *group)
	//  I'm assuming we wont have time to implement moderating
	//moderate := false
	if !backend.IsAdmin(db, userID, *group) {
		if group.PostPublic == 1 {
			if subscribed == 0 {
				return false
			}
			if group.PostConfirmed == 1 && subscribed == 1 {
				return false
			}
			if group.PostMember == 1 {
				return false
			} /*  Probably not going to have time to implement moderating messages
			            if group.PostConfirmed == 2 && subscribed == 1 {
			                    moderate = true
			            } else if group.PostMember == 2 && subscribed == 2 {
			                    moderate = true
			            }
			    } else if group.PostPublic == 2 {
			            if subscribed == 0 {
			                    moderate = true
			            } else if group.PostConfirmed == 2 && subscribed == 1 {
			                    moderate = true
			            } else if group.PostMember == 2 && subscribed == 2 {
			                    moderate = true
			            }*/
		}
	}
	return true
}
Beispiel #2
0
func (d dirGroups) Subentity(name string, req he.Request) he.Entity {
	db := req.Things["db"].(*periwinkle.Tx)
	sess := req.Things["session"].(*backend.Session)
	grp := backend.GetGroupByID(db, name)
	if grp.ReadPublic == 1 {
		subscribed := backend.IsSubscribed(db, sess.UserID, *grp)
		if (grp.ReadConfirmed == 1 && subscribed == 1) || subscribed == 0 {
			return nil
		}
	}
	return (*group)(grp)
}
Beispiel #3
0
func (o *group) Methods() map[string]func(he.Request) he.Response {
	return map[string]func(he.Request) he.Response{
		"GET": func(req he.Request) he.Response {
			var enum Enumerategroup
			enum = EnumerateGroup(o)
			return rfc7231.StatusOK(he.NetJSON{Data: enum})
		},
		"PUT": func(req he.Request) he.Response {
			db := req.Things["db"].(*periwinkle.Tx)

			var newGroup group
			httperr := safeDecodeJSON(req.Entity, &newGroup)
			if httperr != nil {
				return *httperr
			}
			if o.ID != newGroup.ID {
				return rfc7231.StatusConflict(he.NetPrintf("Cannot change group id"))
			}
			*o = newGroup
			o.backend().Save(db)
			return rfc7231.StatusOK(o)
		},
		"PATCH": func(req he.Request) he.Response {
			db := req.Things["db"].(*periwinkle.Tx)
			sess := req.Things["session"].(*backend.Session)
			subscribed := backend.IsSubscribed(db, sess.UserID, *o.backend())
			if !backend.IsAdmin(db, sess.UserID, *o.backend()) {
				if o.JoinPublic == 1 {
					if subscribed == 0 {
						return rfc7231.StatusForbidden(he.NetPrintf("Unauthorized user"))
					}
					if o.JoinConfirmed == 1 && subscribed == 1 {
						return rfc7231.StatusForbidden(he.NetPrintf("Unauthorized user"))
					}
					if o.JoinMember == 1 {
						return rfc7231.StatusForbidden(he.NetPrintf("Unauthorized user"))
					}
				}
			}
			enum := EnumerateGroup(o)
			var newGroup Enumerategroup
			patch, ok := req.Entity.(jsonpatch.Patch)
			if !ok {
				return rfc7231.StatusUnsupportedMediaType(he.NetPrintf("PATCH request must have a patch media type"))
			}
			err := patch.Apply(enum, &newGroup)
			if err != nil {
				return rfc7231.StatusConflict(he.NetPrintf("%v", err))
			}
			if o.ID != newGroup.Groupname {
				return rfc7231.StatusConflict(he.NetPrintf("Cannot change group id"))
			}

			*o = RenumerateGroup(newGroup)
			o.backend().Save(db)
			return rfc7231.StatusOK(o)
		},
		"DELETE": func(req he.Request) he.Response {
			db := req.Things["db"].(*periwinkle.Tx)
			sess := req.Things["session"].(*backend.Session)
			if !backend.IsAdmin(db, sess.UserID, *o.backend()) {
				return rfc7231.StatusForbidden(he.NetPrintf("Unauthorized user"))
			}
			o.backend().Delete(db)
			return rfc7231.StatusNoContent()
		},
	}
}