Files
2012-02-21 01:15:00 -05:00

1 line
3.4 KiB
JSON

[{"user_id": 553, "stars": [], "topic_id": 43654, "date_created": 1313084572.8032329, "message": "and login of course :)", "group_id": 81, "id": 1849858}, {"user_id": 553, "stars": [], "topic_id": 43654, "date_created": 1313084552.9775319, "message": "What is the best way to lock users from one group to defined url. So like users from group \"clients\" can only go to /client", "group_id": 81, "id": 1849852}, {"user_id": 23956, "stars": [], "topic_id": 43654, "date_created": 1313133844.6801939, "message": "Maybe by giving the group a custom permission, and only letting users with that permission access the page?", "group_id": 81, "id": 1855442}, {"user_id": 553, "stars": [], "topic_id": 43654, "date_created": 1313166414.4849069, "message": "so far i came up with middleware idea", "group_id": 81, "id": 1858144}, {"user_id": 553, "stars": [], "topic_id": 43654, "date_created": 1313166407.585952, "message": "I also need those users to not be able to access any other page", "group_id": 81, "id": 1858142}, {"user_id": 23956, "stars": [], "topic_id": 43654, "date_created": 1313220035.3203731, "message": "If you were using custom permissions, I think a combination of the login_required and permission_required decorators would work, but I guess you could also write custom middleware. I do not know which would be better performance-wise, but the latter would almost certainly be more code.", "group_id": 81, "id": 1863189}, {"user_id": 32294, "stars": [], "topic_id": 43654, "date_created": 1313398220.049325, "message": "class OrganizationManager(models.Manager):\n filter_by_user_limit_field = None\n \n def by_user(self, user):\n \"\"\"\n Extension for filtering organization objects (also related objects) by\n the groups of a user.\n Avoiding that a user can touch other organization objects. Superusers and \n Partner Administrators are able to see all organizations.\n \"\"\"\n # TODO: optimization: would be nice to find a way to make by_user chainable like .filter(), ...\n return self.limit_queryset_by_user(\n self.get_query_set(),\n user,\n self.model.filter_by_user_limit_field\n )\n \n @staticmethod\n def limit_queryset_by_user(qs, user, field_key):\n if user.is_superuser or user.groups.filter(name=PARTNER_ADMIN_GROUP_NAME).count()>0:\n return qs\n kwargs = {}\n if field_key and user.groups.count() > 0:\n kwargs[field_key] = [u['id'] for u in user.groups.values('id')]\n return qs.filter(**kwargs)", "group_id": 81, "id": 1874615}, {"user_id": 32294, "stars": [], "topic_id": 43654, "date_created": 1313398211.4568989, "message": "We have created a CustomManager and assigned a Group to the client.", "group_id": 81, "id": 1874614}, {"user_id": 32294, "stars": [], "topic_id": 43654, "date_created": 1313398311.5762429, "message": "class OrganizationGroup(Group):\n \"\"\"\n User group of the Organization\n \"\"\"\n organization = models.OneToOneField(Organization)", "group_id": 81, "id": 1874617}, {"user_id": 32294, "stars": [], "topic_id": 43654, "date_created": 1313398667.9217229, "message": "class Organization(ExtendedModel):\n name = models.CharField(max_length=64, unique=True)\n slug = models.SlugField(unique=True)\n .....\n filter_by_user_limit_field = \"organizationgroup__in\"\n ....\n objects = OrganizationManager()\n", "group_id": 81, "id": 1874627}]