Skip to content

Commit

Permalink
Merge pull request #111 from lishengbao/selection
Browse files Browse the repository at this point in the history
Update tpc role
  • Loading branch information
lishengbao authored Aug 5, 2024
2 parents a157fe3 + c3b69a8 commit 3c932c3
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 38 deletions.
6 changes: 6 additions & 0 deletions app/graphql/mutations/base_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def login_required!(current_user)
raise GraphQL::ExecutionError.new I18n.t('users.require_login') if current_user.blank?
end

def validate_tpc!(current_user)
login_required!(current_user)
return if current_user&.is_tpc?
raise GraphQL::ExecutionError.new I18n.t('users.forbidden')
end

def validate_admin!(current_user)
login_required!(current_user)
return if current_user&.is_admin?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AcceptTpcSoftwareReportMetricClarification < BaseMutation
def resolve(short_code: nil, metric_name: nil, state: 1, member_type: 0)

current_user = context[:current_user]
login_required!(current_user)
validate_tpc!(current_user)

raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') unless TpcSoftwareCommentState::States.include?(state)
raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') unless TpcSoftwareCommentState::Member_Types.include?(member_type)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/tpc/accept_tpc_software_selection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AcceptTpcSoftwareSelection < BaseMutation
def resolve(selection_id: nil, state: 1, member_type: 0)

current_user = context[:current_user]
login_required!(current_user)
validate_tpc!(current_user)

raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') unless TpcSoftwareCommentState::States.include?(state)
raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') unless TpcSoftwareCommentState::Member_Types.include?(member_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def resolve(short_code: nil,
content: nil
)
current_user = context[:current_user]
login_required!(current_user)
validate_tpc!(current_user)

report = TpcSoftwareSelectionReport.find_by(short_code: short_code)
raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') if report.nil?
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/tpc/create_tpc_software_selection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def resolve(label: nil,
)
label = ShortenedLabel.normalize_label(label)
current_user = context[:current_user]
login_required!(current_user)
validate_tpc!(current_user)

subject = Subject.find_by(label: label, level: level)
raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') if subject.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CreateTpcSoftwareSelectionComment < BaseMutation

def resolve(selection_id: nil, content: nil)
current_user = context[:current_user]
login_required!(current_user)
validate_tpc!(current_user)

selection = TpcSoftwareSelection.find_by(id: selection_id)
raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') if selection.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def resolve(label: nil,
)
label = ShortenedLabel.normalize_label(label)
current_user = context[:current_user]
login_required!(current_user)
validate_tpc!(current_user)

subject = Subject.find_by(label: label, level: level)
raise GraphQL::ExecutionError.new I18n.t('basic.subject_not_exist') if subject.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class TpcSoftwareSelectionPageQuery < BaseQuery
argument :sort_opts, [Input::SortOptionInput], required: false, description: 'sort options'

def resolve(label: nil, level: nil, selection_type: 0, page: 1, per: 9, filter_opts: nil, sort_opts: nil)
current_user = context[:current_user]
login_required!(current_user)
validate_by_label!(current_user, label)

subject = Subject.find_by(label: label, level: level)

items = []
Expand Down
24 changes: 14 additions & 10 deletions app/graphql/types/queries/tpc/tpc_software_selection_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ class TpcSoftwareSelectionQuery < BaseQuery

def resolve(selection_id: nil)
current_user = context[:current_user]
login_required!(current_user)

selection = TpcSoftwareSelection.find_by(id: selection_id)
if selection
selection_hash = selection.attributes
selection_report = TpcSoftwareSelectionReport.where("id IN (?)", JSON.parse(selection.tpc_software_selection_report_ids))
.where("code_url LIKE ?", "%#{selection.target_software}%")
.take
committer_permission = 0
if selection_report
committer_permission = TpcSoftwareMember.check_committer_permission?(selection_report.tpc_software_sig_id, current_user)
committer_permission = false
sig_lead_permission = false
legal_permission = false
compliance_permission = false
if current_user.present?
selection_report = TpcSoftwareSelectionReport.where("id IN (?)", JSON.parse(selection.tpc_software_selection_report_ids))
.where("code_url LIKE ?", "%#{selection.target_software}%")
.take
if selection_report
committer_permission = TpcSoftwareMember.check_committer_permission?(selection_report.tpc_software_sig_id, current_user)
end
sig_lead_permission = TpcSoftwareMember.check_sig_lead_permission?(current_user)
legal_permission = TpcSoftwareMember.check_legal_permission?(current_user)
compliance_permission = TpcSoftwareMember.check_compliance_permission?(current_user)
end
sig_lead_permission = TpcSoftwareMember.check_sig_lead_permission?(current_user)
legal_permission = TpcSoftwareMember.check_legal_permission?(current_user)
compliance_permission = TpcSoftwareMember.check_compliance_permission?(current_user)

