def test_is_admin(self): admin = User.objects.create_user(username='******', password='******', email='*****@*****.**') superuser = User.objects.create_user(username='******', password='******', email='*****@*****.**') nonadmin = User.objects.create_user(username='******', password='******', email='*****@*****.**') admin.groups.add(self.admin_group) admin.save() superuser.is_superuser = True superuser.save() self.assertTrue(is_admin(admin)) self.assertTrue(is_admin(superuser)) self.assertFalse(is_admin(nonadmin))
def user_can_view(self, user): from storybase_user.utils import is_admin if self.status == 'published': return True if user.is_superuser or is_admin(user): return True return False
def user_can_change(self, user): from storybase_user.utils import is_admin if not user.is_active: return False if self.section.story.author == user: return True if is_admin(user): return True return False
def user_can_change(self, user): from storybase_user.utils import is_admin if not user.is_active: return False if self.owner == user: return True if is_admin(user): return True return False
def user_can_change(self, user): from storybase_user.utils import is_admin if not user.is_active: return False # Authenticated, active users can change their own dataset if self.owner == user: return True # Admins can change any asset if is_admin(user): return True return False
def handle(self, *args, **options): from storybase_user.utils import is_admin if name_generator is None: raise CommandError("To use this management command, you need to " "install the name_generator package from " "https://github.com/macropin/random-name-generator") interactive = options.get('interactive') if interactive: confirm = raw_input("""You have requested to anonymize all user data. This action CANNOT BE REVERSED. Are you sure you want to do this? Type 'yes' to continue, or 'no' to cancel """) else: confirm = 'yes' if confirm == 'yes': file_path = lambda x: os.path.join(options['name_data_dir'], x) first_data = name_generator.parse_data(file_path('dist.female.first')) + name_generator.parse_data(file_path('dist.male.first')) last_data = name_generator.parse_data(file_path('dist.all.last')) first_wc = WeightedChoice(first_data) last_wc = WeightedChoice(last_data) users = User.objects.all() names = name_generator.generate_names(first_wc, last_wc, users.count(), True) for i, user in enumerate(users): if options['skip_admins'] and is_admin(user): # Skip admin user self.stderr.write("Skipping admin user %s\n" % (user.username)) continue (fname, lname) = [n.title() for n in names[i].split(' ')] username = "******" % (fname.lower(), lname.lower()) email = "*****@*****.**" % (fname.lower(), lname.lower()) password = User.objects.make_random_password() user.username = username user.first_name = fname user.last_name = lname user.set_password(password) user.email = email user.save() else: self.stderr.write("User anonymization cancelled\n")
def user_can_change(self, user): from storybase_user.utils import is_admin if not user.is_active: return False # TODO: Add additional logic as different relation types # are defined if self.relation_type == 'connected' and self.target.author == user: # Users should be able to define the parent of connected # stories for stories that they own return True if is_admin(user): return True return False