Skip to content

Commit 23d06c6

Browse files
rahmatrhdayushi0014Ayushi Sharma
authored
feat: expose list resources and manage access APIs (#5)
* feat: expose groups and vpns related list APIs (#1) * feat: expose groups and vpns related list APIs * feat: filter active user only for group admins API * feat(group): membership management APIs (#2) * feat(group): added remove_user and check user_in_group api * feat(api): get group member API * feat: remove get group user API --------- Co-authored-by: Ayushi Sharma <[email protected]> Co-authored-by: Rahmat Hidayat <[email protected]> * feat: enhance list groups and vpns APIs (#4) * chore: return 404 if group not found * feat: introduce search query in list vpns * fix: return 404 if vpn not found * fix: return 404 if group not found * fix: use find_by_id instead of find * feat: introduce search query in list vpn groups * ci: docker release (#3) * ci: test docker release action * ci: change trigger * chore: lock bundler version * fix: fix docker push command * ci: change trigger * ci: run release only on tag --------- Co-authored-by: Ayushi Sharma <[email protected]> Co-authored-by: Ayushi Sharma <[email protected]>
1 parent 9c863c5 commit 23d06c6

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

.github/workflows/release.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Build the Docker image
14+
run: docker build . --file Dockerfile --tag gotocompany/gate:${{ github.ref_name }}
15+
- name: Login to DockerHub
16+
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
17+
- name: Push Docker image
18+
run: docker push gotocompany/gate:${{ github.ref_name }}

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WORKDIR /app
1010
COPY Gemfile /app
1111
COPY Gemfile.lock /app
1212

13-
RUN gem install bundler -v '>= 2.0'
13+
RUN gem install bundler -v '2.0.2'
1414
RUN bundle install --without development
1515
COPY . /app
1616

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ gem 'slim-rails'
3131
gem 'turbolinks'
3232
gem 'uglifier'
3333
gem 'whenever', require: false
34+
gem 'kaminari'
3435

3536
group :development, :test do
3637
gem 'capybara'

app/controllers/api/v1/groups_controller.rb

+36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
class ::Api::V1::GroupsController < ::Api::V1::BaseController
2+
def index
3+
groups = Group.order(:id).page(params[:page]).per(params[:per_page])
4+
render json: groups, status: :ok
5+
end
6+
27
def create
38
if current_user.admin?
49
@group = Group.new(group_params)
@@ -40,6 +45,37 @@ def add_user
4045
head :no_content
4146
end
4247

48+
def remove_user
49+
@group = Group.find_by(id: params[:id])
50+
return head :not_found unless @group.present?
51+
52+
return raise_unauthorized unless current_user.admin? || @group.admin?(current_user)
53+
54+
user = User.find_by(id: params[:user_id])
55+
return head :unprocessable_entity unless user.present?
56+
57+
@group.remove_user(params[:user_id])
58+
head :no_content
59+
end
60+
61+
def list_admins
62+
group = Group.find_by_id(params[:id])
63+
return head :not_found unless group.present?
64+
65+
users = group.group_admins.joins(:user).
66+
select('users.id, users.email, users.name, users.active, group_admins.created_at as join_date').
67+
where('users.active = ?', true)
68+
render json: users, status: :ok
69+
end
70+
71+
def associated_vpns
72+
group = Group.find_by_id(params[:id])
73+
return head :not_found unless group.present?
74+
75+
vpns = group.vpns
76+
render json: vpns, status: :ok
77+
end
78+
4379
private
4480

4581
def group_params

app/controllers/api/v1/vpns_controller.rb

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
class ::Api::V1::VpnsController < ::Api::V1::BaseController
22
before_action :set_vpn, only: [:assign_group]
33

4+
def index
5+
vpns = Vpn.order(:id).page(params[:page]).per(params[:per_page])
6+
vpns = vpns.where("name LIKE ?", "%#{params[:q]}%") if params[:q].present?
7+
render json: vpns, status: :ok
8+
end
9+
10+
def associated_groups
11+
vpn = Vpn.find_by_id(params[:id])
12+
return head :not_found unless vpn.present?
13+
14+
groups = vpn.groups
15+
groups = groups.where("name LIKE ?", "%#{params[:q]}%") if params[:q].present?
16+
render json: groups, status: :ok
17+
end
18+
419
def create
520
if current_user.admin?
621
@vpn = Vpn.new(vpn_params)

config/routes.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@
8787
post 'endpoints' => 'endpoints#create', format: :json, :constraints => { format: 'json' }
8888
post 'endpoints/:id/add_group' => 'endpoints#add_group', format: :json, constraints: { format: 'json' }
8989
post 'groups/:id/users' => 'groups#add_user', format: :json, constraints: { format: 'json' }
90-
91-
resources :groups, only: [:create], format: :json
92-
resources :vpns, only: [:create], format: :json do
90+
delete 'groups/:id/users/:user_id' => 'groups#remove_user', format: :json, constraints: { format: 'json' }
91+
get 'groups/:id/admins' => 'groups#list_admins', format: :json, constraints: { format: 'json' }
92+
get 'groups/:id/vpns' => 'groups#associated_vpns', format: :json, constraints: { format: 'json' }
93+
get 'vpns/:id/groups' => 'vpns#associated_groups', format: :json, constraints: { format: 'json' }
94+
95+
resources :groups, only: [:create, :index], format: :json
96+
resources :vpns, only: [:create, :index], format: :json do
9397
member do
9498
post 'assign_group'
9599
end

0 commit comments

Comments
 (0)