Set favorite to the logged in user. If no user, no action is done
6269
public void add(DbSession dbSession, ComponentDto componentDto, @Nullable Integer userId, boolean failIfTooManyFavorites) {
    if (userId == null) {
      return;
    }

    List<PropertyDto> existingFavoriteOnComponent = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
      .setKey(PROP_FAVORITE_KEY)
      .setUserId(userId)
      .setComponentId(componentDto.getId())
      .build(), dbSession);
    checkArgument(existingFavoriteOnComponent.isEmpty(), "Component '%s' is already a favorite", componentDto.getDbKey());

    List<PropertyDto> existingFavorites = dbClient.propertiesDao().selectByKeyAndUserIdAndComponentQualifier(dbSession, PROP_FAVORITE_KEY, userId, componentDto.qualifier());
    if (existingFavorites.size() >= 100) {
      checkArgument(!failIfTooManyFavorites, "You cannot have more than 100 favorites on components with qualifier '%s'", componentDto.qualifier());
      return;
    }
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
      .setKey(PROP_FAVORITE_KEY)
      .setResourceId(componentDto.getId())
      .setUserId(userId));
  }
334493
def set_user_session(user):
    
    from uliweb import settings, request

    user_fieldname = settings.get_var('AUTH/GET_AUTH_USER_FIELDNAME', 'id')
    share_session = settings.get_var('AUTH/AUTH_SHARE_USER_SESSION', False)
    if isinstance(user, dict):
        user_id = user[user_fieldname]
    else:
        user_id = getattr(user, user_fieldname)

    if share_session:
        cache = functions.get_cache()
        key = get_user_session_key(user_id)
        session_id = cache.get(key, None)
        log.debug('Auth: user session user_id={}, session_id={}, key={}'.format(user_id, session_id, key))
        if not session_id:
            request.session.save()
            log.debug('Auth: set user session mapping userid={}, '
                      'session_id={}, expiry time={}'.format(user_id,
                                                             request.session.key,
                                                             request.session.expiry_time))
            cache.set(key, request.session.key, expire=request.session.expiry_time)
        elif session_id != request.session.key:
            log.debug('Auth: load oldkey={}, key={}'.format(request.session.key, session_id))
            request.session.delete()
            request.session.load(session_id)
    if isinstance(user, dict):
        request.session[_get_auth_key()] = user
    else:
        request.session[_get_auth_key()] = user_id
    request.user = user
170837
public static Iterable<Item> getFavorites(@Nonnull User user) {
        FavoriteUserProperty fup = user.getProperty(FavoriteUserProperty.class);
        if (fup == null) {
            return ImmutableList.of();
        }
        Set<String> favorites = fup.getAllFavorites();
        if (favorites.isEmpty()) {
            return ImmutableList.of();
        }
        final Iterator<String> iterator = favorites.iterator();
        final Jenkins jenkins = Jenkins.getInstance();
        if (jenkins == null) {
            throw new IllegalStateException("Jenkins not started");
        }
        return new Iterable<Item>() {
            @Override
            public Iterator<Item> iterator() {
                return Iterators.filter(new Iterator<Item>() {
                    @Override
                    public boolean hasNext() {
                        return iterator.hasNext();
                    }

                    @Override
                    public Item next() {
                        return jenkins.getItemByFullName(iterator.next());
                    }
                    
                    /* Fix build. */
                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                }, Predicates.<Item>notNull());
            }
        };
    }
425194
def guest_reset(self, userid):
        
        action = "reset guest '%s'" % userid
        with zvmutils.log_and_reraise_sdkbase_error(action):
            self._vmops.guest_reset(userid)
325775
def add_user(self, user):
        """"""
        if not isinstance(user, User):
            user = User(user)
        if user.nick in self.members:
            _log.warning("Ignoring request to add user '%s' to channel '%s' "
                         "because that user is already in the member list.",
                         user, self.name)
            return
        self.members[user.nick] = user
        _log.debug("Added '%s' to channel '%s'", user, self.name)
