-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an interface for users to personally update their organizations.
Signed-off-by: EdmondFrank <[email protected]>
- Loading branch information
1 parent
aad3575
commit 5a8fe75
Showing
11 changed files
with
1,068 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Input | ||
class ContributorOrgInput < Types::BaseInputObject | ||
argument :org_name, String, description: "organization's name" | ||
argument :first_date, GraphQL::Types::ISO8601DateTime, description: 'time of begin of service by the organization' | ||
argument :last_date, GraphQL::Types::ISO8601DateTime, description: 'time of end of service by the organization' | ||
|
||
def self.validate_no_overlap(inputs) | ||
ranges = inputs.map do |i| | ||
if i.last_date < i.first_date | ||
raise GraphQL::ExecutionError.new I18n.t('contributor_orgs.range_invalid') | ||
end | ||
(i.first_date..i.last_date) | ||
end | ||
|
||
overlaps = ranges.combination(2).any? { |r1, r2| (r1.min..r1.max).overlaps?(r2.min..r2.max) } | ||
if overlaps | ||
raise GraphQL::ExecutionError.new I18n.t('contributor_orgs.range_overlap') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutations | ||
class ModifyUserOrgs < BaseMutation | ||
include CompassUtils | ||
|
||
field :status, String, null: false | ||
|
||
argument :platform, String, required: true, description: 'platform of the organization' | ||
argument :organizations, [Input::ContributorOrgInput], required: true, description: 'contributor organizations' | ||
|
||
def resolve(platform: nil, organizations: []) | ||
current_user = context[:current_user] | ||
|
||
login_required!(current_user) | ||
|
||
Input::ContributorOrgInput.validate_no_overlap(organizations) | ||
|
||
login_bind = current_user.login_binds.find_by(provider: platform) | ||
raise GraphQL::ExecutionError.new I18n.t('users.no_such_login_bind') if login_bind.blank? | ||
contributor = login_bind.nickname | ||
uuid = get_uuid(contributor, ContributorOrg::UserIndividual, nil, nil, platform) | ||
record = OpenStruct.new( | ||
{ | ||
id: uuid, | ||
uuid: uuid, | ||
org_change_date_list: organizations, | ||
modify_by: current_user.id, | ||
modify_type: ContributorOrg::UserIndividual, | ||
platform_type: platform, | ||
is_bot: false, | ||
label: nil, | ||
level: nil, | ||
update_at_date: Time.current | ||
} | ||
) | ||
|
||
ContributorOrg.import(record) | ||
|
||
{ status: true, message: '' } | ||
rescue => ex | ||
{ status: false, message: ex.message } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
module Types | ||
class ContributorOrgType < Types::BaseObject | ||
field :org_name, String, description: "organization's name" | ||
field :first_date, GraphQL::Types::ISO8601DateTime, description: 'time of begin of service by the organization' | ||
field :last_date, GraphQL::Types::ISO8601DateTime, description: 'time of end of service by the organization' | ||
field :platform_type, String, description: 'platform type of the organization' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class ContributorOrg < BaseIndex | ||
URL = 'URL' | ||
RepoAdmin = 'Repo Admin' | ||
UserIndividual = 'User Individual' | ||
|
||
def self.index_name | ||
'contributor_org' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.