selection_hash['comment_committer_permission'] = committer_permission ? 1 : 0
selection_hash['comment_sig_lead_permission'] = sig_lead_permission ? 1 : 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class TpcSoftwareSelectionReportPageQuery < BaseQuery
argument :sort_opts, [Input::SortOptionInput], required: false, description: 'sort options'

def resolve(label: nil, level: nil, report_type_list: [], page: 1, per: 9, filter_opts: nil, sort_opts: nil)
current_user = context[:current_user]
login_required!(current_user)
validate_by_label!(current_user, label)

subject = Subject.find_by(label: label, level: level)

items = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ class TpcSoftwareSelectionReportQuery < BaseQuery

def resolve(short_code: nil)
current_user = context[:current_user]
login_required!(current_user)

report = TpcSoftwareSelectionReport.find_by(short_code: short_code)
if report
report_hash = report.attributes
clarification_committer_permission = TpcSoftwareMember.check_committer_permission?(report.tpc_software_sig_id, current_user)
clarification_sig_lead_permission = TpcSoftwareMember.check_sig_lead_permission?(current_user)
clarification_legal_permission = TpcSoftwareMember.check_legal_permission?(current_user)
clarification_compliance_permission = TpcSoftwareMember.check_compliance_permission?(current_user)
clarification_committer_permission = false
clarification_sig_lead_permission = false
clarification_legal_permission = false
clarification_compliance_permission = false
if current_user.present?
clarification_committer_permission = TpcSoftwareMember.check_committer_permission?(report.tpc_software_sig_id, current_user)
clarification_sig_lead_permission = TpcSoftwareMember.check_sig_lead_permission?(current_user)
clarification_legal_permission = TpcSoftwareMember.check_legal_permission?(current_user)
clarification_compliance_permission = TpcSoftwareMember.check_compliance_permission?(current_user)
end

report_hash['clarification_committer_permission'] = clarification_committer_permission ? 1 : 0
report_hash['clarification_sig_lead_permission'] = clarification_sig_lead_permission ? 1 : 0
Expand Down
4 changes: 0 additions & 4 deletions app/graphql/types/queries/tpc/tpc_software_sig_list_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class TpcSoftwareSigListQuery < BaseQuery
argument :level, String, required: false, description: 'repo or project level(repo/community)'

def resolve(label: nil, level: nil)
current_user = context[:current_user]
login_required!(current_user)
validate_by_label!(current_user, label)

subject = Subject.find_by(label: label, level: level)
items = []
if subject.present?
Expand Down
8 changes: 4 additions & 4 deletions app/models/tpc_software_report_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,21 +547,21 @@ def self.get_code_count(sonar_scanner_result)
code_count
end

def self.get_license(project_url, scancode_result)
def self.get_license(scancode_result)
license_detections = scancode_result.dig("license_detections") || []
unless license_detections&.any?
return nil
end

standard_license_location = "#{project_url.split("/")[-1]}/License.txt"
license_detections.each do |license_detection|
(license_detection.dig("reference_matches") || []).each do |reference_match|
if reference_match.dig("from_file") == standard_license_location
from_file_split = reference_match.dig("from_file").split("/")
if from_file_split.length == 2
return reference_match.dig("license_expression")
end
end
end
license_detections.first.dig("license_expression")
return nil
end

def self.get_ecology_dependency_acquisition(dependency_checker_result)
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class User < ApplicationRecord

ANONYMOUS_EMAIL_SUFFIX = '@user.anonymous.oss-compass.org'
NORMAL_ROLE = 3
TPC_ROLE = 2

def email_verified?
email_verification_token.nil?
Expand All @@ -63,6 +64,10 @@ def is_admin?
role_level.to_i > NORMAL_ROLE
end

def is_tpc?
role_level.to_i >= TPC_ROLE
end

def verify_email(token)
if !email_verification_expired? && email_verification_token == token
self.email_verification_token = nil
Expand Down
2 changes: 1 addition & 1 deletion app/services/tpc_software_metric_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def tpc_software_callback(command_list, scan_results, task_metadata)
when "scancode"
metric_hash.merge!(TpcSoftwareReportMetric.get_compliance_license(scan_results.dig(command) || {}))
metric_hash.merge!(TpcSoftwareReportMetric.get_compliance_license_compatibility(scan_results.dig(command) || {}))
license = TpcSoftwareReportMetric.get_license(@project_url, scan_results.dig(command) || {})
license = TpcSoftwareReportMetric.get_license(scan_results.dig(command) || {})
when "binary-checker"
metric_hash.merge!(TpcSoftwareReportMetric.get_security_binary_artifact(scan_results.dig(command) || {}))
when "signature-checker"
Expand Down

0 comments on commit 3c932c3

Please sign in to comment.