This allows replacing id_name with "self".
    e.g. /users/joe/account == /users/self/account if joe is in the session
    as an authorized user
552054
def enable_selfalias(config, id_name):
    

    def context_found_subscriber(event):
        request = event.request
        user = getattr(request, 'user', None)
        if (request.matchdict and
                request.matchdict.get(id_name, None) == 'self' and
                user):
            request.matchdict[id_name] = user.username

    config.add_subscriber(context_found_subscriber, ContextFound)
755026
def rename(name, options={})
      result = @session.rename(path, name, options)
      @path = result.path.gsub(/^\//, '')
      return result
    end
1024235
def reassign(self, user_ids, requester_id):
        
        if not user_ids:
            raise Error('Must pass at least one user id')
        self._do_action('reassign', requester_id=requester_id, assigned_to_user=','.join(user_ids))
313303
def user(self, id, expand=None):
        
        user = User(self._options, self._session)
        params = {}
        if expand is not None:
            params['expand'] = expand
        user.find(id, params=params)
        return user
210778
def user_as_string=(user)
      # reset both either way
      self.user_as_model = self.username = nil
      user.is_a?(::ActiveRecord::Base) ?
        self.user_as_model = user :
        self.username = user
    end
1273219
def load_session
      unless logged_in?
        session[Shibbolite.pid] = request.env[Shibbolite.pid.to_s]
        current_user.update(get_attributes) if registered_user?
      end
    end
1083164
def get_user_id(user_id_or_username):
    
    user_id_or_username = user_id_or_username.lower()
    if not user_id_or_username.startswith("user-"):
        user_id = "user-" + user_id_or_username.lower()
    else:
        user_id = user_id_or_username
    return user_id
216351
def HandleAccounts(self, result):
    
    self.logger.debug('Checking for changes to user accounts.')
    configured_users = self.utils.GetConfiguredUsers()
    enable_oslogin = self._GetEnableOsLoginValue(result)
    enable_two_factor = self._GetEnableTwoFactorValue(result)
    if enable_oslogin:
      desired_users = {}
      self.oslogin.UpdateOsLogin(True, two_factor_desired=enable_two_factor)
    else:
      desired_users = self._GetAccountsData(result)
      self.oslogin.UpdateOsLogin(False)
    remove_users = sorted(set(configured_users) - set(desired_users.keys()))
    self._UpdateUsers(desired_users)
    self._RemoveUsers(remove_users)
    self.utils.SetConfiguredUsers(desired_users.keys())
426290
def self_register_user(self, user_name, account_id, user_terms_of_use, pseudonym_unique_id, communication_channel_address=None, communication_channel_type=None, user_birthdate=None, user_locale=None, user_short_name=None, user_sortable_name=None, user_time_zone=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - account_id
        """ID"""
        path["account_id"] = account_id

        # REQUIRED - user[name]
        """The full name of the user. This name will be used by teacher for grading."""
        data["user[name]"] = user_name

        # OPTIONAL - user[short_name]
        """User's name as it will be displayed in discussions, messages, and comments."""
        if user_short_name is not None:
            data["user[short_name]"] = user_short_name

        # OPTIONAL - user[sortable_name]
        """User's name as used to sort alphabetically in lists."""
        if user_sortable_name is not None:
            data["user[sortable_name]"] = user_sortable_name

        # OPTIONAL - user[time_zone]
        """The time zone for the user. Allowed time zones are
        {http://www.iana.org/time-zones IANA time zones} or friendlier
        {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Ruby on Rails time zones}."""
        if user_time_zone is not None:
            data["user[time_zone]"] = user_time_zone

        # OPTIONAL - user[locale]
        """The user's preferred language, from the list of languages Canvas supports.
        This is in RFC-5646 format."""
        if user_locale is not None:
            data["user[locale]"] = user_locale

        # OPTIONAL - user[birthdate]
        """The user's birth date."""
        if user_birthdate is not None:
            data["user[birthdate]"] = user_birthdate

        # REQUIRED - user[terms_of_use]
        """Whether the user accepts the terms of use."""
        data["user[terms_of_use]"] = user_terms_of_use

        # REQUIRED - pseudonym[unique_id]
        """User's login ID. Must be a valid email address."""
        data["pseudonym[unique_id]"] = pseudonym_unique_id

        # OPTIONAL - communication_channel[type]
        """The communication channel type, e.g. 'email' or 'sms'."""
        if communication_channel_type is not None:
            data["communication_channel[type]"] = communication_channel_type

        # OPTIONAL - communication_channel[address]
        """The communication channel address, e.g. the user's email address."""
        if communication_channel_address is not None:
            data["communication_channel[address]"] = communication_channel_address

        self.logger.debug("POST /api/v1/accounts/{account_id}/self_registration with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("POST", "/api/v1/accounts/{account_id}/self_registration".format(**path), data=data, params=params, single_item=True)
100103
def is_owner(self, user):
        
        if user.is_authenticated:
            return self.created_by.id == user.id
        return False
3912
def activate(self, profile_name=NotSet):
        
        if profile_name is NotSet:
            profile_name = self.profile_name
        self._active_profile_name = profile_name
932898
def auth_as(self, user):
        """"""
        old_user = self._user
        self.auth(user)
        try:
            yield
        finally:
            self.auth(old_user)
1336129
def update_user(self, user, username=None, first_name=None, last_name=None):
		""""""
		
		if not isinstance(user, User):
			raise ValueError
		args = locals()
		url = api_url+'users/'+str(user.id)+'/'
		payload = {}
		for i in args:
			if args[i] is not None and i not in ['self', 'user']:
				payload[i] = args[i]
		r = requests.patch(url, data=json.dumps(payload), headers=self.headers)
		print(request_status(r))
		r.raise_for_status()
		return User(r.json())
711902
def CheckIfUserIsAdmin(self, username):
    """"""

    user_obj = data_store.REL_DB.ReadGRRUser(username)
    if user_obj.user_type != user_obj.UserType.USER_TYPE_ADMIN:
      raise access_control.UnauthorizedAccess("User %s is not an admin." %
                                              username)
617348
def match_user
      unless admin?
        user = User.find(current_user)

        unless user.id == set_user.id
          redirect_to user_path(current_user), notice: 'You do not have any permission to grant this page !'
        end
      end
    end
480019
def put(self, name=None, user_ids=None):
        
        return self.connection.put('account', data=dict(name=name, user_ids=user_ids))
448058
def revoke_user_access(self, instance, user, db_names, strict=True):
        
        return instance.revoke_user_access(user, db_names, strict=strict)