Skip to content

Commit 9420e90

Browse files
authored
Add CurrentUser from OOD and toggle if user is mayaosu (#150)
Add CurrentUser from OOD and toggle if user is mayaosu. This distingushes osu users from kent state users (who only have 2025 available).
1 parent 7706ca5 commit 9420e90

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

app/models/current_user.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
# The CurrentUser class represents the current user on the system from Etc.
4+
# It has a name, a home directory, gid, uid and so on.
5+
#
6+
#
7+
# It is a singleton for the simple reason that this is ran in a single
8+
# user context (i.e., the Per User Nginx). And for convienence to do stuff
9+
# like User.home instead of User.new.home or OodSupport::User.new.home.
10+
class CurrentUser
11+
include Singleton
12+
13+
class << self
14+
delegate :name, :uid, :gid, :gecos, :dir, :shell, to: :instance
15+
delegate :primary_group, :primary_group_name, :group_names, :groups, to: :instance
16+
17+
alias_method :home, :dir
18+
end
19+
20+
attr_reader :pwuid
21+
delegate :name, :uid, :gid, :gecos, :dir, :shell, to: :pwuid
22+
23+
def initialize
24+
@pwuid = Etc.getpwuid
25+
end
26+
27+
def primary_group
28+
@primary_group ||= Etc.getgrgid(gid)
29+
end
30+
31+
def primary_group_name
32+
@primary_group_name ||= primary_group.name
33+
end
34+
35+
def group_names
36+
@group_names ||= groups.map(&:name)
37+
end
38+
39+
def groups
40+
@groups ||= begin
41+
42+
# let's guarentee that the first item in this list is the primary group
43+
groups = Process.groups
44+
groups.delete(primary_group.gid)
45+
groups.unshift(primary_group.gid).map { |gid| Etc.getgrgid(gid) }
46+
end
47+
end
48+
end

app/models/maya_script.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ def cluster
2626
end
2727

2828
def available_versions
29-
['2025']
29+
if accad?
30+
['2023', '2025']
31+
else
32+
['2025']
33+
end
3034
end
3135

3236
def job_name
3337
'maya-render'
3438
end
39+
40+
def accad?
41+
CurrentUser.group_names.include?('mayaosu')
42+
end
3543
end

0 commit comments

Comments
 (0)