Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverted and fixed current_auth booleans #460

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hasjob/forms/jobpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class ApplicationForm(forms.Form):
def __init__(self, *args, **kwargs):
super(ApplicationForm, self).__init__(*args, **kwargs)
self.apply_email.choices = []
if current_auth:
if current_auth.not_anonymous:
self.apply_email.description = Markup(
_(u'Add new email addresses from <a href="{}" target="_blank">your profile</a>').format(
g.user.profile_url))
Expand Down
12 changes: 6 additions & 6 deletions hasjob/templates/detail.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</div>
<div class="col-md-3">{% if not g.kiosk %}
<div class="list-group">
{%- if current_auth %}
{%- if current_auth.not_anonymous %}
{% if g.user.has_starred_post(post) %}
<a class="list-group-item pstar" href="#">
<i class="fa fa-fw fa-star" data-id="{{ post.hashid }}"></i>&nbsp;&nbsp;
Expand Down Expand Up @@ -142,7 +142,7 @@
</a>
<div class="popup-box" id="report">
<a class="close-popup" href="#">&#10005;</a>
{%- if current_auth %}
{%- if current_auth.not_anonymous %}
<h2>What’s wrong with it?</h2>
{% include "inc/reportform.html.jinja2" %}
{%- else %}
Expand Down Expand Up @@ -196,7 +196,7 @@
</div>
</div>
{%- endif %}
{%- if is_siteadmin or (current_auth and g.board and g.board.owner_is(g.user)) %}
{%- if is_siteadmin or (current_auth.not_anonymous and g.board and g.board.owner_is(g.user)) %}
<div class="list-group-item">
<a class="popup" href="#makepinned">
<i class="fa fa-fw fa-thumb-tack"></i>&nbsp;&nbsp; Pin this
Expand All @@ -207,7 +207,7 @@
</div>
</div>
{%- endif %}
{%- if current_auth and g.user.flags.has_boards %}
{%- if current_auth.not_anonymous and g.user.flags.has_boards %}
<div class="list-group-item">
<a class="popup" href="#add-to-board">
<i class="fa fa-fw fa-plus"></i>&nbsp;&nbsp; Add to board
Expand Down Expand Up @@ -275,7 +275,7 @@
<p id="apply-info-para">
{%- if post.state.DRAFT %}{# Always show when in draft state #}
{{ post.how_to_apply|hideemail }}
{%- elif current_auth %}
{%- elif current_auth.not_anonymous %}
<a class="btn btn-primary" id="reveal-button" href="{{ post.url_for('reveal') }}">Show instructions</a> <span class="loading hidden"></span>
{%- else %}
<a class="btn btn-primary" href="{{ url_for('login') }}">Login with Google or GitHub</a>
Expand All @@ -285,7 +285,7 @@
</p>
{%- endif %}
</div>
{%- if not post.state.DRAFT and (current_auth or g.kiosk) and applyform %}
{%- if not post.state.DRAFT and (current_auth.not_anonymous or g.kiosk) and applyform %}
<div id="apply-section" class="section hidden">
</div>
{%- endif %}
Expand Down
12 changes: 6 additions & 6 deletions hasjob/templates/layout.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en" {% block manifest %}{%- if g.kiosk %} manifest="{{ url_for('kiosk_manifest') }}" {%- endif %}{% endblock %}> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en" {{ self.manifest() }}> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en" {{ self.manifest() }}> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" class="no-js {%- if current_auth %} userlogin {%- else %} no-userlogin {%- endif %}" {{ self.manifest() }}> <!--<![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" class="no-js {%- if current_auth.not_anonymous %} userlogin {%- else %} no-userlogin {%- endif %}" {{ self.manifest() }}> <!--<![endif]-->
{%- endblock -%}

{%- block titletags %}
Expand Down Expand Up @@ -218,16 +218,16 @@
{% endmacro %}
{% if not g.kiosk %}
{% with site_links=[], user_links = [] %}
{%- if current_auth and g.user.flags.is_candidate_alltime %}
{%- if current_auth.not_anonymous and g.user.flags.is_candidate_alltime %}
{% set user_links = user_links + [{'title': "Applied jobs", 'url': url_for('applied')}] %}
{%- endif %}
{%- if current_auth %}
{%- if current_auth.not_anonymous %}
{% set user_links = user_links + [{'title': "Bookmarks", 'url': url_for('bookmarks')}] %}
{%- endif %}
{%- if current_auth and g.user.flags.is_employer_alltime %}
{%- if current_auth.not_anonymous and g.user.flags.is_employer_alltime %}
{% set user_links = user_links + [{'title': "My posts", 'url': url_for('my_posts')}] %}
{%- endif %}
{%- if current_auth and g.user.flags.has_jobpost_unconfirmed_month %}
{%- if current_auth.not_anonymous and g.user.flags.has_jobpost_unconfirmed_month %}
{% set user_links = user_links + [{'title': "Drafts", 'url': url_for('browse_drafts')}] %}
{%- endif %}
{%- if is_siteadmin %}
Expand Down Expand Up @@ -273,7 +273,7 @@
to find out when new jobs are posted. Hosted by
<a href="http://e2enetworks.com/">E2E Networks</a>.
{%- endif %}
{%- if not current_auth and not g.anon_user %}
{%- if not current_auth %}
<img src="{{ url_for('sniffle') }}" width="1" height="1" alt=""/>
{%- endif %}
</p>
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/postjob.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
{%- else %}
{#{{ renderfield(form.poster_name) }}-#} {# Deprecated 2013-11-20 -#}
{{ renderfield(form.poster_email) }}
{%- if current_auth %}
{%- if current_auth.not_anonymous %}
<p>
Only you, <strong>{{ g.user.fullname }}</strong>, will be able to respond to candidates.
To allow others to respond, add them as a collaborator.
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/related_posts.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- if related_posts %}
{%- for post in related_posts -%}
<li class="col-xs-12 col-md-3 col-sm-4">
{{ stickie(post, post.url_for(), false, get_post_viewcounts, show_viewcounts=is_siteadmin or current_auth and g.user.flags.is_employer_month, show_pay=is_siteadmin, starred=current_auth and post.id in g.starred_ids) }}
{{ stickie(post, post.url_for(), false, get_post_viewcounts, show_viewcounts=is_siteadmin or current_auth.not_anonymous and g.user.flags.is_employer_month, show_pay=is_siteadmin, starred=current_auth.not_anonymous and post.id in g.starred_ids) }}
</li>
{%- endfor -%}
{%- endif %}
8 changes: 4 additions & 4 deletions hasjob/views/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def action_new(self, **kwargs):
@route('views.csv')
def view_counts(self, **kwargs):
campaign = self.obj
timezone = current_auth.actor.timezone if current_auth else 'UTC'
timezone = current_auth.actor.timezone if current_auth.not_anonymous else 'UTC'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can be current_auth.actor.timezone if current_auth else 'UTC' provided the AnonUser object reports a timezone (which it should).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not setting and using g.anon_user until we close that other PR that moved AnonUser to mouse interaction. So gonna leave it like this for now and fix it when I close that other PR.

viewdict = defaultdict(dict)

interval = chart_interval_for(campaign)
Expand Down Expand Up @@ -332,7 +332,7 @@ def csv(self, **kwargs):
def campaign_action_redirect(campaign, action):
if action.type != CAMPAIGN_ACTION.LINK:
abort(405)
if current_auth:
if current_auth.not_anonymous:
cua = CampaignUserAction.get(action, g.user)
if not cua:
cua = CampaignUserAction(action=action, user=g.user)
Expand Down Expand Up @@ -362,7 +362,7 @@ def campaign_action(campaign):

dismissed = 'dismiss' in request.form
if dismissed:
if current_auth:
if current_auth.not_anonymous:
view = campaign.view_for(g.user)
if view:
view.dismissed = True
Expand All @@ -382,7 +382,7 @@ def campaign_action(campaign):
campaign=campaign,
message=Markup("<p>Unknown action selected</p>"))
cua = None
if current_auth:
if current_auth.not_anonymous:
cua = CampaignUserAction.get(action, g.user)
if not cua:
cua = CampaignUserAction(action=action, user=g.user)
Expand Down
8 changes: 4 additions & 4 deletions hasjob/views/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def index_is_paginated():

def has_post_stats(post):
is_siteadmin = lastuser.has_permission('siteadmin')
return is_siteadmin or post.admin_is(g.user) or (current_auth and g.user.flags.get('is_employer_month'))
return is_siteadmin or post.admin_is(g.user) or (current_auth.not_anonymous and g.user.flags.get('is_employer_month'))


@form_validation_success.connect
Expand Down Expand Up @@ -128,7 +128,7 @@ def load_user_data(user):
g.anon_user = anon_user

# Prepare event session if it's not already present
if current_auth or g.anon_user and not g.esession:
if current_auth and not g.esession:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because current_auth checks for g.user or g.anon_user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true if Hasjob is reporting g.anon_user to current_auth as an actor, which has not been handled yet in this PR. This was reserved for a future PR.

g.esession = EventSession.get_session(uuid=session.get('es'), user=g.user, anon_user=g.anon_user)
if g.esession:
session['es'] = g.esession.uuid
Expand Down Expand Up @@ -254,7 +254,7 @@ def record_views_and_events(response):
if g.impressions:
g.event_data['impressions'] = g.impressions.values()

if current_auth:
if current_auth.not_anonymous:
for campaign in g.campaign_views:
if not CampaignView.exists(campaign, g.user):
db.session.begin_nested()
Expand All @@ -278,7 +278,7 @@ def record_views_and_events(response):
campaign_view_count_update.delay(campaign_id=campaign.id, anon_user_id=g.anon_user.id)

if g.esession: # Will be None for anon static requests
if current_auth or g.anon_user:
if current_auth:
ue = UserEvent.new_from_request(request)
else:
ue = UserEventBase.new_from_request(request)
Expand Down
16 changes: 8 additions & 8 deletions hasjob/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ def json_index(data):
for pinned, post, is_bgroup in group:
rgroup['posts'].append(stickie_dict(
post=post, url=post.url_for(b=is_bgroup), pinned=pinned, is_bgroup=is_bgroup,
show_viewcounts=is_siteadmin or current_auth and g.user.flags.get('is_employer_month'),
show_pay=is_siteadmin, starred=current_auth and post.id in g.starred_ids
show_viewcounts=is_siteadmin or current_auth.not_anonymous and g.user.flags.get('is_employer_month'),
show_pay=is_siteadmin, starred=current_auth.not_anonymous and post.id in g.starred_ids
))
result['grouped'].append(rgroup)
if pinsandposts:
for pinned, post, is_bgroup in pinsandposts:
result['posts'].append(stickie_dict(
post=post, url=post.url_for(b=is_bgroup), pinned=pinned, is_bgroup=is_bgroup,
show_viewcounts=is_siteadmin or current_auth and g.user.flags.get('is_employer_month'),
show_pay=is_siteadmin, starred=current_auth and post.id in g.starred_ids
show_viewcounts=is_siteadmin or current_auth.not_anonymous and g.user.flags.get('is_employer_month'),
show_pay=is_siteadmin, starred=current_auth.not_anonymous and post.id in g.starred_ids
))

return jsonify(result)
Expand Down Expand Up @@ -373,7 +373,7 @@ def index(basequery=None, filters={}, md5sum=None, tag=None, domain=None, locati
is_index = True
else:
is_index = False
if basequery is None and not (current_auth or g.kiosk or (board and not board.require_login)):
if basequery is None and not (current_auth.not_anonymous or g.kiosk or (board and not board.require_login)):
showall = False
batched = False

Expand Down Expand Up @@ -404,12 +404,12 @@ def index(basequery=None, filters={}, md5sum=None, tag=None, domain=None, locati
# For logging
g.event_data['filters'] = data['data_filters']

if current_auth:
if current_auth.not_anonymous:
g.starred_ids = set(g.user.starred_job_ids(agelimit if not ageless else None))
else:
g.starred_ids = set()

if is_siteadmin or (current_auth and g.user.flags.get('is_employer_month')):
if is_siteadmin or (current_auth.not_anonymous and g.user.flags.get('is_employer_month')):
load_viewcounts(data['posts'])
show_viewcounts = True
else:
Expand All @@ -435,7 +435,7 @@ def index(basequery=None, filters={}, md5sum=None, tag=None, domain=None, locati
# Test values for development:
# if not g.user_geonameids:
# g.user_geonameids = [1277333, 1277331, 1269750]
if not location and 'l' not in request.args and g.user_geonameids and (current_auth or g.anon_user) and (
if not location and 'l' not in request.args and g.user_geonameids and current_auth and (
(not g.board.auto_locations) if g.board else True):
# No location filters? Prompt the user
ldata = location_geodata(g.user_geonameids)
Expand Down
32 changes: 16 additions & 16 deletions hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def jobdetail(domain, hashid):
return redirect(post.url_for(), code=301)

if post.state.UNPUBLISHED:
if not (current_auth and post.admin_is(g.user)):
if not (current_auth.not_anonymous and post.admin_is(g.user)):
abort(403)
if post.state.GONE:
abort(410)
if current_auth:
if current_auth.not_anonymous:
jobview = UserJobView.get(post, g.user)
if jobview is None:
jobview = UserJobView(user=g.user, jobpost=post)
Expand All @@ -87,7 +87,7 @@ def jobdetail(domain, hashid):
except IntegrityError:
db.session.rollback()

if current_auth:
if current_auth.not_anonymous:
report = JobPostReport.query.filter_by(post=post, user=g.user).first()
else:
report = None
Expand All @@ -106,7 +106,7 @@ def jobdetail(domain, hashid):
pinnedform = forms.PinnedForm(obj=post)

if reportform.validate_on_submit():
if current_auth:
if current_auth.not_anonymous:
if report is None:
report = JobPostReport(post=post, user=g.user)
report.reportcode_id = reportform.report_code.data
Expand Down Expand Up @@ -140,14 +140,14 @@ def jobdetail(domain, hashid):
else:
header_campaign = None

if current_auth and not g.kiosk:
if current_auth.not_anonymous and not g.kiosk:
g.starred_ids = set(g.user.starred_job_ids(agelimit))
else:
g.starred_ids = set()

is_bgroup = getbool(request.args.get('b'))
headline = post.headlineb if is_bgroup and post.headlineb else post.headline
if is_siteadmin or post.admin_is(g.user) or (current_auth and g.user.flags.get('is_employer_month')):
if is_siteadmin or post.admin_is(g.user) or (current_auth.not_anonymous and g.user.flags.get('is_employer_month')):
post_viewcounts = get_post_viewcounts(post.id)
else:
post_viewcounts = None
Expand All @@ -167,7 +167,7 @@ def jobdetail(domain, hashid):
def job_viewstats(domain, hashid):
is_siteadmin = lastuser.has_permission('siteadmin')
post = JobPost.query.filter_by(hashid=hashid).options(db.load_only('id', 'datetime')).first_or_404()
if is_siteadmin or post.admin_is(g.user) or (current_auth and g.user.flags.get('is_employer_month')):
if is_siteadmin or post.admin_is(g.user) or (current_auth.not_anonymous and g.user.flags.get('is_employer_month')):
return jsonify({
"unittype": post.viewstats[0],
"stats": post.viewstats[1],
Expand All @@ -186,7 +186,7 @@ def job_related_posts(domain, hashid):
post = JobPost.query.filter_by(hashid=hashid).options(*JobPost._defercols).first_or_404()
jobpost_ab = session_jobpost_ab()
related_posts = post.related_posts().all()
if is_siteadmin or (current_auth and g.user.flags.get('is_employer_month')):
if is_siteadmin or (current_auth.not_anonymous and g.user.flags.get('is_employer_month')):
load_viewcounts(related_posts)
g.impressions = {rp.id: (False, rp.id, bgroup(jobpost_ab, rp)) for rp in related_posts}
max_counts = get_max_counts()
Expand Down Expand Up @@ -290,7 +290,7 @@ def applyjob(domain, hashid):
if post.email_domain != domain:
return redirect(post.url_for('apply'), code=301)

if current_auth:
if current_auth.not_anonymous:
job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first()
else:
job_application = None
Expand All @@ -308,7 +308,7 @@ def applyjob(domain, hashid):
applyform = forms.ApplicationForm()
applyform.post = post
if applyform.validate_on_submit():
if current_auth and g.user.blocked:
if current_auth.not_anonymous and g.user.blocked:
flashmsg = "Your account has been blocked from applying to jobs"
else:
if g.kiosk:
Expand Down Expand Up @@ -417,7 +417,7 @@ def view_application(domain, hashid, application):
post = JobPost.query.filter_by(hashid=hashid).first_or_404()
# Transition code until we force all employers to login before posting
if post.user and not (post.admin_is(g.user) or lastuser.has_permission('siteadmin')):
if not current_auth:
if current_auth.is_anonymous:
return redirect(url_for('login', message=u"You need to be logged in to view candidate applications on Hasjob."))
else:
abort(403)
Expand Down Expand Up @@ -456,7 +456,7 @@ def view_application(domain, hashid, application):
def process_application(domain, hashid, application):
post = JobPost.query.filter_by(hashid=hashid).first_or_404()
if post.user and not post.admin_is(g.user):
if not current_auth:
if current_auth.is_anonymous:
return redirect(url_for('login'))
else:
abort(403)
Expand Down Expand Up @@ -775,7 +775,7 @@ def confirm_email(domain, hashid, key):
def withdraw(domain, hashid, key):
post = JobPost.query.filter_by(hashid=hashid).first_or_404()
form = forms.WithdrawForm()
if not ((key is None and current_auth and post.admin_is(g.user)) or (key == post.edit_key)):
if not ((key is None and current_auth.not_anonymous and post.admin_is(g.user)) or (key == post.edit_key)):
abort(403)
if post.state.WITHDRAWN:
flash("Your job post has already been withdrawn", "info")
Expand Down Expand Up @@ -812,7 +812,7 @@ def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None):

if not newpost:
post = JobPost.query.filter_by(hashid=hashid).first_or_404()
if not ((key is None and current_auth and post.admin_is(g.user)) or (key == post.edit_key)):
if not ((key is None and current_auth.not_anonymous and post.admin_is(g.user)) or (key == post.edit_key)):
abort(403)

# Once this post is published, require editing at /domain/<hashid>/edit
Expand Down Expand Up @@ -962,7 +962,7 @@ def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None):
def newjob():
form = forms.ListingForm()
archived_post = None
if not current_auth:
if current_auth.is_anonymous:
return redirect(url_for('login', next=url_for('newjob'),
message=u"Hasjob now requires you to login before posting a job. Please login as yourself."
u" We'll add details about your company later"))
Expand All @@ -983,7 +983,7 @@ def newjob():
if request.method == 'GET':
header_campaign = Campaign.for_context(CAMPAIGN_POSITION.BEFOREPOST, board=g.board, user=g.user,
anon_user=g.anon_user, geonameids=g.user_geonameids)
if current_auth:
if current_auth.not_anonymous:
# form.poster_name.data = g.user.fullname # Deprecated 2013-11-20
form.poster_email.data = g.user.email
else:
Expand Down