996586
public function setConfiguredUserAction()
    {
        $user = $this->getRequest()->getParam('user');
        Mage::getModel('core/config')
            ->saveConfig(Aoe_Scheduler_Helper_Data::XML_PATH_CRON_USER, (string) $user);

        $this->_getSession()->addSuccess($this->__('Configured cron user updated to be "%s"', $user));
        $this->_redirectReferer();
    }
70755
def get_favoritable_value
      if spree_current_user.present?
        @favorite = spree_current_user.favorites.where(favoritable_params).first
      end

      respond_to do |format|
        format.js
      end
    end
1248912
def action_inactivate(self, ids):
        """"""
        try:
            count = 0
            for user_id in ids:
                user = _datastore.get_user(user_id)
                if user is None:
                    raise ValueError(_("Cannot find user."))
                if _datastore.deactivate_user(user):
                    count += 1
            if count > 0:
                flash(_('User(s) were successfully inactivated.'), 'success')
        except Exception as exc:
            if not self.handle_view_exception(exc):
                raise

            current_app.logger.exception(str(exc))  # pragma: no cover
            flash(_('Failed to inactivate users.'),
                  'error')
296384
def toggle_favourite(self):
        """"""
        status = self.get_selected_status()
        assert status
        app, user = self.app, self.user
        if not app or not user:
            self.footer.draw_message("You must be logged in to favourite", Color.RED)
            return
        status_id = status['id']
        if status['favourited']:
            self.footer.draw_message("Undoing favourite status...", Color.YELLOW)
            api.unfavourite(app, user, status_id)
            self.footer.draw_message("✓ Status unfavourited", Color.GREEN)
        else:
            self.footer.draw_message("Favourite status...", Color.YELLOW)
            api.favourite(app, user, status_id)
            self.footer.draw_message("✓ Status favourited", Color.GREEN)
        status['favourited'] = not status['favourited']

        self.right.draw(status)
537182
def users_deactivate(user):
    """"""
    user_obj = _datastore.get_user(user)
    if user_obj is None:
        raise click.UsageError('ERROR: User not found.')
    if _datastore.deactivate_user(user_obj):
        click.secho('User "{0}" has been deactivated.'.format(user),
                    fg='green')
    else:
        click.secho('User "{0}" was already deactivated.'.format(user),
                    fg='yellow')
29137
protected function setUserForgot()
    {
        $token = $this->getQuery('key');
        $user_id = $this->getQuery('user_id');

        $this->data_user = array();

        if (!empty($token) && is_numeric($user_id)) {
            $this->data_user = $this->user->get($user_id);
            $this->controlTokenUserForgot($this->data_user, $token);
        }
    }
741090
protected function setUserFromSession()
    {
        $id = $this->session->get();

        if ($id) {
            $user = $this->repository->getById($this->session->get());
            if ($user instanceof UserInterface) {
                $this->admitUser($user);
                return;
            }
        }

        $this->currentUser = new GuestUser();
    }
31709
def create_inactive_user(self, form):
        """"""
        new_user = form.save(commit=False)
        new_user.is_active = False
        new_user.save()
        return new_user
81660
def admirers(options = {})
      options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
      favorite_listings = FavoriteListing.find_all_listings_favored_by(id, options)
      user_ids  = favorite_listings.map {|f| f.user_id }.uniq
      (user_ids.size > 0) ? Array(Etsy::User.find(user_ids, options)) : []
    end
1186896
def set_user(self, user):
        
        super(Segment, self)._check_ended()
        self.user = user
474592
public void setSelectedInternalItem(User user) {
		User internalUser = null;
		int index = getIndexOf(user);
		if (index != -1) {
			internalUser = getElementAt(index);
		} else if (getSize() > 0) {
			internalUser = getElementAt(0);
		}

		setSelectedItemImpl(internalUser);
	}
910312
protected function setUser()
    {
        $this->uid = $this->getParam('u', null);

        if (isset($this->uid)) {

            $this->current_user = $this->user->get($this->uid);

            if (empty($this->current_user['status'])) {
                $this->errorAndExit($this->text('No access'));
            }
        }
    }