Hide an announcement for the logged-in user.

        announcements_hidden in the user model is the related_name for
        "users_hidden" in the announcement model.
778458
def hide_announcement_view(request):
    
    if request.method == "POST":
        announcement_id = request.POST.get("announcement_id")
        if announcement_id:
            announcement = Announcement.objects.get(id=announcement_id)
            try:
                announcement.user_map.users_hidden.add(request.user)
                announcement.user_map.save()
            except IntegrityError:
                logger.warning("Duplicate value when hiding announcement {} for {}.".format(announcement_id, request.user.username))
            return http.HttpResponse("Hidden")
        raise http.Http404
    else:
        return http.HttpResponseNotAllowed(["POST"], "HTTP 405: METHOD NOT ALLOWED")
507191
public function saveOrUpdate(Announcement $announcement, Request $request)
    {
        $announcement
            ->fill($request->get('announcement'))
            ->fill([
                'user_id' => $request->user()->id,
                'active'  => 1,
            ])->save();

        Alert::info(__('Announcement has been created or updated.'));

        return back();
    }
440661
def hide_stevedore_logs():
    
    stevedore_logger = logging.getLogger('stevedore.extension')
    stevedore_logger.propagate = False
    stevedore_logger.setLevel(logging.ERROR)
    stevedore_logger.addHandler(logging.NullHandler())
56821
def _nick(self, nick):
        
        with self.lock:
            self.send('NICK :%s' % nick)

            if self.readable():
                msg = self._recv(expected_replies='NICK')
                if msg[0] == 'NICK':
                    if not self.hide_called_events:
                        self.stepback()

            for channel in self.channels:
                if 'USERS' in self.channels[channel]:
                    priv_level = \
                    self.channels[channel]['USERS'][self.current_nick]
                    del self.channels[channel]['USERS'][self.current_nick]
                    self.channels[channel]['USERS'][nick] = priv_level
            self.current_nick = nick
244128
def _Notify(username, notification_type, message, object_reference):
  """"""

  # Do not try to notify system users (e.g. Cron).
  if username in aff4_users.GRRUser.SYSTEM_USERS:
    return

  if object_reference:
    uc = object_reference.UnionCast()
    if hasattr(uc, "client_id"):
      message = _HostPrefix(uc.client_id) + message

  n = rdf_objects.UserNotification(
      username=username,
      notification_type=notification_type,
      state=rdf_objects.UserNotification.State.STATE_PENDING,
      message=message,
      reference=object_reference)
  data_store.REL_DB.WriteUserNotification(n)
740106
def visible_to_user(self, user):
        

        return (Event.objects.filter(approved=True).filter(Q(groups__in=user.groups.all()) | Q(groups__isnull=True) | Q(user=user)))
83179
def make_unpublished(self, request, queryset):
        
        rows_updated = queryset.update(is_published=False)
        self.message_user(request,
                          ungettext('%(count)d newsitem was unpublished',
                                    '%(count)d newsitems were unpublished',
                                    rows_updated) % {'count': rows_updated})
1015531
def remove_from_user(self, name, *args):
        
        user = self.get_user(name=name)
        attrs_ = user['user']
        for a in args:
            del attrs_[a]
1001737
def admin_request_announcement_email(request, form, obj):
    

    subject = "News Post Approval Needed ({})".format(obj.title)
    emails = [settings.APPROVAL_EMAIL]
    base_url = request.build_absolute_uri(reverse('index'))
    data = {
        "req": obj,
        "formdata": form.data,
        "info_link": request.build_absolute_uri(reverse("admin_approve_announcement", args=[obj.id])),
        "base_url": base_url
    }
    email_send("announcements/emails/admin_approve.txt", "announcements/emails/admin_approve.html", data, subject, emails)
1003132
public function isAllowedNotify(): bool
    {
        //====================================================================//
        // Safety Check
        if (!isset($this->authChecker)) {
            return true;
        }

        try {
            //====================================================================//
            // Walk on User Allowed Roles
            foreach ($this->getCoreParameter('notify') as $notifyRole) {
                //====================================================================//
                // User as Role => Notifications Allowed
                if ($this->authChecker->isGranted($notifyRole)) {
                    return true;
                }
            }
        } catch (AuthenticationCredentialsNotFoundException $exc) {
            //====================================================================//
            // Notifications Not Allowed
            return false;
        }

        return false;
    }
1042283
def stop_notifying(cls, user_or_email, instance):
        """"""
        super(InstanceEvent, cls).stop_notifying(user_or_email,
                                                 object_id=instance.pk)
248720
def release_name(self, username):
        
        self.temp_names.append(username)
        if self.is_username_used(username):
            self.registered_names.remove(username)
604533
def UpdateUserNotifications(self, username, timestamps, state=None):
    """"""
    if not timestamps:
      return

    for n in self.notifications_by_username.get(username, []):
      if n.timestamp in timestamps:
        n.state = state
261507
def mentioned_in(self, message):
        

        if message.mention_everyone:
            return True

        for user in message.mentions:
            if user.id == self.id:
                return True

        return False
54424
def notice(self, msg, *args, **kw):
        """"""
        if self.isEnabledFor(NOTICE):
            self._log(NOTICE, msg, args, **kw)
813674
def user_save_event(user):
    
    msg = 'User ({}){} updated/saved'.format(user.id, user.email)
    current_app.logger.info(msg)
531911
def insertAnnouncement(self, announcement):
        
        url = announcement.get('url', None)
        try:
            peers.Peer(url)
        except:
            raise exceptions.BadUrlException(url)
        try:
            # TODO get more details about the user agent
            models.Announcement.create(
                url=announcement.get('url'),
                attributes=json.dumps(announcement.get('attributes', {})),
                remote_addr=announcement.get('remote_addr', None),
                user_agent=announcement.get('user_agent', None))
        except Exception as e:
            raise exceptions.RepoManagerException(e)