Skip to content

Commit

Permalink
Removed listOfGroupType API of user_roles
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljames-dj committed Jun 22, 2024
1 parent 1e2d8f8 commit e95e997
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 24 deletions.
12 changes: 0 additions & 12 deletions app/controllers/api/v0/user_roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ def index
paginate json: roles
end

# Returns a list of roles primarily based on groupType.
def index_for_group_type
group_type = params.require(:group_type)
roles = UserGroup.roles_of_group_type(group_type)

# Filter & Sort roles
roles = UserRole.filter_roles(roles, current_user, params)
roles = UserRole.sort_roles(roles, params[:sort])

render json: roles
end

def show
id = params.require(:id)
role = UserRole.find(id)
Expand Down
2 changes: 1 addition & 1 deletion app/webpacker/components/DelegateProbations/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function DelegateProbations() {

const {
data: probationRoles, loading, error, sync,
} = useLoadedData(apiV0Urls.userRoles.listOfGroupType(groupTypes.delegate_probation));
} = useLoadedData(apiV0Urls.userRoles.list({ groupType: groupTypes.delegate_probation }));
const { save, saving } = useSaveAction();

if (loading || saving) return 'Loading...'; // No i18n because this page is used only by WCA Staff.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export default function BoardEditorPage() {
const {
data: boardRoles, loading, error, sync,
} = useLoadedData(
apiV0Urls.userRoles.listOfGroupType(groupTypes.board, 'name', {
apiV0Urls.userRoles.list({
groupType: groupTypes.board,
isActive: true,
}),
}, 'name'),
);

if (loading) return <Loading />;
Expand Down
5 changes: 3 additions & 2 deletions app/webpacker/components/Panel/Board/OfficersEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export default function OfficersEditor() {
const {
data: officers, loading: officersLoading, error: officersError, sync,
} = useLoadedData(
apiV0Urls.userRoles.listOfGroupType(groupTypes.officers, 'status:desc', {
apiV0Urls.userRoles.list({
groupType: groupTypes.officers,
isActive: true,
}),
}, 'status:desc'),
);
const [openModal, setOpenModal] = useState(false);
const [newOfficer, setNewOfficer] = useState(initialOfficerValue);
Expand Down
5 changes: 3 additions & 2 deletions app/webpacker/components/Panel/Board/SeniorDelegatesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import Errored from '../../Requests/Errored';

export default function SeniorDelegatesList() {
const { data: seniorDelegates, loading, error } = useLoadedData(
apiV0Urls.userRoles.listOfGroupType(groupTypes.delegate_regions, 'name', {
apiV0Urls.userRoles.list({
groupType: groupTypes.delegate_regions,
status: 'senior_delegate',
}),
}, 'name'),
);
if (loading) return <Loading />;
if (error) return <Errored />;
Expand Down
2 changes: 1 addition & 1 deletion app/webpacker/components/Panel/pages/Translators/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Translators() {
const {
data: translators, loading: translatorsLoading, error: translatorsError, sync,
} = useLoadedData(
apiV0Urls.userRoles.listOfGroupType(groupTypes.translators, 'name', { isActive: true }),
apiV0Urls.userRoles.list({ groupType: groupTypes.translators, isActive: true }, 'name'),
);
const {
data: locales, loading: loadingLocales, error: errorLocales,
Expand Down
1 change: 0 additions & 1 deletion app/webpacker/lib/requests/routes.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export const apiV0Urls = {
},
userRoles: {
list: ({isActive, isGroupHidden, userId, groupId, status, groupType, isLead} = {}, sort, perPage = 100) => `<%= CGI.unescape(Rails.application.routes.url_helpers.api_v0_user_roles_path) %>?${jsonToQueryString({ sort, isActive, isGroupHidden, userId, groupId, status, groupType, isLead, per_page: perPage })}`,
listOfGroupType: (groupType, sort, {status, isActive} = {}) => `<%= CGI.unescape(Rails.application.routes.url_helpers.api_v0_index_for_group_type_path('${groupType}')) %>?${jsonToQueryString({ sort, status, isActive })}`,
create: () => `<%= CGI.unescape(Rails.application.routes.url_helpers.api_v0_user_roles_path) %>`,
update: (roleId) => `<%= CGI.unescape(Rails.application.routes.url_helpers.api_v0_user_role_path("${roleId}")) %>`,
delete: (roleId) => `<%= CGI.unescape(Rails.application.routes.url_helpers.api_v0_user_role_path("${roleId}")) %>`,
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@
post '/registration-data' => 'competitions#registration_data', as: :registration_data

scope 'user_roles' do
get '/group-type/:group_type' => 'user_roles#index_for_group_type', as: :index_for_group_type
get '/search' => 'user_roles#search', as: :user_roles_search
end
resources :user_roles, only: [:index, :show, :create, :update, :destroy]
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/api/v0/user_roles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

it 'does not fetches list of banned competitos' do
get :index_for_group_type, params: { group_type: UserGroup.group_types[:banned_competitors] }
get :index, params: { groupType: UserGroup.group_types[:banned_competitors] }

expect(response.body).to eq([banned_competitor].to_json)
end
Expand All @@ -47,7 +47,7 @@
end

it 'fetches list of banned competitos' do
get :index_for_group_type, params: { group_type: UserGroup.group_types[:banned_competitors] }
get :index, params: { groupType: UserGroup.group_types[:banned_competitors] }

expect(response.body).to eq([].to_json)
end
Expand Down

0 comments on commit e95e997

Please sign in to comment.