def add_all_accounts(self): account = get_account_by_id(settings.RESTCLIENTS_CANVAS_ACCOUNT_ID) accounts = get_all_sub_accounts(account.account_id) accounts.append(account) super(AccountManager, self).get_queryset().update(is_deleted=True) for account in accounts: self.add_account(account)
def load_all_accounts(self): root_id = settings.RESTCLIENTS_CANVAS_ACCOUNT_ID accounts = [get_account_by_id(root_id)] accounts.extend(get_all_sub_accounts(root_id)) Account.objects.all().update(is_deleted=True) for account in accounts: self.load_account(account)
def get(self, request, *args, **kwargs): try: account = get_account_by_id(kwargs.get('account_id')) return self.json_response({ 'account_id': account.account_id, 'sis_account_id': account.sis_account_id, 'name': account.name, 'parent_account_id': account.parent_account_id, 'root_account_id': account.root_account_id, 'account_url': "{host}/accounts/{account_id}".format( host=getattr(settings, 'RESTCLIENTS_CANVAS_HOST', ''), account_id=account.account_id) }) except Exception as e: return self.error_response( 400, "Unable to retrieve account: {}".format(e))
def GET(self, request, **kwargs): try: account = get_account_by_id(kwargs.get('account_id')) return self.json_response(json.dumps({ 'account_id': account.account_id, 'sis_account_id': account.sis_account_id, 'name': account.name, 'parent_account_id': account.parent_account_id, 'root_account_id': account.root_account_id, 'account_url': "%s/accounts/%s" % ( getattr(settings, 'RESTCLIENTS_CANVAS_HOST', ''), account.account_id) })) except Exception as e: return self.json_response( '{"error": "Unable to retrieve account: %s"' % (e) + ' }', status=400)
def handle(self, *args, **options): root_account = get_account_by_id(options.get('root_account')) accounts = get_all_sub_accounts(root_account.account_id) accounts.append(root_account) for account in accounts: account_id = account.account_id for admin in get_admins(account_id): if not Admin.objects.verify_canvas_admin(admin, account_id): if options.get('commit'): delete_admin(account_id, admin.user.user_id, admin.role) logger.info( ('REMOVE UNAUTHORIZED ADMIN "{}", account: "{}", ' 'role: "{}"').format(admin.user.login_id, account_id, admin.role)) self.update_job()
def import_tools_in_account(self, account_id, changed_by): try: account = Account.objects.get(canvas_id=account_id) except Account.DoesNotExist: account_data = get_account_by_id(account_id) account = Account.objects.add_account(account_data) for config in get_external_tools(account_id): try: tool = ExternalTool.objects.get(canvas_id=config.get('id')) except ExternalTool.DoesNotExist: tool = ExternalTool(canvas_id=config.get('id')) tool.account = account tool.config = json.dumps(config) tool.changed_by = changed_by tool.changed_date = datetime.utcnow().replace(tzinfo=utc) tool.queue_id = None tool.save() for subaccount in get_sub_accounts(account_id): self.import_tools_in_account(subaccount.account_id, changed_by)