Skip to content

Commit

Permalink
Merging fixes from master to stable (#10677)
Browse files Browse the repository at this point in the history
* Adjusting log messages + linter fixes (#10667)

Co-authored-by: Gerald Iakobinyi-Pich <[email protected]>

* Fixes for bounties: (#10671)

- layout for contact details (avoid overlapping, wrap the line with contact details)
   - editing bounty that was not reserved was not working

Co-authored-by: Gerald Iakobinyi-Pich <[email protected]>

* toggle user sybils: add comparisons to thresholds (#10676)

* Adding try + catch + error message when scoring passport.

Co-authored-by: Gerald Iakobinyi-Pich <[email protected]>
Co-authored-by: Danilo Lessa Bernardineli <[email protected]>
  • Loading branch information
3 people authored Jun 15, 2022
1 parent 37c2b78 commit 7bf1185
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 61 deletions.
4 changes: 2 additions & 2 deletions app/assets/v2/js/pages/change_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,10 @@ if (document.getElementById('gc-hackathon-new-bounty')) {
project_length: bounty.project_length,
experience_level: bounty.experience_level,
never_expires: bounty.never_expires,
reserved_for_user: {
reserved_for_user: bounty.bounty_reserved_for_user ? {
text: bounty.bounty_reserved_for_user.handle,
avatar_url: bounty.bounty_reserved_for_user.avatar_url
},
} : { text: '', avatar_url: ''},
richDescriptionContent: bounty.custom_issue_description ? JSON.parse(bounty.custom_issue_description) : null,
richDescriptionText: bounty.custom_issue_description ? bounty.custom_issue_description : ''
},
Expand Down
93 changes: 51 additions & 42 deletions app/assets/v2/js/pages/profile-trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,52 +190,61 @@ Vue.component('active-trust-manager', {
// enter loading
this.loading = true;

// check for a passport and then its validity
if (passport) {
// check if the stamps are unique to this user...
const stampHashes = await apiCall(`/api/v2/profile/${document.contxt.github_handle}/passport/stamp/check`, {
'did': this.did,
'stamp_hashes': passport.stamps.map((stamp) => {
return stamp.credential.credentialSubject.hash;
})
});
// reset errors
this.verificationError = undefined;

try {

// check for a passport and then its validity
if (passport) {
// check if the stamps are unique to this user...
const stampHashes = await apiCall(`/api/v2/profile/${document.contxt.github_handle}/passport/stamp/check`, {
'did': this.did,
'stamp_hashes': passport.stamps.map((stamp) => {
return stamp.credential.credentialSubject.hash;
})
});

// perform checks on issuer, expiry, owner, VC validity and stamp_hash validity
await Promise.all(passport.stamps.map(async(stamp) => {
if (stamp && Object.keys(stamp).length > 0) {
// set the service against provider and issuer
const serviceDictId = `${this.IAMIssuer}#${stamp.provider}`;
// validate the contents of the stamp collection
const expiryCheck = new Date(stamp.credential.expirationDate) > new Date();
const issuerCheck = stamp.credential.issuer === this.IAMIssuer;
const hashCheck = stampHashes.checks[stamp.credential.credentialSubject.hash] === true;
const providerCheck = stamp.provider === stamp.credential.credentialSubject.provider;
const ownerCheck = selectedAccount.toLowerCase() == stamp.credential.credentialSubject.id.replace('did:pkh:eip155:1:', '').toLowerCase();

// check exists and has valid expiry / issuer / hash / owner...
if (this.serviceDict[serviceDictId] && stamp.credential && expiryCheck && issuerCheck && hashCheck && providerCheck && ownerCheck) {
// verify with DIDKits verifyCredential()
const verified = JSON.parse(await this.DIDKit.verifyCredential(
JSON.stringify(stamp.credential),
`{"proofPurpose":"${stamp.credential.proof.proofPurpose}"}`
));

// if no errors then this is a valid VerifiableCredential issued by the known issuer and is unique to our store
this.serviceDict[serviceDictId].is_verified = verified.errors.length === 0;
// perform checks on issuer, expiry, owner, VC validity and stamp_hash validity
await Promise.all(passport.stamps.map(async(stamp) => {
if (stamp && Object.keys(stamp).length > 0) {
// set the service against provider and issuer
const serviceDictId = `${this.IAMIssuer}#${stamp.provider}`;
// validate the contents of the stamp collection
const expiryCheck = new Date(stamp.credential.expirationDate) > new Date();
const issuerCheck = stamp.credential.issuer === this.IAMIssuer;
const hashCheck = stampHashes.checks[stamp.credential.credentialSubject.hash] === true;
const providerCheck = stamp.provider === stamp.credential.credentialSubject.provider;
const ownerCheck = selectedAccount.toLowerCase() == stamp.credential.credentialSubject.id.replace('did:pkh:eip155:1:', '').toLowerCase();

// check exists and has valid expiry / issuer / hash / owner...
if (this.serviceDict[serviceDictId] && stamp.credential && expiryCheck && issuerCheck && hashCheck && providerCheck && ownerCheck) {
// verify with DIDKits verifyCredential()
const verified = JSON.parse(await this.DIDKit.verifyCredential(
JSON.stringify(stamp.credential),
`{"proofPurpose":"${stamp.credential.proof.proofPurpose}"}`
));

// if no errors then this is a valid VerifiableCredential issued by the known issuer and is unique to our store
this.serviceDict[serviceDictId].is_verified = verified.errors.length === 0;
}
// collect array of true/false to check validity of every issued stamp (if stamp isn't recognised then it should be ignored (always true))
return !this.serviceDict[serviceDictId] ? true : this.serviceDict[serviceDictId].is_verified;
}
// collect array of true/false to check validity of every issued stamp (if stamp isn't recognised then it should be ignored (always true))
return !this.serviceDict[serviceDictId] ? true : this.serviceDict[serviceDictId].is_verified;
}
}));
}));

// set the new trustBonus score
this.trustBonus = Math.min(150, this.services.reduce((total, service) => {
return (service.is_verified ? service.match_percent : 0) + total;
}, 50));
// set the new trustBonus score
this.trustBonus = Math.min(150, this.services.reduce((total, service) => {
return (service.is_verified ? service.match_percent : 0) + total;
}, 50));
}
} catch (error) {
console.error('Error checking passport: ', error);
this.verificationError = 'Oh, we had a technical error while scoring. Please give it another try.';
throw error;
} finally {
this.loading = false;
}

// stop loading
this.loading = false;
},
async savePassport() {
// enter loading
Expand Down
12 changes: 6 additions & 6 deletions app/dashboard/templates/bounty/details2.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ <h4 id="title" class="font-title p-0 text-center text-lg-left">[[ bounty.title ]
</div>
</div>

<div v-if="bounty.contact_details && bounty.contact_details.length > 0" class="mt-3">
<div v-if="bounty.contact_details && bounty.contact_details.length > 0" class="row mt-3">
<span class="bounty-info-heading">{% trans "Contacts" %}</span>

<div id="bounty-info-row" class="row font-body bounty-info">
<div class="col-12 col-sm-4 col-md-2 d-flex mt-1 text-nowrap" v-for="contact in bounty.contact_details">
<span v-if="contact.type=='Discord'"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
<div id="bounty-info-row" class="d-flex flex-wrap font-body bounty-info">
<div class="d-flex mt-1 text-nowrap" v-for="contact in bounty.contact_details">
<span v-if="contact.type=='Discord'" class="mr-2"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'" class="mr-2"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'" class="mr-2"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/dashboard/templates/bounty/new_bounty_step_5.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ <h4 id="title" class="font-title p-0 text-center text-lg-left">[[ form.title ]]<
<div v-if="nonEmptyContactDetails && nonEmptyContactDetails.length > 0" class="mt-3">
<span class="bounty-info-heading">{% trans "Contacts" %}</span>

<div id="bounty-info-row" class="row font-body bounty-info">
<div class="col-12 col-sm-4 col-md-2 d-flex mt-1 text-nowrap" v-for="contact in nonEmptyContactDetails">
<span v-if="contact.type=='Discord'"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
<div id="bounty-info-row" class="d-flex flex-wrap font-body bounty-info">
<div class="d-flex mt-1 text-nowrap" v-for="contact in nonEmptyContactDetails">
<span v-if="contact.type=='Discord'" class="mr-2"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'" class="mr-2"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'" class="mr-2"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/grants/management/commands/grants_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ def calculate_voting_power(grant):
grant.metadata['cv'] = round(grantVotingPower[grantId])
grant.save()
except Exception as e:
print("Error:", e)
print("Error:", e)
10 changes: 5 additions & 5 deletions app/grants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,13 @@ def bsci_script(csv: str) -> tuple:
labels_by_evaluation)))

# Assign final `is_sybil` markings according to a priorization criteria
df.loc[labels_by_evaluation, 'is_sybil'] = df[labels_by_evaluation].evaluation_score
df.loc[labels_by_evaluation, 'is_sybil'] = df[labels_by_evaluation].evaluation_score > EVAL_THRESHOLD
df.loc[labels_by_evaluation, 'label'] = "Human Evaluation"

df.loc[labels_by_heuristic, 'is_sybil'] = df[labels_by_heuristic].heuristic_score
df.loc[labels_by_heuristic, 'is_sybil'] = df[labels_by_heuristic].heuristic_score > HEURISTIC_THRESHOLD
df.loc[labels_by_heuristic, 'label'] = "Heuristics"

df.loc[labels_by_prediction, 'is_sybil'] = df[labels_by_prediction].prediction_score
df.loc[labels_by_prediction, 'is_sybil'] = df[labels_by_prediction].prediction_score > ML_THRESHOLD
df.loc[labels_by_prediction, 'label'] = "ML Prediction"

# Generate dict records
Expand Down

0 comments on commit 7bf1185

Please sign in to comment.