Yes i am using group memberships in my Auth tables On Monday, October 22, 2018 at 8:58:06 AM UTC+2, Dave S wrote: > > > > On Saturday, October 20, 2018 at 12:30:07 PM UTC-7, mostwanted wrote: >> >> I can get registered users to view only what they post and not what >> others post, below is the simple code i used. What i want now is how to get >> only members of groups to view only what their group members post and not >> members of other groups: >> >> > Are you using group membership in your Auth tables? See chapter 9 of the > book. > <URL: > http://web2py.com/books/default/chapter/29/09/access-control#Authorization > > > > > >> *MODEL:* >> db.define_table('post', >> Field('body', 'text', requires=IS_NOT_EMPTY(), label='What >> is on your mind'), >> Field('posted_on', 'datetime', default=request.now, >> readable=False, writable=False), >> Field('posted_by', 'reference auth_user', default=auth. >> user_id, readable=False, writable=False)) >> >> >> *CONTROLLER:* >> @auth.requires_login() >> > > replace this decorator (here and below) with > @auth.requires_membership('groupIbelong2') > > (group membership isn't defined until the user logs in) > > > >> >> def index(): >> form=SQLFORM(db.post) >> if form.process().accepted: >> response.flash=T('Entered') >> return locals() >> >> @auth.requires_login() >> def details(): >> user=db.auth_user(auth.user_id) >> if not user or not(user.id==auth.user_id): redirect(URL('index')) >> details=db(db.post.posted_by==user.id).select(db.post.ALL) >> return locals() >> >> *VIEWS* >> >> *index* >> {{extend 'layout.html'}} >> >> {{=form}} >> {{pass}} >> >> *details*: >> {{extend 'layout.html'}} >> >> {{for details in details:}} >> Infomation: {{=details.body}}<br /> >> Date: {{=details.posted_on}}<br /> >> Poster: {{=details.posted_by.first_name}}<br /> >> <hr /> >> {{pass}} >> >> How can I change my *details controller* to be able to achieve the above >> task? >> >> Regards: >> >> Mostwanted >> > > There are poster here with more group membership experience, if this > doesn't answer your question. > > /dps > > > >
-- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.