Module: Vortex::Rails::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/vortex/rails.rb
Instance Method Summary collapse
-
#accept_invitations ⇒ Object
Accept invitations POST /api/vortex/invitations/accept.
-
#delete_invitations_by_group ⇒ Object
Delete invitations by group DELETE /api/vortex/invitations/by-group/:group_type/:group_id.
-
#generate_jwt ⇒ Object
Generate JWT for authenticated user POST /api/vortex/jwt.
-
#get_invitation ⇒ Object
Get specific invitation by ID GET /api/vortex/invitations/:invitation_id.
-
#get_invitations_by_group ⇒ Object
Get invitations by group GET /api/vortex/invitations/by-group/:group_type/:group_id.
-
#get_invitations_by_target ⇒ Object
Get invitations by target GET /api/vortex/invitations?targetType=email&[email protected].
-
#reinvite ⇒ Object
Reinvite user POST /api/vortex/invitations/:invitation_id/reinvite.
-
#revoke_invitation ⇒ Object
Revoke (delete) invitation DELETE /api/vortex/invitations/:invitation_id.
Instance Method Details
#accept_invitations ⇒ Object
Accept invitations POST /api/vortex/invitations/accept
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/vortex/rails.rb', line 160 def accept_invitations Vortex::Rails.logger.debug("Vortex::Rails::Controller#accept_invitations invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('ACCEPT_INVITATIONS', user) return render_forbidden('Not authorized to accept invitations') end invitation_ids = params[:invitationIds] target = params[:target] unless invitation_ids && target return render_bad_request('Missing invitationIds or target') end result = vortex_client.accept_invitations(invitation_ids, target) render json: result rescue Vortex::VortexError => e render_server_error("Failed to accept invitations: #{e.}") end |
#delete_invitations_by_group ⇒ Object
Delete invitations by group DELETE /api/vortex/invitations/by-group/:group_type/:group_id
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/vortex/rails.rb', line 206 def delete_invitations_by_group Vortex::Rails.logger.debug("Vortex::Rails::Controller#delete_invitations_by_group invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('DELETE_GROUP_INVITATIONS', user) return render_forbidden('Not authorized to delete group invitations') end group_type = params[:group_type] group_id = params[:group_id] vortex_client.delete_invitations_by_group(group_type, group_id) render json: { success: true } rescue Vortex::VortexError => e render_server_error("Failed to delete group invitations: #{e.}") end |
#generate_jwt ⇒ Object
Generate JWT for authenticated user POST /api/vortex/jwt
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/vortex/rails.rb', line 53 def generate_jwt Vortex::Rails.logger.debug("Vortex::Rails::Controller#generate_jwt invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('JWT', user) Vortex::Rails.logger.warn("Vortex JWT authorization failed for user #{user[:user_id]}") return render_forbidden('Not authorized to generate JWT') end # Extract email from identifiers for the user hash email = user[:identifiers]&.find { |i| i[:type] == 'email' }&.dig(:value) # Build the JWT jwt_params = { user: { id: user[:user_id], email: email } } # Add adminScopes if present if user[:admin_scopes]&.any? jwt_params[:user][:admin_scopes] = user[:admin_scopes] end # Add attributes if present if user[:attributes] jwt_params[:attributes] = user[:attributes] end jwt = vortex_client.generate_jwt(jwt_params) Vortex::Rails.logger.debug("Vortex JWT generated successfully for user #{user[:user_id]}") render json: { jwt: jwt } rescue Vortex::VortexError => e Vortex::Rails.logger.error("Vortex error generating JWT: #{e.}") render_server_error("Failed to generate JWT: #{e.}") rescue StandardError => e Vortex::Rails.logger.error("Unexpected error generating JWT: #{e.class} - #{e.}") render_server_error("Unexpected error: #{e.}") end |
#get_invitation ⇒ Object
Get specific invitation by ID GET /api/vortex/invitations/:invitation_id
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/vortex/rails.rb', line 122 def get_invitation Vortex::Rails.logger.debug("Vortex::Rails::Controller#get_invitation invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('GET_INVITATION', user) return render_forbidden('Not authorized to get invitation') end invitation_id = params[:invitation_id] invitation = vortex_client.get_invitation(invitation_id) render json: invitation rescue Vortex::VortexError => e render_not_found("Invitation not found: #{e.}") end |
#get_invitations_by_group ⇒ Object
Get invitations by group GET /api/vortex/invitations/by-group/:group_type/:group_id
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/vortex/rails.rb', line 185 def get_invitations_by_group Vortex::Rails.logger.debug("Vortex::Rails::Controller#get_invitations_by_group invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('GET_GROUP_INVITATIONS', user) return render_forbidden('Not authorized to get group invitations') end group_type = params[:group_type] group_id = params[:group_id] invitations = vortex_client.get_invitations_by_group(group_type, group_id) render json: { invitations: invitations } rescue Vortex::VortexError => e render_server_error("Failed to get group invitations: #{e.}") end |
#get_invitations_by_target ⇒ Object
Get invitations by target GET /api/vortex/invitations?targetType=email&[email protected]
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/vortex/rails.rb', line 99 def get_invitations_by_target Vortex::Rails.logger.debug("Vortex::Rails::Controller#get_invitations_by_target invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('GET_INVITATIONS', user) return render_forbidden('Not authorized to get invitations') end target_type = params[:targetType] target_value = params[:targetValue] return render_bad_request('Missing targetType or targetValue') unless target_type && target_value invitations = vortex_client.get_invitations_by_target(target_type, target_value) render json: { invitations: invitations } rescue Vortex::VortexError => e render_server_error("Failed to get invitations: #{e.}") end |
#reinvite ⇒ Object
Reinvite user POST /api/vortex/invitations/:invitation_id/reinvite
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/vortex/rails.rb', line 227 def reinvite Vortex::Rails.logger.debug("Vortex::Rails::Controller#reinvite invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('REINVITE', user) return render_forbidden('Not authorized to reinvite') end invitation_id = params[:invitation_id] result = vortex_client.reinvite(invitation_id) render json: result rescue Vortex::VortexError => e render_server_error("Failed to reinvite: #{e.}") end |
#revoke_invitation ⇒ Object
Revoke (delete) invitation DELETE /api/vortex/invitations/:invitation_id
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/vortex/rails.rb', line 141 def revoke_invitation Vortex::Rails.logger.debug("Vortex::Rails::Controller#revoke_invitation invoked") user = authenticate_vortex_user return ('Authentication required') unless user unless ('REVOKE_INVITATION', user) return render_forbidden('Not authorized to revoke invitation') end invitation_id = params[:invitation_id] vortex_client.revoke_invitation(invitation_id) render json: { success: true } rescue Vortex::VortexError => e render_server_error("Failed to revoke invitation: #{e.}") end |